From 13279131999b20446788c159b13282db8fc7144a Mon Sep 17 00:00:00 2001 From: moham Date: Sat, 20 Sep 2025 15:12:43 +0200 Subject: [PATCH] Ajouter .gitea/workflows/build-canary.yml --- .gitea/workflows/build-canary.yml | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .gitea/workflows/build-canary.yml diff --git a/.gitea/workflows/build-canary.yml b/.gitea/workflows/build-canary.yml new file mode 100644 index 0000000..9ad52c9 --- /dev/null +++ b/.gitea/workflows/build-canary.yml @@ -0,0 +1,87 @@ +name: build-canary + +on: + push: + branches: [ main ] + paths: + - "app.py" + - "config.py" + - "templates/**" + - "static/**" + - "Dockerfile" + - ".gitea/workflows/build-canary.yml" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Force LAN host mapping (ephagit & srv) + run: | + echo "10.90.0.10 ephagit.ephaitek.com" | sudo tee -a /etc/hosts + echo "10.10.0.10 srv.ephaitek.com" | sudo tee -a /etc/hosts + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + persist-credentials: false + + - name: Set tags + id: vars + shell: bash + run: | + SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7) + echo "short=${SHORT_SHA}" >> "$GITHUB_OUTPUT" + echo "canary=canary-${SHORT_SHA}" >> "$GITHUB_OUTPUT" + + - name: Login registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build & Push (canary + latest-canary) + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ secrets.REGISTRY }}/${{ secrets.IMAGE_REPO }}:${{ steps.vars.outputs.canary }} + ${{ secrets.REGISTRY }}/${{ secrets.IMAGE_REPO }}:latest-canary + cache-from: type=registry,ref=${{ secrets.REGISTRY }}/${{ secrets.IMAGE_REPO }}:buildcache + cache-to: type=registry,ref=${{ secrets.REGISTRY }}/${{ secrets.IMAGE_REPO }}:buildcache,mode=max + + deploy_canary: + needs: build + runs-on: ubuntu-latest + steps: + - name: Deploy CANARY on srv (image latest-canary) + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + port: ${{ secrets.SSH_PORT }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} + envs: REGISTRY,IMAGE_REPO + script: | + set -euo pipefail + IMAGE="${REGISTRY}/${IMAGE_REPO}:latest-canary" + + # .env CANARY distinct (ex: /srv/ihm/.env.canary) + ENV_CANARY="/srv/ihm/.env.canary" + if [ ! -f "${ENV_CANARY}" ]; then + cp /srv/ihm/.env "${ENV_CANARY}" + fi + if grep -q '^IMAGE=' "${ENV_CANARY}"; then + sed -i -E "s|^IMAGE=.*|IMAGE=${IMAGE}|" "${ENV_CANARY}" + else + echo "IMAGE=${IMAGE}" >> "${ENV_CANARY}" + fi + + # lancer/relancer canary (utilise /srv/ihm/scripts/docker-run-canary.sh lisant .env.canary) + /srv/ihm/scripts/docker-run-canary.sh + + # healthcheck canary (ex: port 18081) + curl -sf http://127.0.0.1:18081/ >/dev/null + echo "✅ CANARY ok avec ${IMAGE}" \ No newline at end of file