ci: aligner pipeline sur le modèle de référence (fabio/consul/registrator)
- Suppression de deploy-rsync (hors stack) - Renommage deploy-docker → deploy - Ajout healthcheck (curl localhost:3006, max 100s) - Remplacement notify Telegram/vars Drone → notify-failure avec vars CI ($CI_BUILD_NUMBER, $CI_COMMIT_SHA, $CI_COMMIT_BRANCH) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ when:
|
|||||||
steps:
|
steps:
|
||||||
|
|
||||||
# Etape 1 : Build de l'application statique
|
# Etape 1 : Build de l'application statique
|
||||||
|
# Les vars CI (CI_REPO_OWNER, CI_COMMIT_BRANCH) sont injectees automatiquement par Woodpecker
|
||||||
- name: build
|
- name: build
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
environment:
|
environment:
|
||||||
@@ -21,59 +22,44 @@ steps:
|
|||||||
- npm run build
|
- npm run build
|
||||||
- ls -la build/ | head -10
|
- ls -la build/ | head -10
|
||||||
|
|
||||||
# Etape 2a : Deploiement via rsync (optionnel — choisir rsync OU docker, pas les deux)
|
# Etape 2 : Deploiement sur sonic via Docker socket
|
||||||
- name: deploy-rsync
|
# NOTE: from_secret et volumes: incompatibles dans le meme step (bug Woodpecker next)
|
||||||
image: alpine:latest
|
# Aucun secret ici — les variables de build sont dans docker-compose.business.yml
|
||||||
environment:
|
- name: deploy
|
||||||
DEPLOY_HOST:
|
|
||||||
from_secret: deploy_host
|
|
||||||
DEPLOY_USER:
|
|
||||||
from_secret: deploy_user
|
|
||||||
DEPLOY_PATH:
|
|
||||||
from_secret: deploy_path
|
|
||||||
DEPLOY_KEY:
|
|
||||||
from_secret: deploy_key
|
|
||||||
commands:
|
|
||||||
- apk add --no-cache openssh-client rsync
|
|
||||||
- mkdir -p ~/.ssh
|
|
||||||
- echo "$DEPLOY_KEY" > ~/.ssh/id_rsa
|
|
||||||
- chmod 600 ~/.ssh/id_rsa
|
|
||||||
- ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts || true
|
|
||||||
- rsync -avz --delete build/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/
|
|
||||||
- echo "Deploiement termine sur $DEPLOY_HOST:$DEPLOY_PATH"
|
|
||||||
|
|
||||||
# Etape 2b : Deploiement via Docker Compose (recommande)
|
|
||||||
- name: deploy-docker
|
|
||||||
image: docker:27-cli
|
image: docker:27-cli
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
commands:
|
commands:
|
||||||
- docker compose -f docker-compose.business.yml build --no-cache
|
- docker compose -f docker-compose.business.yml build --no-cache
|
||||||
- docker compose -f docker-compose.business.yml up -d --remove-orphans
|
- docker compose -f docker-compose.business.yml up -d --remove-orphans
|
||||||
- docker compose -f docker-compose.business.yml ps | grep laplank-radar || echo "Conteneur non trouve"
|
- docker compose -f docker-compose.business.yml ps
|
||||||
|
|
||||||
# Etape 3 : Notification Telegram
|
# Etape 3 : Healthcheck post-deploiement
|
||||||
- name: notify
|
- name: healthcheck
|
||||||
image: appleboy/drone-telegram
|
image: alpine:3.20
|
||||||
settings:
|
commands:
|
||||||
token:
|
- apk add --no-cache --quiet curl
|
||||||
from_secret: telegram_token
|
- |
|
||||||
to:
|
MAX=20
|
||||||
from_secret: telegram_chat_id_ajr
|
i=0
|
||||||
format: markdown
|
until [ $i -ge $MAX ]; do
|
||||||
message: >
|
CODE=$(curl -sSo /dev/null -w "%{http_code}" http://localhost:3006/ 2>/dev/null)
|
||||||
{{#success build.status}}
|
echo "Tentative $((i+1))/$MAX - HTTP $CODE"
|
||||||
✅ Build réussi pour `{{repo.name}}` sur la branche `{{commit.branch}}`
|
if [ "$CODE" = "200" ]; then
|
||||||
📝 Commit: `{{commit.message}}`
|
echo "Radar repond sur http://localhost:3006/"
|
||||||
👤 Auteur: {{commit.author}}
|
exit 0
|
||||||
🔗 {{ build.link }}
|
fi
|
||||||
{{else}}
|
i=$((i+1))
|
||||||
❌ Build échoué pour `{{repo.name}}` sur la branche `{{commit.branch}}`
|
sleep 5
|
||||||
📝 Commit: `{{commit.message}}`
|
done
|
||||||
👤 Auteur: {{commit.author}}
|
echo "ERREUR: Radar ne repond pas apres $(($MAX * 5)) secondes"
|
||||||
🔗 {{ build.link }}
|
exit 1
|
||||||
{{/success}}
|
|
||||||
|
# Notification en cas d'echec
|
||||||
|
- name: notify-failure
|
||||||
|
image: alpine:3.20
|
||||||
|
commands:
|
||||||
|
- 'echo "ECHEC pipeline #$CI_BUILD_NUMBER sur commit $CI_COMMIT_SHA"'
|
||||||
|
- 'echo "Branche: $CI_COMMIT_BRANCH"'
|
||||||
when:
|
when:
|
||||||
- status:
|
- status: failure
|
||||||
- success
|
|
||||||
- failure
|
|
||||||
|
|||||||
Reference in New Issue
Block a user