fix(cicd): sync corrected pipelines from cicd branch
Some checks failed
CD Production / Frontend — Lint & Type-check (push) Failing after 6m11s
CD Production / Frontend — Unit Tests (push) Has been skipped
CD Production / Backend — Lint (push) Successful in 10m24s
CD Production / Backend — Unit Tests (push) Failing after 5m32s
CD Production / Verify Preprod Image Exists (push) Has been skipped
CD Production / Promote Images (preprod-SHA → prod) (push) Has been skipped
CD Production / Deploy to Production (k3s) (push) Has been skipped
CD Production / Smoke Tests (push) Has been skipped
CD Production / Notify Success (push) Has been skipped
CD Production / Notify Failure (push) Has been skipped

This commit is contained in:
David 2026-04-04 13:16:48 +02:00
parent 9c511c0619
commit ce8a1049dd
5 changed files with 499 additions and 633 deletions

View File

@ -1,111 +1,197 @@
name: CD Production (Hetzner k3s) name: CD Production
# Production deployment pipeline — Hetzner k3s cluster. # Production pipeline — Hetzner k3s.
# #
# Flow: # SECURITY: Two mandatory gates before any production deployment:
# 1. Promote: re-tag preprod → latest + prod-SHA within Scaleway (no rebuild, no data transfer) # 1. quality-gate — lint + unit tests on the exact commit being deployed
# 2. Deploy: kubectl set image + rollout status (blocks until pods are healthy) # 2. verify-image — confirms preprod-SHA image EXISTS in registry,
# 3. Auto-rollback: kubectl rollout undo if rollout fails # which proves this commit passed the full preprod
# 4. Smoke tests: belt-and-suspenders HTTP health checks # pipeline (lint + unit + integration + docker build).
# 5. Notify Discord # If someone merges to main without going through preprod,
# this step fails and the deployment is blocked.
# #
# Required secrets: # Flow: quality-gate → verify-image → promote → deploy → smoke-tests → notify
# REGISTRY_TOKEN — Scaleway registry token (read + write)
# HETZNER_KUBECONFIG — base64-encoded kubeconfig for xpeditis-prod cluster
# PROD_BACKEND_URL — https://api.xpeditis.com (health check)
# PROD_FRONTEND_URL — https://app.xpeditis.com (health check)
# DISCORD_WEBHOOK_URL — Discord notifications
#
# K8s cluster details (from docs/deployment/hetzner/):
# Namespace: xpeditis-prod
# Deployments: xpeditis-backend (container: backend)
# xpeditis-frontend (container: frontend)
# #
# Secrets required:
# REGISTRY_TOKEN — Scaleway registry (read/write)
# HETZNER_KUBECONFIG — base64: cat ~/.kube/kubeconfig-xpeditis-prod | base64 -w 0
# PROD_BACKEND_URL — https://api.xpeditis.com
# PROD_FRONTEND_URL — https://app.xpeditis.com
# DISCORD_WEBHOOK_URL
on: on:
push: push:
branches: [main] branches: [main]
# Only one prod deployment at a time. Never cancel.
concurrency: concurrency:
group: cd-production group: cd-production
cancel-in-progress: false cancel-in-progress: false
env: env:
REGISTRY: rg.fr-par.scw.cloud/weworkstudio REGISTRY: rg.fr-par.scw.cloud/weworkstudio
IMAGE_BACKEND: rg.fr-par.scw.cloud/weworkstudio/xpeditis-backend NODE_VERSION: '20'
IMAGE_FRONTEND: rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend
K8S_NAMESPACE: xpeditis-prod K8S_NAMESPACE: xpeditis-prod
jobs: jobs:
# ────────────────────────────────────────────────────────────── # ── 1. Quality Gate ──────────────────────────────────────────────────
# 1. Promote preprod → prod tags within Scaleway # Runs on every prod deployment regardless of what happened in preprod.
# imagetools create re-tags at manifest level — no layer backend-quality:
# download/upload, instant even for multi-arch images. name: Backend — Lint
# ──────────────────────────────────────────────────────────────
promote-images:
name: Promote Images (preprod → prod)
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: defaults:
short-sha: ${{ steps.sha.outputs.short }} run:
backend-image: ${{ steps.images.outputs.backend }} working-directory: apps/backend
frontend-image: ${{ steps.images.outputs.frontend }}
steps: steps:
- name: Compute short SHA - uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm run lint
frontend-quality:
name: Frontend — Lint & Type-check
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm run lint
- run: npm run type-check
backend-tests:
name: Backend — Unit Tests
runs-on: ubuntu-latest
needs: backend-quality
defaults:
run:
working-directory: apps/backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm test -- --passWithNoTests
frontend-tests:
name: Frontend — Unit Tests
runs-on: ubuntu-latest
needs: frontend-quality
defaults:
run:
working-directory: apps/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm test -- --passWithNoTests
# ── 2. Image Verification ────────────────────────────────────────────
# Checks that preprod-SHA tags exist for this EXACT commit.
# This is the security gate: if the preprod pipeline never ran for this
# commit (or failed before the docker build step), this job fails and
# the deployment is fully blocked.
verify-image:
name: Verify Preprod Image Exists
runs-on: ubuntu-latest
needs: [backend-tests, frontend-tests]
outputs:
sha: ${{ steps.sha.outputs.short }}
steps:
- name: Short SHA
id: sha id: sha
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- name: Set image references - uses: docker/setup-buildx-action@v3
id: images
run: |
echo "backend=${{ env.IMAGE_BACKEND }}:prod-${{ steps.sha.outputs.short }}" >> $GITHUB_OUTPUT
echo "frontend=${{ env.IMAGE_FRONTEND }}:prod-${{ steps.sha.outputs.short }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx - uses: docker/login-action@v3
uses: docker/setup-buildx-action@v3
- name: Login to Scaleway Registry
uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: nologin username: nologin
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- name: Promote Backend (preprod → latest + prod-SHA) - name: Check backend image preprod-SHA
run: | run: |
docker buildx imagetools create \ TAG="${{ env.REGISTRY }}/xpeditis-backend:preprod-${{ steps.sha.outputs.short }}"
--tag ${{ env.IMAGE_BACKEND }}:latest \ echo "Verifying: $TAG"
--tag ${{ steps.images.outputs.backend }} \ docker buildx imagetools inspect "$TAG" || {
${{ env.IMAGE_BACKEND }}:preprod echo ""
echo "BLOCKED: Image $TAG not found in registry."
echo "This commit was not built by the preprod pipeline."
echo "Merge to preprod first and wait for the full pipeline to succeed."
exit 1
}
- name: Promote Frontend (preprod → latest + prod-SHA) - name: Check frontend image preprod-SHA
run: | run: |
docker buildx imagetools create \ TAG="${{ env.REGISTRY }}/xpeditis-frontend:preprod-${{ steps.sha.outputs.short }}"
--tag ${{ env.IMAGE_FRONTEND }}:latest \ echo "Verifying: $TAG"
--tag ${{ steps.images.outputs.frontend }} \ docker buildx imagetools inspect "$TAG" || {
${{ env.IMAGE_FRONTEND }}:preprod echo ""
echo "BLOCKED: Image $TAG not found in registry."
echo "This commit was not built by the preprod pipeline."
echo "Merge to preprod first and wait for the full pipeline to succeed."
exit 1
}
- name: Verify promoted images # ── 3. Promote Images ────────────────────────────────────────────────
run: | # Re-tags preprod-SHA → latest + prod-SHA within Scaleway.
echo "=== Backend ===" # No rebuild. No layer transfer. Manifest-level operation only.
docker buildx imagetools inspect ${{ steps.images.outputs.backend }} promote-images:
echo "=== Frontend ===" name: Promote Images (preprod-SHA → prod)
docker buildx imagetools inspect ${{ steps.images.outputs.frontend }}
# ──────────────────────────────────────────────────────────────
# 2. Deploy to Hetzner k3s
# kubectl set image → rollout status waits for pods to be
# healthy (readiness probes pass) before the job succeeds.
# Auto-rollback on failure via kubectl rollout undo.
# ──────────────────────────────────────────────────────────────
deploy:
name: Deploy to k3s (xpeditis-prod)
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: promote-images needs: verify-image
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: nologin
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Promote backend
run: |
SHA="${{ needs.verify-image.outputs.sha }}"
docker buildx imagetools create \
--tag ${{ env.REGISTRY }}/xpeditis-backend:latest \
--tag ${{ env.REGISTRY }}/xpeditis-backend:prod-${SHA} \
${{ env.REGISTRY }}/xpeditis-backend:preprod-${SHA}
echo "Backend promoted: preprod-${SHA} → latest + prod-${SHA}"
- name: Promote frontend
run: |
SHA="${{ needs.verify-image.outputs.sha }}"
docker buildx imagetools create \
--tag ${{ env.REGISTRY }}/xpeditis-frontend:latest \
--tag ${{ env.REGISTRY }}/xpeditis-frontend:prod-${SHA} \
${{ env.REGISTRY }}/xpeditis-frontend:preprod-${SHA}
echo "Frontend promoted: preprod-${SHA} → latest + prod-${SHA}"
# ── 4. Deploy to k3s ─────────────────────────────────────────────────
deploy:
name: Deploy to Production (k3s)
runs-on: ubuntu-latest
needs: [verify-image, promote-images]
environment: environment:
name: production name: production
url: https://app.xpeditis.com url: https://app.xpeditis.com
steps: steps:
- name: Configure kubectl - name: Configure kubectl
run: | run: |
@ -113,156 +199,113 @@ jobs:
echo "${{ secrets.HETZNER_KUBECONFIG }}" | base64 -d > ~/.kube/config echo "${{ secrets.HETZNER_KUBECONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config chmod 600 ~/.kube/config
kubectl cluster-info kubectl cluster-info
kubectl get nodes kubectl get nodes -o wide
- name: Deploy Backend - name: Deploy backend
id: deploy-backend
run: | run: |
IMAGE="${{ needs.promote-images.outputs.backend-image }}" SHA="${{ needs.verify-image.outputs.sha }}"
echo "Deploying backend: $IMAGE" IMAGE="${{ env.REGISTRY }}/xpeditis-backend:prod-${SHA}"
kubectl set image deployment/xpeditis-backend \ echo "Deploying: $IMAGE"
backend=$IMAGE \ kubectl set image deployment/xpeditis-backend backend="$IMAGE" -n ${{ env.K8S_NAMESPACE }}
-n ${{ env.K8S_NAMESPACE }} kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=300s
kubectl rollout status deployment/xpeditis-backend \ echo "Backend rollout complete."
-n ${{ env.K8S_NAMESPACE }} \
--timeout=300s
echo "Backend deployed."
- name: Deploy Frontend - name: Deploy frontend
id: deploy-frontend
run: | run: |
IMAGE="${{ needs.promote-images.outputs.frontend-image }}" SHA="${{ needs.verify-image.outputs.sha }}"
echo "Deploying frontend: $IMAGE" IMAGE="${{ env.REGISTRY }}/xpeditis-frontend:prod-${SHA}"
kubectl set image deployment/xpeditis-frontend \ echo "Deploying: $IMAGE"
frontend=$IMAGE \ kubectl set image deployment/xpeditis-frontend frontend="$IMAGE" -n ${{ env.K8S_NAMESPACE }}
-n ${{ env.K8S_NAMESPACE }} kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=300s
kubectl rollout status deployment/xpeditis-frontend \ echo "Frontend rollout complete."
-n ${{ env.K8S_NAMESPACE }} \
--timeout=300s
echo "Frontend deployed."
- name: Auto-rollback on failure - name: Auto-rollback on deployment failure
if: failure() if: failure()
run: | run: |
echo "Deployment failed — rolling back..." echo "Deployment failed — initiating rollback..."
kubectl rollout undo deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} || true kubectl rollout undo deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }}
kubectl rollout undo deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} || true kubectl rollout undo deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }}
kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=120s || true kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=120s
kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=120s || true kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=120s
echo "Previous version restored." echo "Rollback complete. Previous version is live."
# ────────────────────────────────────────────────────────────── # ── 5. Smoke Tests ───────────────────────────────────────────────────
# 3. Smoke Tests # kubectl rollout status already verified pod readiness.
# kubectl rollout status already verifies pod readiness. # These smoke tests validate the full network path:
# These confirm the full network path: # Cloudflare → Hetzner LB → Traefik → pod.
# Cloudflare → Hetzner LB → Traefik → pod.
# ──────────────────────────────────────────────────────────────
smoke-tests: smoke-tests:
name: Smoke Tests name: Smoke Tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: deploy needs: deploy
steps: steps:
- name: Wait for LB propagation - name: Wait for LB propagation
run: sleep 30 run: sleep 30
- name: Health check — Backend - name: Health — Backend
run: | run: |
for i in {1..12}; do for i in {1..12}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
"${{ secrets.PROD_BACKEND_URL }}/api/v1/health" 2>/dev/null || echo "000") "${{ secrets.PROD_BACKEND_URL }}/api/v1/health" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then echo "Backend healthy."; exit 0; fi if [ "$STATUS" = "200" ]; then echo "Backend OK."; exit 0; fi
sleep 15 sleep 15
done done
echo "CRITICAL: Backend unreachable after rollout." echo "CRITICAL: Backend unreachable after 12 attempts."
exit 1 exit 1
- name: Health check — Frontend - name: Health — Frontend
run: | run: |
for i in {1..12}; do for i in {1..12}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
"${{ secrets.PROD_FRONTEND_URL }}" 2>/dev/null || echo "000") "${{ secrets.PROD_FRONTEND_URL }}" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then echo "Frontend healthy."; exit 0; fi if [ "$STATUS" = "200" ]; then echo "Frontend OK."; exit 0; fi
sleep 15 sleep 15
done done
echo "CRITICAL: Frontend unreachable after rollout." echo "CRITICAL: Frontend unreachable after 12 attempts."
exit 1 exit 1
# ────────────────────────────────────────────────────────────── # ── Notifications ────────────────────────────────────────────────────
# 4. Deployment Summary
# ──────────────────────────────────────────────────────────────
summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [promote-images, smoke-tests]
if: success()
steps:
- name: Write summary
run: |
echo "## Production Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Backend** | \`${{ needs.promote-images.outputs.backend-image }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Frontend** | \`${{ needs.promote-images.outputs.frontend-image }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Source** | Promoted from \`preprod\` tag — no rebuild |" >> $GITHUB_STEP_SUMMARY
echo "| **Cluster** | Hetzner k3s — namespace \`xpeditis-prod\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To rollback: [Run rollback workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/rollback.yml)" >> $GITHUB_STEP_SUMMARY
# ──────────────────────────────────────────────────────────────
# Discord — Success
# ──────────────────────────────────────────────────────────────
notify-success: notify-success:
name: Notify Success name: Notify Success
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [promote-images, smoke-tests] needs: [verify-image, smoke-tests]
if: success() if: success()
steps: steps:
- name: Send Discord notification - run: |
run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"embeds": [{ "embeds": [{
"title": "🚀 Production Deployed & Healthy", "title": "🚀 Production Deployed & Healthy",
"color": 3066993, "color": 3066993,
"fields": [ "fields": [
{"name": "Author", "value": "${{ github.actor }}", "inline": true}, {"name": "Author", "value": "${{ github.actor }}", "inline": true},
{"name": "Version", "value": "`prod-${{ needs.promote-images.outputs.short-sha }}`", "inline": true}, {"name": "Version", "value": "`prod-${{ needs.verify-image.outputs.sha }}`", "inline": true},
{"name": "Commit", "value": "[`${{ github.sha }}`](${{ github.event.head_commit.url }})", "inline": false},
{"name": "Registry", "value": "Scaleway — promoted from `preprod`, no rebuild", "inline": false},
{"name": "Cluster", "value": "Hetzner k3s — `xpeditis-prod`", "inline": false}, {"name": "Cluster", "value": "Hetzner k3s — `xpeditis-prod`", "inline": false},
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false} {"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Production"} "footer": {"text": "Xpeditis CI/CD • Production"}
}] }]
}' ${{ secrets.DISCORD_WEBHOOK_URL }} }' ${{ secrets.DISCORD_WEBHOOK_URL }}
# ──────────────────────────────────────────────────────────────
# Discord — Failure (CRITICAL)
# ──────────────────────────────────────────────────────────────
notify-failure: notify-failure:
name: Notify Failure name: Notify Failure
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [promote-images, deploy, smoke-tests] needs: [backend-quality, frontend-quality, backend-tests, frontend-tests, verify-image, promote-images, deploy, smoke-tests]
if: failure() if: failure()
steps: steps:
- name: Send Discord notification - run: |
run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"content": "@here PRODUCTION DEPLOYMENT FAILED", "content": "@here PRODUCTION PIPELINE FAILED",
"embeds": [{ "embeds": [{
"title": "🔴 PRODUCTION PIPELINE FAILED", "title": "🔴 Production Pipeline Failed",
"description": "Auto-rollback was triggered if deployment failed. Check rollout history.", "description": "Check the workflow for details. Auto-rollback was triggered if the failure was during deploy.",
"color": 15158332, "color": 15158332,
"fields": [ "fields": [
{"name": "Author", "value": "${{ github.actor }}", "inline": true}, {"name": "Author", "value": "${{ github.actor }}", "inline": true},
{"name": "Commit", "value": "[`${{ github.sha }}`](${{ github.event.head_commit.url }})", "inline": true}, {"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false},
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}, {"name": "Rollback", "value": "[Run rollback workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/rollback.yml)", "inline": false}
{"name": "Manual rollback", "value": "[Run rollback workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/rollback.yml)", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Production"} "footer": {"text": "Xpeditis CI/CD • Production"}
}] }]

View File

@ -1,23 +1,22 @@
name: CD Preprod name: CD Preprod
# Full pipeline for the preprod branch. # Full pipeline triggered on every push to preprod.
# Flow: quality → integration tests → Docker build & push → deploy → smoke tests → notify # Flow: lint → unit tests → integration tests → docker build → deploy → smoke tests → notify
# #
# Required secrets: # Secrets required:
# REGISTRY_TOKEN — Scaleway container registry token # REGISTRY_TOKEN — Scaleway registry (read/write)
# NEXT_PUBLIC_API_URL Preprod API URL (e.g. https://api.preprod.xpeditis.com) # NEXT_PUBLIC_API_URL — https://api.preprod.xpeditis.com
# NEXT_PUBLIC_APP_URL Preprod app URL (e.g. https://preprod.xpeditis.com) # NEXT_PUBLIC_APP_URL — https://preprod.xpeditis.com
# PORTAINER_WEBHOOK_BACKEND — Portainer webhook for preprod backend service # PORTAINER_WEBHOOK_BACKEND — Portainer webhook (preprod backend)
# PORTAINER_WEBHOOK_FRONTEND — Portainer webhook for preprod frontend service # PORTAINER_WEBHOOK_FRONTEND— Portainer webhook (preprod frontend)
# PREPROD_BACKEND_URL Health check URL (e.g. https://api.preprod.xpeditis.com) # PREPROD_BACKEND_URL — https://api.preprod.xpeditis.com
# PREPROD_FRONTEND_URL Health check URL (e.g. https://preprod.xpeditis.com) # PREPROD_FRONTEND_URL — https://preprod.xpeditis.com
# DISCORD_WEBHOOK_URL — Discord deployment notifications # DISCORD_WEBHOOK_URL
on: on:
push: push:
branches: [preprod] branches: [preprod]
# Only one preprod deployment at a time. Never cancel an in-progress deployment.
concurrency: concurrency:
group: cd-preprod group: cd-preprod
cancel-in-progress: false cancel-in-progress: false
@ -27,81 +26,80 @@ env:
NODE_VERSION: '20' NODE_VERSION: '20'
jobs: jobs:
# ────────────────────────────────────────── # ── 1. Lint ─────────────────────────────────────────────────────────
# 1. Lint & Type-check backend-quality:
# ────────────────────────────────────────── name: Backend — Lint
quality:
name: Quality (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/backend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm run lint
- name: Install dependencies frontend-quality:
run: npm ci --legacy-peer-deps name: Frontend — Lint & Type-check
- name: Lint
run: npm run lint
- name: Type-check (frontend only)
if: matrix.app == 'frontend'
run: npm run type-check
# ──────────────────────────────────────────
# 2. Unit Tests
# ──────────────────────────────────────────
unit-tests:
name: Unit Tests (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: quality
strategy:
fail-fast: true
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/frontend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm run lint
- run: npm run type-check
- name: Install dependencies # ── 2. Unit Tests ────────────────────────────────────────────────────
run: npm ci --legacy-peer-deps backend-tests:
name: Backend — Unit Tests
runs-on: ubuntu-latest
needs: backend-quality
defaults:
run:
working-directory: apps/backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm test -- --passWithNoTests
- name: Run unit tests frontend-tests:
run: npm test -- --passWithNoTests --coverage name: Frontend — Unit Tests
runs-on: ubuntu-latest
needs: frontend-quality
defaults:
run:
working-directory: apps/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm test -- --passWithNoTests
# ────────────────────────────────────────── # ── 3. Integration Tests ─────────────────────────────────────────────
# 3. Integration Tests
# ──────────────────────────────────────────
integration-tests: integration-tests:
name: Integration Tests name: Backend — Integration Tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: unit-tests needs: [backend-tests, frontend-tests]
defaults: defaults:
run: run:
working-directory: apps/backend working-directory: apps/backend
@ -120,7 +118,6 @@ jobs:
--health-retries 10 --health-retries 10
ports: ports:
- 5432:5432 - 5432:5432
redis: redis:
image: redis:7-alpine image: redis:7-alpine
options: >- options: >-
@ -133,17 +130,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Run integration tests - name: Run integration tests
env: env:
NODE_ENV: test NODE_ENV: test
@ -152,50 +144,40 @@ jobs:
DATABASE_USER: xpeditis_test DATABASE_USER: xpeditis_test
DATABASE_PASSWORD: xpeditis_test_password DATABASE_PASSWORD: xpeditis_test_password
DATABASE_NAME: xpeditis_test DATABASE_NAME: xpeditis_test
DATABASE_SYNCHRONIZE: false DATABASE_SYNCHRONIZE: 'false'
REDIS_HOST: localhost REDIS_HOST: localhost
REDIS_PORT: 6379 REDIS_PORT: 6379
REDIS_PASSWORD: '' REDIS_PASSWORD: ''
JWT_SECRET: test-secret-key-for-ci-only JWT_SECRET: test-secret-key-ci
SMTP_HOST: localhost SMTP_HOST: localhost
SMTP_PORT: 1025 SMTP_PORT: 1025
SMTP_FROM: test@xpeditis.com SMTP_FROM: test@xpeditis.com
run: npm run test:integration -- --passWithNoTests run: npm run test:integration -- --passWithNoTests
# ────────────────────────────────────────── # ── 4. Docker Build & Push ───────────────────────────────────────────
# 4a. Docker Build & Push — Backend # Tags: preprod (latest for this env) + preprod-SHA (used by prod for exact promotion)
# ──────────────────────────────────────────
build-backend: build-backend:
name: Build & Push Backend name: Build Backend
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: integration-tests needs: integration-tests
outputs: outputs:
image-tag: ${{ steps.sha.outputs.short }} sha: ${{ steps.sha.outputs.short }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Short SHA
- name: Compute short SHA
id: sha id: sha
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v3
- name: Set up Docker Buildx - uses: docker/login-action@v3
uses: docker/setup-buildx-action@v3
- name: Login to Scaleway Registry
uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: nologin username: nologin
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- uses: docker/build-push-action@v5
- name: Build and push Backend image
uses: docker/build-push-action@v5
with: with:
context: ./apps/backend context: ./apps/backend
file: ./apps/backend/Dockerfile file: ./apps/backend/Dockerfile
push: true push: true
# Tag with branch name AND commit SHA for traceability and prod promotion
tags: | tags: |
${{ env.REGISTRY }}/xpeditis-backend:preprod ${{ env.REGISTRY }}/xpeditis-backend:preprod
${{ env.REGISTRY }}/xpeditis-backend:preprod-${{ steps.sha.outputs.short }} ${{ env.REGISTRY }}/xpeditis-backend:preprod-${{ steps.sha.outputs.short }}
@ -203,35 +185,24 @@ jobs:
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache,mode=max cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache,mode=max
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
# ──────────────────────────────────────────
# 4b. Docker Build & Push — Frontend
# ──────────────────────────────────────────
build-frontend: build-frontend:
name: Build & Push Frontend name: Build Frontend
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: integration-tests needs: integration-tests
outputs: outputs:
image-tag: ${{ steps.sha.outputs.short }} sha: ${{ steps.sha.outputs.short }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Short SHA
- name: Compute short SHA
id: sha id: sha
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v3
- name: Set up Docker Buildx - uses: docker/login-action@v3
uses: docker/setup-buildx-action@v3
- name: Login to Scaleway Registry
uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: nologin username: nologin
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- uses: docker/build-push-action@v5
- name: Build and push Frontend image
uses: docker/build-push-action@v5
with: with:
context: ./apps/frontend context: ./apps/frontend
file: ./apps/frontend/Dockerfile file: ./apps/frontend/Dockerfile
@ -246,151 +217,91 @@ jobs:
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL }} NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL }}
# ────────────────────────────────────────── # ── 5. Deploy via Portainer ──────────────────────────────────────────
# 5. Deploy to Preprod via Portainer
# ──────────────────────────────────────────
deploy: deploy:
name: Deploy to Preprod name: Deploy to Preprod
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [build-backend, build-frontend] needs: [build-backend, build-frontend]
environment: preprod environment: preprod
steps: steps:
- name: Trigger Backend deployment - name: Deploy backend
run: | run: |
echo "Deploying backend (preprod-${{ needs.build-backend.outputs.image-tag }})..." curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_BACKEND }}"
curl -sf -X POST \
-H "Content-Type: application/json" \
"${{ secrets.PORTAINER_WEBHOOK_BACKEND }}"
echo "Backend webhook triggered." echo "Backend webhook triggered."
- name: Wait for backend startup
- name: Wait for backend to stabilize
run: sleep 20 run: sleep 20
- name: Deploy frontend
- name: Trigger Frontend deployment
run: | run: |
echo "Deploying frontend (preprod-${{ needs.build-frontend.outputs.image-tag }})..." curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}"
curl -sf -X POST \
-H "Content-Type: application/json" \
"${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}"
echo "Frontend webhook triggered." echo "Frontend webhook triggered."
# ────────────────────────────────────────── # ── 6. Smoke Tests ───────────────────────────────────────────────────
# 6. Smoke Tests — verify preprod is healthy
# ──────────────────────────────────────────
smoke-tests: smoke-tests:
name: Smoke Tests name: Smoke Tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: deploy needs: deploy
steps: steps:
- name: Wait for services to start - name: Wait for services
run: sleep 40 run: sleep 40
- name: Health — Backend
- name: Health check — Backend
run: | run: |
echo "Checking backend health..." for i in {1..12}; do
for i in {1..10}; do STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ "${{ secrets.PREPROD_BACKEND_URL }}/api/v1/health" 2>/dev/null || echo "000")
--max-time 10 \
"${{ secrets.PREPROD_BACKEND_URL }}/health" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then if [ "$STATUS" = "200" ]; then echo "Backend OK."; exit 0; fi
echo "Backend is healthy."
exit 0
fi
sleep 15 sleep 15
done done
echo "Backend health check failed after 10 attempts." echo "Backend unreachable after 12 attempts."
exit 1 exit 1
- name: Health — Frontend
- name: Health check — Frontend
run: | run: |
echo "Checking frontend health..." for i in {1..12}; do
for i in {1..10}; do STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
--max-time 10 \
"${{ secrets.PREPROD_FRONTEND_URL }}" 2>/dev/null || echo "000") "${{ secrets.PREPROD_FRONTEND_URL }}" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then if [ "$STATUS" = "200" ]; then echo "Frontend OK."; exit 0; fi
echo "Frontend is healthy."
exit 0
fi
sleep 15 sleep 15
done done
echo "Frontend health check failed after 10 attempts." echo "Frontend unreachable after 12 attempts."
exit 1 exit 1
# ────────────────────────────────────────── # ── Notifications ────────────────────────────────────────────────────
# 7. Deployment Summary
# ──────────────────────────────────────────
summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [build-backend, build-frontend, smoke-tests]
if: success()
steps:
- name: Write summary
run: |
echo "## Preprod Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Backend image** | \`${{ env.REGISTRY }}/xpeditis-backend:preprod-${{ needs.build-backend.outputs.image-tag }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Frontend image** | \`${{ env.REGISTRY }}/xpeditis-frontend:preprod-${{ needs.build-frontend.outputs.image-tag }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To promote this exact build to production, merge this commit to \`main\`." >> $GITHUB_STEP_SUMMARY
# ──────────────────────────────────────────
# Discord — Success
# ──────────────────────────────────────────
notify-success: notify-success:
name: Notify Success name: Notify Success
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [build-backend, build-frontend, smoke-tests] needs: [build-backend, build-frontend, smoke-tests]
if: success() if: success()
steps: steps:
- name: Send Discord notification - run: |
run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"embeds": [{ "embeds": [{
"title": "✅ Preprod Deployed & Healthy", "title": "✅ Preprod Deployed & Healthy",
"color": 3066993, "color": 3066993,
"fields": [ "fields": [
{"name": "Author", "value": "${{ github.actor }}", "inline": true}, {"name": "Author", "value": "${{ github.actor }}", "inline": true},
{"name": "Commit", "value": "[`${{ github.sha }}`](${{ github.event.head_commit.url }})", "inline": true}, {"name": "SHA", "value": "`${{ needs.build-backend.outputs.sha }}`", "inline": true},
{"name": "Backend", "value": "`preprod-${{ needs.build-backend.outputs.image-tag }}`", "inline": false}, {"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
{"name": "Frontend", "value": "`preprod-${{ needs.build-frontend.outputs.image-tag }}`", "inline": false},
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Preprod"} "footer": {"text": "Xpeditis CI/CD • Preprod"}
}] }]
}' ${{ secrets.DISCORD_WEBHOOK_URL }} }' ${{ secrets.DISCORD_WEBHOOK_URL }}
# ──────────────────────────────────────────
# Discord — Failure
# ──────────────────────────────────────────
notify-failure: notify-failure:
name: Notify Failure name: Notify Failure
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [quality, unit-tests, integration-tests, build-backend, build-frontend, deploy, smoke-tests] needs: [backend-quality, frontend-quality, backend-tests, frontend-tests, integration-tests, build-backend, build-frontend, deploy, smoke-tests]
if: failure() if: failure()
steps: steps:
- name: Send Discord notification - run: |
run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"embeds": [{ "embeds": [{
"title": "❌ Preprod Pipeline Failed", "title": "❌ Preprod Pipeline Failed",
"description": "Preprod was NOT deployed. Fix the issue before retrying.", "description": "Preprod was NOT deployed.",
"color": 15158332, "color": 15158332,
"fields": [ "fields": [
{"name": "Author", "value": "${{ github.actor }}", "inline": true}, {"name": "Author", "value": "${{ github.actor }}", "inline": true},
{"name": "Commit", "value": "[`${{ github.sha }}`](${{ github.event.head_commit.url }})", "inline": true}, {"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Preprod"} "footer": {"text": "Xpeditis CI/CD • Preprod"}
}] }]

View File

@ -1,8 +1,5 @@
name: Dev CI name: Dev CI
# Fast feedback loop for the dev branch.
# Runs lint + unit tests only — no Docker build, no deployment.
on: on:
push: push:
branches: [dev] branches: [dev]
@ -17,96 +14,90 @@ env:
NODE_VERSION: '20' NODE_VERSION: '20'
jobs: jobs:
# ────────────────────────────────────────── backend-quality:
# Lint & Type-check name: Backend — Lint
# ──────────────────────────────────────────
quality:
name: Quality (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/backend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm run lint
- name: Install dependencies frontend-quality:
run: npm ci --legacy-peer-deps name: Frontend — Lint & Type-check
- name: Lint
run: npm run lint
- name: Type-check (frontend only)
if: matrix.app == 'frontend'
run: npm run type-check
# ──────────────────────────────────────────
# Unit Tests
# ──────────────────────────────────────────
unit-tests:
name: Unit Tests (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: quality
strategy:
fail-fast: false
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/frontend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm run lint
- run: npm run type-check
- name: Install dependencies backend-tests:
run: npm ci --legacy-peer-deps name: Backend — Unit Tests
runs-on: ubuntu-latest
needs: backend-quality
defaults:
run:
working-directory: apps/backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm test -- --passWithNoTests
- name: Run unit tests frontend-tests:
run: npm test -- --passWithNoTests --coverage name: Frontend — Unit Tests
runs-on: ubuntu-latest
needs: frontend-quality
defaults:
run:
working-directory: apps/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm test -- --passWithNoTests
# ──────────────────────────────────────────
# Discord notification on failure
# ──────────────────────────────────────────
notify-failure: notify-failure:
name: Notify Failure name: Notify Failure
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [quality, unit-tests] needs: [backend-quality, frontend-quality, backend-tests, frontend-tests]
if: failure() if: failure()
steps: steps:
- name: Send Discord notification - name: Discord
run: | run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"embeds": [{ "embeds": [{
"title": "❌ Dev CI Failed", "title": "❌ Dev CI Failed",
"description": "Fix the issues before merging to preprod.",
"color": 15158332, "color": 15158332,
"fields": [ "fields": [
{"name": "Branch", "value": "`${{ github.ref_name }}`", "inline": true}, {"name": "Branch", "value": "`${{ github.ref_name }}`", "inline": true},
{"name": "Author", "value": "${{ github.actor }}", "inline": true}, {"name": "Author", "value": "${{ github.actor }}", "inline": true},
{"name": "Commit", "value": "[`${{ github.sha }}`](${{ github.event.head_commit.url }})", "inline": false}, {"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD"} "footer": {"text": "Xpeditis CI • Dev"}
}] }]
}' ${{ secrets.DISCORD_WEBHOOK_URL }} }' ${{ secrets.DISCORD_WEBHOOK_URL }}

View File

@ -1,10 +1,8 @@
name: PR Checks name: PR Checks
# Validation gate for pull requests. # Required status checks — configure these in branch protection rules.
# PRs to preprod → lint + unit tests + integration tests # PRs to preprod : lint + type-check + unit tests + integration tests
# PRs to main → lint + unit tests only (code was integration-tested in preprod already) # PRs to main : lint + type-check + unit tests only
#
# Configure these as required status checks in GitHub branch protection rules.
on: on:
pull_request: pull_request:
@ -18,82 +16,80 @@ env:
NODE_VERSION: '20' NODE_VERSION: '20'
jobs: jobs:
# ────────────────────────────────────────── backend-quality:
# Lint & Type-check (both apps, parallel) name: Backend — Lint
# ──────────────────────────────────────────
quality:
name: Quality (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/backend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm run lint
- name: Install dependencies frontend-quality:
run: npm ci --legacy-peer-deps name: Frontend — Lint & Type-check
- name: Lint
run: npm run lint
- name: Type-check (frontend only)
if: matrix.app == 'frontend'
run: npm run type-check
# ──────────────────────────────────────────
# Unit Tests (both apps, parallel)
# ──────────────────────────────────────────
unit-tests:
name: Unit Tests (${{ matrix.app }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: quality
strategy:
fail-fast: false
matrix:
app: [backend, frontend]
defaults: defaults:
run: run:
working-directory: apps/${{ matrix.app }} working-directory: apps/frontend
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/${{ matrix.app }}/package-lock.json cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm run lint
- run: npm run type-check
- name: Install dependencies backend-tests:
run: npm ci --legacy-peer-deps name: Backend — Unit Tests
runs-on: ubuntu-latest
needs: backend-quality
defaults:
run:
working-directory: apps/backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- run: npm test -- --passWithNoTests
- name: Run unit tests frontend-tests:
run: npm test -- --passWithNoTests --coverage name: Frontend — Unit Tests
runs-on: ubuntu-latest
needs: frontend-quality
defaults:
run:
working-directory: apps/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: apps/frontend/package-lock.json
- run: npm ci --legacy-peer-deps
- run: npm test -- --passWithNoTests
# ────────────────────────────────────────── # Integration tests — PRs to preprod only
# Integration Tests — PRs to preprod only # Code going to main was already integration-tested when it passed through preprod
# ──────────────────────────────────────────
integration-tests: integration-tests:
name: Integration Tests name: Backend — Integration Tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: unit-tests needs: backend-tests
if: github.base_ref == 'preprod' if: github.base_ref == 'preprod'
defaults: defaults:
run: run:
working-directory: apps/backend working-directory: apps/backend
@ -112,7 +108,6 @@ jobs:
--health-retries 10 --health-retries 10
ports: ports:
- 5432:5432 - 5432:5432
redis: redis:
image: redis:7-alpine image: redis:7-alpine
options: >- options: >-
@ -125,17 +120,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: 'npm' cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json cache-dependency-path: apps/backend/package-lock.json
- run: npm install --legacy-peer-deps
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Run integration tests - name: Run integration tests
env: env:
NODE_ENV: test NODE_ENV: test
@ -144,33 +134,12 @@ jobs:
DATABASE_USER: xpeditis_test DATABASE_USER: xpeditis_test
DATABASE_PASSWORD: xpeditis_test_password DATABASE_PASSWORD: xpeditis_test_password
DATABASE_NAME: xpeditis_test DATABASE_NAME: xpeditis_test
DATABASE_SYNCHRONIZE: false DATABASE_SYNCHRONIZE: 'false'
REDIS_HOST: localhost REDIS_HOST: localhost
REDIS_PORT: 6379 REDIS_PORT: 6379
REDIS_PASSWORD: '' REDIS_PASSWORD: ''
JWT_SECRET: test-secret-key-for-ci-only JWT_SECRET: test-secret-key-ci
SMTP_HOST: localhost SMTP_HOST: localhost
SMTP_PORT: 1025 SMTP_PORT: 1025
SMTP_FROM: test@xpeditis.com SMTP_FROM: test@xpeditis.com
run: npm run test:integration -- --passWithNoTests run: npm run test:integration -- --passWithNoTests
# ──────────────────────────────────────────
# PR Summary
# ──────────────────────────────────────────
pr-summary:
name: PR Summary
runs-on: ubuntu-latest
needs: [quality, unit-tests]
if: always()
steps:
- name: Write job summary
run: |
echo "## PR Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Quality (lint + type-check) | ${{ needs.quality.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Unit Tests | ${{ needs.unit-tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Target Branch | \`${{ github.base_ref }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Author | ${{ github.actor }} |" >> $GITHUB_STEP_SUMMARY

View File

@ -1,16 +1,24 @@
name: Rollback name: Rollback
# Emergency rollback for production (Hetzner k3s) and preprod (Portainer). # Emergency rollback — production (Hetzner k3s) and preprod (Portainer).
# All images are on Scaleway registry.
# #
# Production (k3s): # Production strategies:
# Option A — "previous": kubectl rollout undo (instant, reverts to last ReplicaSet) # previous — kubectl rollout undo (fastest, reverts to previous ReplicaSet)
# Option B — "specific-version": kubectl set image to a Scaleway prod-SHA tag # specific-version — kubectl set image to a specific prod-SHA tag
# #
# Preprod (Portainer): # Preprod strategy:
# Re-tags a Scaleway preprod-SHA image back to :preprod, triggers Portainer webhook. # Re-tags a preprod-SHA image back to :preprod, triggers Portainer webhook.
# #
# Run from: GitHub Actions → Workflows → Rollback → Run workflow # Secrets required:
# REGISTRY_TOKEN — Scaleway registry
# HETZNER_KUBECONFIG — base64 kubeconfig (production only)
# PORTAINER_WEBHOOK_BACKEND — Portainer webhook preprod backend
# PORTAINER_WEBHOOK_FRONTEND — Portainer webhook preprod frontend
# PROD_BACKEND_URL — https://api.xpeditis.com
# PROD_FRONTEND_URL — https://app.xpeditis.com
# PREPROD_BACKEND_URL — https://api.preprod.xpeditis.com
# PREPROD_FRONTEND_URL — https://preprod.xpeditis.com
# DISCORD_WEBHOOK_URL
on: on:
workflow_dispatch: workflow_dispatch:
@ -19,41 +27,31 @@ on:
description: 'Target environment' description: 'Target environment'
required: true required: true
type: choice type: choice
options: options: [production, preprod]
- production
- preprod
strategy: strategy:
description: 'Rollback strategy ("previous" = kubectl rollout undo, prod only)' description: 'Strategy (production only — "previous" = instant kubectl undo)'
required: true required: true
type: choice type: choice
options: options: [previous, specific-version]
- previous
- specific-version
version_tag: version_tag:
description: 'Tag for specific-version (e.g. prod-a1b2c3d or preprod-a1b2c3d)' description: 'Tag for specific-version (e.g. prod-a1b2c3d or preprod-a1b2c3d)'
required: false required: false
type: string type: string
reason: reason:
description: 'Reason for rollback (audit trail)' description: 'Reason (audit trail)'
required: true required: true
type: string type: string
env: env:
REGISTRY: rg.fr-par.scw.cloud/weworkstudio REGISTRY: rg.fr-par.scw.cloud/weworkstudio
IMAGE_BACKEND: rg.fr-par.scw.cloud/weworkstudio/xpeditis-backend
IMAGE_FRONTEND: rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend
K8S_NAMESPACE: xpeditis-prod K8S_NAMESPACE: xpeditis-prod
jobs: jobs:
# ──────────────────────────────────────────
# Validate inputs
# ──────────────────────────────────────────
validate: validate:
name: Validate Inputs name: Validate Inputs
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Validate - name: Check inputs
run: | run: |
ENV="${{ github.event.inputs.environment }}" ENV="${{ github.event.inputs.environment }}"
STRATEGY="${{ github.event.inputs.strategy }}" STRATEGY="${{ github.event.inputs.strategy }}"
@ -64,38 +62,31 @@ jobs:
exit 1 exit 1
fi fi
if [ "$STRATEGY" = "specific-version" ] && [ "$ENV" = "production" ]; then if [ "$ENV" = "production" ] && [ "$STRATEGY" = "specific-version" ]; then
if [[ ! "$TAG" =~ ^prod- ]]; then if [[ ! "$TAG" =~ ^prod- ]]; then
echo "ERROR: Production tag must start with 'prod-' (got: $TAG)" echo "ERROR: Production tag must start with 'prod-' (got: $TAG)"
exit 1 exit 1
fi fi
fi fi
if [ "$STRATEGY" = "specific-version" ] && [ "$ENV" = "preprod" ]; then if [ "$ENV" = "preprod" ]; then
if [[ ! "$TAG" =~ ^preprod- ]]; then if [[ ! "$TAG" =~ ^preprod- ]]; then
echo "ERROR: Preprod tag must start with 'preprod-' (got: $TAG)" echo "ERROR: Preprod tag must start with 'preprod-' (got: $TAG)"
exit 1 exit 1
fi fi
fi fi
echo "Validation passed." echo "Validated — env: $ENV | strategy: $STRATEGY | tag: ${TAG:-N/A} | reason: ${{ github.event.inputs.reason }}"
echo " Environment : $ENV"
echo " Strategy : $STRATEGY"
echo " Version : ${TAG:-N/A (previous)}"
echo " Reason : ${{ github.event.inputs.reason }}"
# ────────────────────────────────────────── # ── Production rollback via kubectl ──────────────────────────────────
# PRODUCTION ROLLBACK — k3s via kubectl
# ──────────────────────────────────────────
rollback-production: rollback-production:
name: Rollback Production (k3s) name: Rollback Production
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: validate needs: validate
if: github.event.inputs.environment == 'production' if: github.event.inputs.environment == 'production'
environment: environment:
name: production name: production
url: https://app.xpeditis.com url: https://app.xpeditis.com
steps: steps:
- name: Configure kubectl - name: Configure kubectl
run: | run: |
@ -104,26 +95,16 @@ jobs:
chmod 600 ~/.kube/config chmod 600 ~/.kube/config
kubectl cluster-info kubectl cluster-info
# ── Strategy A: kubectl rollout undo (fastest) - name: Rollback — previous version
- name: Rollback to previous version
if: github.event.inputs.strategy == 'previous' if: github.event.inputs.strategy == 'previous'
run: | run: |
echo "Rolling back backend..."
kubectl rollout undo deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} kubectl rollout undo deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }}
kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
echo "Rolling back frontend..."
kubectl rollout undo deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} kubectl rollout undo deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }}
kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
kubectl get pods -n ${{ env.K8S_NAMESPACE }} kubectl get pods -n ${{ env.K8S_NAMESPACE }}
# ── Strategy B: kubectl set image to specific Scaleway tag - name: Login to Scaleway (for image verification)
- name: Set up Docker Buildx (for image inspect)
if: github.event.inputs.strategy == 'specific-version'
uses: docker/setup-buildx-action@v3
- name: Login to Scaleway Registry
if: github.event.inputs.strategy == 'specific-version' if: github.event.inputs.strategy == 'specific-version'
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
@ -131,103 +112,81 @@ jobs:
username: nologin username: nologin
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- name: Rollback to specific version - uses: docker/setup-buildx-action@v3
if: github.event.inputs.strategy == 'specific-version'
- name: Rollback — specific version
if: github.event.inputs.strategy == 'specific-version' if: github.event.inputs.strategy == 'specific-version'
run: | run: |
TAG="${{ github.event.inputs.version_tag }}" TAG="${{ github.event.inputs.version_tag }}"
BACKEND_IMAGE="${{ env.IMAGE_BACKEND }}:${TAG}" BACKEND="${{ env.REGISTRY }}/xpeditis-backend:${TAG}"
FRONTEND_IMAGE="${{ env.IMAGE_FRONTEND }}:${TAG}" FRONTEND="${{ env.REGISTRY }}/xpeditis-frontend:${TAG}"
echo "Verifying images exist in Scaleway..." echo "Verifying images exist..."
docker buildx imagetools inspect "$BACKEND_IMAGE" || \ docker buildx imagetools inspect "$BACKEND" || { echo "ERROR: $BACKEND not found"; exit 1; }
{ echo "ERROR: Backend image not found: $BACKEND_IMAGE"; exit 1; } docker buildx imagetools inspect "$FRONTEND" || { echo "ERROR: $FRONTEND not found"; exit 1; }
docker buildx imagetools inspect "$FRONTEND_IMAGE" || \
{ echo "ERROR: Frontend image not found: $FRONTEND_IMAGE"; exit 1; }
echo "Deploying backend: $BACKEND_IMAGE" kubectl set image deployment/xpeditis-backend backend="$BACKEND" -n ${{ env.K8S_NAMESPACE }}
kubectl set image deployment/xpeditis-backend backend="$BACKEND_IMAGE" -n ${{ env.K8S_NAMESPACE }}
kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
echo "Deploying frontend: $FRONTEND_IMAGE" kubectl set image deployment/xpeditis-frontend frontend="$FRONTEND" -n ${{ env.K8S_NAMESPACE }}
kubectl set image deployment/xpeditis-frontend frontend="$FRONTEND_IMAGE" -n ${{ env.K8S_NAMESPACE }}
kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
kubectl get pods -n ${{ env.K8S_NAMESPACE }} kubectl get pods -n ${{ env.K8S_NAMESPACE }}
- name: Show rollout history - name: Rollout history
if: always() if: always()
run: | run: |
echo "=== Backend rollout history ==="
kubectl rollout history deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} || true kubectl rollout history deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} || true
echo "=== Frontend rollout history ==="
kubectl rollout history deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} || true kubectl rollout history deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} || true
# ────────────────────────────────────────── # ── Preprod rollback via Portainer ───────────────────────────────────
# PREPROD ROLLBACK — Scaleway re-tag + Portainer
# ──────────────────────────────────────────
rollback-preprod: rollback-preprod:
name: Rollback Preprod (Portainer) name: Rollback Preprod
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: validate needs: validate
if: github.event.inputs.environment == 'preprod' if: github.event.inputs.environment == 'preprod'
steps: steps:
- name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v3
- name: Login to Scaleway Registry - uses: docker/login-action@v3
uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: nologin username: nologin
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- name: Verify target images exist - name: Verify target image exists
run: | run: |
TAG="${{ github.event.inputs.version_tag }}" TAG="${{ github.event.inputs.version_tag }}"
docker buildx imagetools inspect "${{ env.IMAGE_BACKEND }}:${TAG}" || \ docker buildx imagetools inspect "${{ env.REGISTRY }}/xpeditis-backend:${TAG}" || \
{ echo "ERROR: Backend image not found: $TAG"; exit 1; } { echo "ERROR: backend image not found: $TAG"; exit 1; }
docker buildx imagetools inspect "${{ env.IMAGE_FRONTEND }}:${TAG}" || \ docker buildx imagetools inspect "${{ env.REGISTRY }}/xpeditis-frontend:${TAG}" || \
{ echo "ERROR: Frontend image not found: $TAG"; exit 1; } { echo "ERROR: frontend image not found: $TAG"; exit 1; }
- name: Re-tag target version as preprod - name: Re-tag as preprod
run: | run: |
TAG="${{ github.event.inputs.version_tag }}" TAG="${{ github.event.inputs.version_tag }}"
echo "Re-tagging $TAG → preprod..."
docker buildx imagetools create \ docker buildx imagetools create \
--tag ${{ env.IMAGE_BACKEND }}:preprod \ --tag ${{ env.REGISTRY }}/xpeditis-backend:preprod \
${{ env.IMAGE_BACKEND }}:${TAG} ${{ env.REGISTRY }}/xpeditis-backend:${TAG}
docker buildx imagetools create \ docker buildx imagetools create \
--tag ${{ env.IMAGE_FRONTEND }}:preprod \ --tag ${{ env.REGISTRY }}/xpeditis-frontend:preprod \
${{ env.IMAGE_FRONTEND }}:${TAG} ${{ env.REGISTRY }}/xpeditis-frontend:${TAG}
echo "Re-tag complete."
- name: Trigger Backend deployment (Portainer) - name: Deploy backend (Portainer)
run: | run: curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_BACKEND }}"
curl -sf -X POST -H "Content-Type: application/json" \ - run: sleep 20
"${{ secrets.PORTAINER_WEBHOOK_BACKEND }}" - name: Deploy frontend (Portainer)
echo "Backend webhook triggered." run: curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}"
- name: Wait for backend # ── Smoke Tests ───────────────────────────────────────────────────────
run: sleep 20
- name: Trigger Frontend deployment (Portainer)
run: |
curl -sf -X POST -H "Content-Type: application/json" \
"${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}"
echo "Frontend webhook triggered."
# ──────────────────────────────────────────
# Smoke Tests
# ──────────────────────────────────────────
smoke-tests: smoke-tests:
name: Smoke Tests name: Smoke Tests Post-Rollback
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [rollback-production, rollback-preprod] needs: [rollback-production, rollback-preprod]
if: always() && (needs.rollback-production.result == 'success' || needs.rollback-preprod.result == 'success') if: always() && (needs.rollback-production.result == 'success' || needs.rollback-preprod.result == 'success')
steps: steps:
- name: Set health check URLs - name: Set URLs
id: urls id: urls
run: | run: |
if [ "${{ github.event.inputs.environment }}" = "production" ]; then if [ "${{ github.event.inputs.environment }}" = "production" ]; then
@ -240,44 +199,40 @@ jobs:
echo "wait=60" >> $GITHUB_OUTPUT echo "wait=60" >> $GITHUB_OUTPUT
fi fi
- name: Wait for services - run: sleep ${{ steps.urls.outputs.wait }}
run: sleep ${{ steps.urls.outputs.wait }}
- name: Health check — Backend - name: Health — Backend
run: | run: |
for i in {1..12}; do for i in {1..12}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
"${{ steps.urls.outputs.backend }}" 2>/dev/null || echo "000") "${{ steps.urls.outputs.backend }}" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then echo "Backend healthy."; exit 0; fi if [ "$STATUS" = "200" ]; then echo "Backend OK."; exit 0; fi
sleep 15 sleep 15
done done
echo "CRITICAL: Backend unhealthy after rollback." echo "Backend unhealthy after rollback."
exit 1 exit 1
- name: Health check — Frontend - name: Health — Frontend
run: | run: |
for i in {1..12}; do for i in {1..12}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
"${{ steps.urls.outputs.frontend }}" 2>/dev/null || echo "000") "${{ steps.urls.outputs.frontend }}" 2>/dev/null || echo "000")
echo " Attempt $i: HTTP $STATUS" echo " Attempt $i: HTTP $STATUS"
if [ "$STATUS" = "200" ]; then echo "Frontend healthy."; exit 0; fi if [ "$STATUS" = "200" ]; then echo "Frontend OK."; exit 0; fi
sleep 15 sleep 15
done done
echo "CRITICAL: Frontend unhealthy after rollback." echo "Frontend unhealthy after rollback."
exit 1 exit 1
# ────────────────────────────────────────── # ── Notifications ─────────────────────────────────────────────────────
# Discord notification
# ──────────────────────────────────────────
notify: notify:
name: Notify Rollback Result name: Notify
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [rollback-production, rollback-preprod, smoke-tests] needs: [rollback-production, rollback-preprod, smoke-tests]
if: always() if: always()
steps: steps:
- name: Notify success - name: Success
if: needs.smoke-tests.result == 'success' if: needs.smoke-tests.result == 'success'
run: | run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
@ -288,29 +243,26 @@ jobs:
{"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true}, {"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true},
{"name": "Strategy", "value": "`${{ github.event.inputs.strategy }}`", "inline": true}, {"name": "Strategy", "value": "`${{ github.event.inputs.strategy }}`", "inline": true},
{"name": "Version", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true}, {"name": "Version", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true},
{"name": "Triggered by", "value": "${{ github.actor }}", "inline": true}, {"name": "By", "value": "${{ github.actor }}", "inline": true},
{"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}, {"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Rollback"} "footer": {"text": "Xpeditis CI/CD • Rollback"}
}] }]
}' ${{ secrets.DISCORD_WEBHOOK_URL }} }' ${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Notify failure - name: Failure
if: needs.smoke-tests.result != 'success' if: needs.smoke-tests.result != 'success'
run: | run: |
curl -s -H "Content-Type: application/json" -d '{ curl -s -H "Content-Type: application/json" -d '{
"content": "@here ROLLBACK FAILED — MANUAL INTERVENTION REQUIRED", "content": "@here ROLLBACK FAILED — MANUAL INTERVENTION REQUIRED",
"embeds": [{ "embeds": [{
"title": "🔴 Rollback Failed", "title": "🔴 Rollback Failed",
"description": "Service may be degraded. Escalate immediately.",
"color": 15158332, "color": 15158332,
"fields": [ "fields": [
{"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true}, {"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true},
{"name": "Attempted version", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true}, {"name": "Attempted", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true},
{"name": "Triggered by", "value": "${{ github.actor }}", "inline": true}, {"name": "By", "value": "${{ github.actor }}", "inline": true},
{"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}, {"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}
{"name": "Workflow", "value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
], ],
"footer": {"text": "Xpeditis CI/CD • Rollback"} "footer": {"text": "Xpeditis CI/CD • Rollback"}
}] }]