Files
client160_IHMKOS/.gitea/workflows/build-canary.yml
T

87 lines
2.8 KiB
YAML

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}"