Migrate CI from Drone to Woodpecker
Replace .drone.yml with .woodpecker/ pipeline configs (frontend.yml, api.yml). Convert Drone env vars to Woodpecker equivalents (CI_PIPELINE_NUMBER, CI_COMMIT_SHA), use woodpeckerci/plugin-git for clone with retry, woodpeckerci/plugin-slack for notifications, and plugins/docker for image builds. Update all docs and skills.
This commit is contained in:
parent
2357722e80
commit
c7c3331d30
9 changed files with 190 additions and 448 deletions
|
|
@ -19,7 +19,8 @@ steps:
|
|||
|
||||
- name: test-shard-1
|
||||
image: node:24-alpine
|
||||
depends_on: [install-frontend-deps]
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -27,7 +28,8 @@ steps:
|
|||
|
||||
- name: test-shard-2
|
||||
image: node:24-alpine
|
||||
depends_on: [install-frontend-deps]
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -35,7 +37,8 @@ steps:
|
|||
|
||||
- name: test-shard-3
|
||||
image: node:24-alpine
|
||||
depends_on: [install-frontend-deps]
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -43,14 +46,15 @@ steps:
|
|||
|
||||
- name: test-shard-4
|
||||
image: node:24-alpine
|
||||
depends_on: [install-frontend-deps]
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
- cd frontend && npx vitest run --reporter=verbose --shard=4/4
|
||||
|
||||
- name: build-frontend-image
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username: viktorbarzin
|
||||
password:
|
||||
|
|
@ -59,12 +63,19 @@ steps:
|
|||
dockerfile: frontend/Dockerfile
|
||||
context: frontend
|
||||
target: production
|
||||
cache_from:
|
||||
- viktorbarzin/immoweb:latest
|
||||
tags:
|
||||
- "build-${CI_PIPELINE_NUMBER}"
|
||||
|
||||
- name: publish-frontend-image
|
||||
image: alpine
|
||||
depends_on: [test-shard-1, test-shard-2, test-shard-3, test-shard-4, build-frontend-image]
|
||||
depends_on:
|
||||
- test-shard-1
|
||||
- test-shard-2
|
||||
- test-shard-3
|
||||
- test-shard-4
|
||||
- build-frontend-image
|
||||
environment:
|
||||
DOCKERHUB_TOKEN:
|
||||
from_secret: dockerhub-token
|
||||
|
|
@ -75,36 +86,75 @@ steps:
|
|||
|
||||
- name: update-deployment
|
||||
image: alpine
|
||||
depends_on: [publish-frontend-image]
|
||||
depends_on:
|
||||
- publish-frontend-image
|
||||
commands:
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
IMAGE="viktorbarzin/immoweb:${CI_PIPELINE_NUMBER}"
|
||||
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
API="https://10.0.20.100:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||
API="https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||
DEPLOY="realestate-crawler-ui"
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE..."
|
||||
curl -sf -X PATCH "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/strategic-merge-patch+json" -k \
|
||||
-d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE with restartedAt=$RESTART_AT..."
|
||||
|
||||
curl -sf -X PATCH "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/strategic-merge-patch+json" \
|
||||
-k -d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||
| jq '{name: .metadata.name, generation: .metadata.generation, image: .spec.template.spec.containers[0].image}'
|
||||
|
||||
- name: verify-deploy
|
||||
image: alpine
|
||||
depends_on: [update-deployment]
|
||||
depends_on:
|
||||
- update-deployment
|
||||
commands:
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
EXPECTED_IMAGE="viktorbarzin/immoweb:${CI_PIPELINE_NUMBER}"
|
||||
PODS_API="https://10.0.20.100:6443/api/v1/namespaces/realestate-crawler/pods?labelSelector=app%3Drealestate-crawler-ui"
|
||||
PODS_API="https://kubernetes:6443/api/v1/namespaces/realestate-crawler/pods?labelSelector=app%3Drealestate-crawler-ui"
|
||||
|
||||
for i in $(seq 1 60); do
|
||||
RESULT=$(curl -sfk "$PODS_API" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | \
|
||||
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select((.status.containerStatuses[]? | .ready == true) and (.spec.containers[]? | .image | endswith($img))) | {name: .metadata.name, image: .spec.containers[0].image}]')
|
||||
RAW=$(curl -sfk "$PODS_API" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json")
|
||||
|
||||
if [ "$i" -eq 1 ]; then
|
||||
echo "DEBUG: All pods for realestate-crawler-ui:"
|
||||
echo "$RAW" | jq -r '[.items[] | {name: .metadata.name, image: .spec.containers[0].image, ready: (.status.containerStatuses[]? | .ready), phase: .status.phase}] | .[] | " \(.name) image=\(.image) ready=\(.ready) phase=\(.phase)"' 2>/dev/null || echo " (no pods found)"
|
||||
fi
|
||||
|
||||
RESULT=$(echo "$RAW" | \
|
||||
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select(
|
||||
(.status.containerStatuses[]? | .ready == true) and
|
||||
(.spec.containers[]? | .image | endswith($img))
|
||||
) | {name: .metadata.name, image: .spec.containers[0].image, started: .status.startTime}]')
|
||||
|
||||
COUNT=$(echo "$RESULT" | jq 'length')
|
||||
echo "Attempt $i/60: $COUNT pod(s) ready with image $EXPECTED_IMAGE"
|
||||
if [ "$COUNT" -gt 0 ]; then echo "New pod is live!"; exit 0; fi
|
||||
echo "Attempt $i/60: $COUNT pod(s) ready with image matching $EXPECTED_IMAGE"
|
||||
|
||||
if [ "$COUNT" -gt 0 ]; then
|
||||
echo "$RESULT" | jq -r '.[] | " \(.name) image=\(.image) started=\(.started)"'
|
||||
echo "New pod is live!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sleep 5
|
||||
done
|
||||
echo "ERROR: No pod with image $EXPECTED_IMAGE appeared within 5 minutes"; exit 1
|
||||
|
||||
echo "ERROR: No new ready pod with image $EXPECTED_IMAGE appeared within 5 minutes"
|
||||
exit 1
|
||||
|
||||
- name: slack
|
||||
image: woodpeckerci/plugin-slack
|
||||
settings:
|
||||
webhook:
|
||||
from_secret: slack-webhook-url
|
||||
channel: general
|
||||
when:
|
||||
- status: [success, failure]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue