7
0
forked from yvv/decision

ci: remplace Traefik par Fabio/Consul (pattern sonic)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

- docker-compose.yml : labels SERVICE_* Registrator, réseau sonic external,
  container_name explicite, name COMPOSE_PROJECT_NAME
- pipeline : APP_DOMAIN (au lieu de DOMAIN), ACME sonic-acme-1 pour TLS,
  test-deploy sans suffixe -1 (container_name fixe)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
syoul
2026-03-23 15:25:06 +01:00
parent 6509137892
commit 73c5bf148c
2 changed files with 53 additions and 40 deletions

View File

@@ -116,7 +116,7 @@ steps:
SECRET_KEY: SECRET_KEY:
from_secret: secret_key from_secret: secret_key
commands: commands:
- echo "DOMAIN=$APP_DOMAIN" > .env.deploy - echo "APP_DOMAIN=$APP_DOMAIN" > .env.deploy
- echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> .env.deploy - echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> .env.deploy
- echo "SECRET_KEY=$SECRET_KEY" >> .env.deploy - echo "SECRET_KEY=$SECRET_KEY" >> .env.deploy
- OWNER=$(echo "$CI_REPO_OWNER" | tr 'A-Z' 'a-z') && REPO=$(echo "$CI_REPO_NAME" | tr 'A-Z' 'a-z') && BRANCH=$(echo "$CI_COMMIT_BRANCH" | tr 'A-Z/' 'a-z-') && echo "COMPOSE_PROJECT_NAME=$OWNER-$REPO-$BRANCH" >> .env.deploy - OWNER=$(echo "$CI_REPO_OWNER" | tr 'A-Z' 'a-z') && REPO=$(echo "$CI_REPO_NAME" | tr 'A-Z' 'a-z') && BRANCH=$(echo "$CI_COMMIT_BRANCH" | tr 'A-Z/' 'a-z-') && echo "COMPOSE_PROJECT_NAME=$OWNER-$REPO-$BRANCH" >> .env.deploy
@@ -135,9 +135,9 @@ steps:
[ -z "$VAL" ] && echo "FAIL: COMPOSE_PROJECT_NAME vide" && exit 1 [ -z "$VAL" ] && echo "FAIL: COMPOSE_PROJECT_NAME vide" && exit 1
echo "PASS: COMPOSE_PROJECT_NAME = $VAL" echo "PASS: COMPOSE_PROJECT_NAME = $VAL"
- | - |
VAL=$(grep '^DOMAIN=' .env.deploy | cut -d= -f2) VAL=$(grep '^APP_DOMAIN=' .env.deploy | cut -d= -f2)
[ -z "$VAL" ] && echo "FAIL: DOMAIN vide" && exit 1 [ -z "$VAL" ] && echo "FAIL: APP_DOMAIN vide" && exit 1
echo "PASS: DOMAIN = $VAL" echo "PASS: APP_DOMAIN = $VAL"
# NOTE: volumes + pas de from_secret : compatible # NOTE: volumes + pas de from_secret : compatible
# Fabio/Traefik routing géré via labels du docker-compose.yml # Fabio/Traefik routing géré via labels du docker-compose.yml
@@ -152,6 +152,24 @@ steps:
- cp .env.deploy /opt/libredecision/.env - cp .env.deploy /opt/libredecision/.env
- chmod 600 /opt/libredecision/.env - chmod 600 /opt/libredecision/.env
- cp docker/docker-compose.yml /opt/libredecision/docker-compose.yml - cp docker/docker-compose.yml /opt/libredecision/docker-compose.yml
# Arreter avant le challenge ACME : libere le webroot pour sonic-acme-1
- cd /opt/libredecision && docker compose stop
- |
DOMAIN=$(grep '^APP_DOMAIN=' /opt/libredecision/.env | cut -d= -f2)
ACME_EXIT=0
docker exec sonic-acme-1 /app/acme.sh \
--home /etc/acme.sh \
--issue -d "$DOMAIN" \
--webroot /usr/share/nginx/html \
--server letsencrypt \
--accountemail support+acme@asycn.io || ACME_EXIT=$?
if [ "$ACME_EXIT" -ne 0 ] && [ "$ACME_EXIT" -ne 2 ]; then
echo "ERREUR: acme.sh a echoue (exit $ACME_EXIT)"
exit 1
fi
docker exec sonic-acme-1 cp /etc/acme.sh/$DOMAIN/fullchain.cer /host/certs/$DOMAIN-cert.pem
docker exec sonic-acme-1 cp /etc/acme.sh/$DOMAIN/$DOMAIN.key /host/certs/$DOMAIN-key.pem
echo "TLS OK (acme exit $ACME_EXIT)"
# Images construites localement dans la pipeline : pas de docker compose pull # Images construites localement dans la pipeline : pas de docker compose pull
- cd /opt/libredecision && docker compose up -d --remove-orphans - cd /opt/libredecision && docker compose up -d --remove-orphans
- cd /opt/libredecision && docker compose ps - cd /opt/libredecision && docker compose ps
@@ -168,9 +186,9 @@ steps:
- | - |
PROJECT=$(grep '^COMPOSE_PROJECT_NAME=' /opt/libredecision/.env | cut -d= -f2) PROJECT=$(grep '^COMPOSE_PROJECT_NAME=' /opt/libredecision/.env | cut -d= -f2)
for SVC in backend frontend; do for SVC in backend frontend; do
STATUS=$(docker inspect --format '{{.State.Status}}' "$PROJECT-$SVC-1" 2>/dev/null || echo "absent") STATUS=$(docker inspect --format '{{.State.Status}}' "$PROJECT-$SVC" 2>/dev/null || echo "absent")
echo "$PROJECT-$SVC-1 : $STATUS" echo "$PROJECT-$SVC : $STATUS"
[ "$STATUS" = "running" ] || { echo "FAIL: $PROJECT-$SVC-1 non running"; exit 1; } [ "$STATUS" = "running" ] || { echo "FAIL: $PROJECT-$SVC non running"; exit 1; }
done done
echo "PASS: tous les containers running" echo "PASS: tous les containers running"
@@ -181,7 +199,7 @@ steps:
commands: commands:
- apk add --no-cache --quiet curl - apk add --no-cache --quiet curl
- | - |
SITE=$(grep '^DOMAIN=' .env.deploy | cut -d= -f2) SITE=$(grep '^APP_DOMAIN=' .env.deploy | cut -d= -f2)
TARGET="https://$SITE" TARGET="https://$SITE"
echo "Healthcheck $TARGET..." echo "Healthcheck $TARGET..."
MAX=60 MAX=60

View File

@@ -1,13 +1,14 @@
version: "3.9" name: ${COMPOSE_PROJECT_NAME:-ehv-decision-main}
services: services:
postgres: postgres:
image: postgres:16-alpine image: postgres:16-alpine
restart: unless-stopped container_name: ${COMPOSE_PROJECT_NAME:-ehv-decision-main}-postgres
restart: always
environment: environment:
POSTGRES_DB: ${POSTGRES_DB:-libredecision} POSTGRES_DB: ${POSTGRES_DB:-libredecision}
POSTGRES_USER: ${POSTGRES_USER:-libredecision} POSTGRES_USER: ${POSTGRES_USER:-libredecision}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change-me-in-production} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes: volumes:
- postgres-data:/var/lib/postgresql/data - postgres-data:/var/lib/postgresql/data
healthcheck: healthcheck:
@@ -18,63 +19,57 @@ services:
start_period: 30s start_period: 30s
networks: networks:
- libredecision - libredecision
# Pas de label SERVICE_* : postgres non exposé publiquement
backend: backend:
image: libredecision-backend:latest image: libredecision-backend:latest
build: container_name: ${COMPOSE_PROJECT_NAME:-ehv-decision-main}-backend
context: ../ restart: always
dockerfile: docker/backend.Dockerfile
target: production
restart: unless-stopped
depends_on: depends_on:
postgres: postgres:
condition: service_healthy condition: service_healthy
environment: environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-libredecision}:${POSTGRES_PASSWORD:-change-me-in-production}@postgres:5432/${POSTGRES_DB:-libredecision} DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-libredecision}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-libredecision}
SECRET_KEY: ${SECRET_KEY:-change-me-in-production-with-a-real-secret-key} SECRET_KEY: ${SECRET_KEY}
DEBUG: "false" DEBUG: "false"
CORS_ORIGINS: '["https://${DOMAIN:-libredecision.org}"]' CORS_ORIGINS: '["https://${APP_DOMAIN:-libredecision.org}"]'
DUNITER_RPC_URL: ${DUNITER_RPC_URL:-wss://gdev.p2p.legal/ws} DUNITER_RPC_URL: ${DUNITER_RPC_URL:-wss://gdev.p2p.legal/ws}
IPFS_API_URL: http://ipfs:5001 IPFS_API_URL: http://ipfs:5001
IPFS_GATEWAY_URL: http://ipfs:8080 IPFS_GATEWAY_URL: http://ipfs:8080
labels: labels:
- "traefik.enable=true" # Registrator enregistre dans Consul, Fabio route automatiquement
- "traefik.http.routers.libredecision-api.rule=Host(`${DOMAIN:-libredecision.org}`) && PathPrefix(`/api`)" - SERVICE_8002_NAME=${COMPOSE_PROJECT_NAME:-ehv-decision-main}-backend-8002
- "traefik.http.routers.libredecision-api.entrypoints=websecure" - SERVICE_8002_TAGS=urlprefix-${APP_DOMAIN:-libredecision.org}/api/*
- "traefik.http.routers.libredecision-api.tls.certresolver=letsencrypt" # TCP : HTTP check échoue si le service redirige (301/302)
- "traefik.http.services.libredecision-api.loadbalancer.server.port=8002" - SERVICE_8002_CHECK_TCP=true
networks: networks:
- libredecision - libredecision
- traefik - sonic
frontend: frontend:
image: libredecision-frontend:latest image: libredecision-frontend:latest
build: container_name: ${COMPOSE_PROJECT_NAME:-ehv-decision-main}-frontend
context: ../ restart: always
dockerfile: docker/frontend.Dockerfile
target: production
restart: unless-stopped
depends_on: depends_on:
- backend - backend
environment: environment:
NUXT_PUBLIC_API_BASE: https://${DOMAIN:-libredecision.org}/api/v1 NUXT_PUBLIC_API_BASE: https://${APP_DOMAIN:-libredecision.org}/api/v1
labels: labels:
- "traefik.enable=true" - SERVICE_3000_NAME=${COMPOSE_PROJECT_NAME:-ehv-decision-main}-frontend-3000
- "traefik.http.routers.libredecision-front.rule=Host(`${DOMAIN:-libredecision.org}`)" - SERVICE_3000_TAGS=urlprefix-${APP_DOMAIN:-libredecision.org}/*
- "traefik.http.routers.libredecision-front.entrypoints=websecure" - SERVICE_3000_CHECK_TCP=true
- "traefik.http.routers.libredecision-front.tls.certresolver=letsencrypt"
- "traefik.http.services.libredecision-front.loadbalancer.server.port=3000"
networks: networks:
- libredecision - sonic
- traefik
ipfs: ipfs:
image: ipfs/kubo:latest image: ipfs/kubo:latest
restart: unless-stopped container_name: ${COMPOSE_PROJECT_NAME:-ehv-decision-main}-ipfs
restart: always
volumes: volumes:
- ipfs-data:/data/ipfs - ipfs-data:/data/ipfs
networks: networks:
- libredecision - libredecision
# Pas de label SERVICE_* : ipfs non exposé publiquement
volumes: volumes:
postgres-data: postgres-data:
@@ -83,5 +78,5 @@ volumes:
networks: networks:
libredecision: libredecision:
driver: bridge driver: bridge
traefik: sonic:
external: true external: true