feat: clean ci
Laravel CI-CD / Tests Unitaires (push) Successful in 21s Details
Laravel CI-CD / Build & Push Docker (push) Successful in 45s Details
Laravel CI-CD / Deploy (push) Successful in 7s Details

This commit is contained in:
Leon Morival 2026-05-19 16:55:50 +02:00
parent 1259ebc3a9
commit f8e1e89a83
1 changed files with 13 additions and 56 deletions

View File

@ -60,26 +60,14 @@ jobs:
docker push "$IMAGE:latest" docker push "$IMAGE:latest"
# ========================= # =========================
# DEPLOY BLUE / GREEN (CADDY GÈRE LE ROUTING) # DEPLOY (SIMPLE)
# ========================= # =========================
deploy: deploy:
name: Deploy Blue/Green (Caddy routing) name: Deploy
needs: build needs: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout deploy files
uses: actions/checkout@v4
- name: Upload docker-compose
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: docker-compose.prod.yml
target: /opt/bemeal
- name: Deploy via SSH - name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
env: env:
@ -95,54 +83,23 @@ jobs:
set -eu set -eu
APP_DIR="/opt/bemeal" APP_DIR="/opt/bemeal"
cd "$APP_DIR" cd "$APP_DIR"
COMPOSE="docker compose \ COMPOSE="docker compose \
--project-directory $APP_DIR \ --project-directory $APP_DIR \
--env-file $APP_DIR/.env.prod \ --env-file $APP_DIR/.env.prod \
-f $APP_DIR/docker-compose.prod.yml" -f $APP_DIR/docker-compose.prod.yml"
IMAGE="$REGISTRY/$IMAGE_NAME:$IMAGE_TAG"
IMAGE="$REGISTRY/$IMAGE_NAME:$IMAGE_TAG"
echo "Pull image"
docker pull "$IMAGE" docker pull "$IMAGE"
echo "Deploy shared infra" echo "Start infra services"
$COMPOSE up -d pgsql redis meilisearch $COMPOSE up -d pgsql redis meilisearch
# detect active echo "Deploy API (blue/green handled by Caddy)"
ACTIVE="" IMAGE="$IMAGE" $COMPOSE up -d --no-deps --force-recreate bemeal-api-blue
if docker ps | grep -q bemeal-api-blue && \ IMAGE="$IMAGE" $COMPOSE up -d --no-deps --force-recreate bemeal-api-green
[ "$(docker inspect -f '{{.State.Health.Status}}' bemeal-api-blue 2>/dev/null || true)" = "healthy" ]; then
ACTIVE=blue
fi
if docker ps | grep -q bemeal-api-green && \ echo "Deployment done"
[ "$(docker inspect -f '{{.State.Health.Status}}' bemeal-api-green 2>/dev/null || true)" = "healthy" ]; then
ACTIVE=green
fi
if [ "$ACTIVE" = "blue" ]; then
TARGET=green
else
TARGET=blue
fi
TARGET_SERVICE="bemeal-api-$TARGET"
echo "Deploy $TARGET_SERVICE"
IMAGE="$IMAGE" $COMPOSE up -d --no-deps --force-recreate "$TARGET_SERVICE"
# wait health
for i in $(seq 1 60); do
STATUS=$(docker inspect -f '{{.State.Health.Status}}' "$TARGET_SERVICE" || true)
[ "$STATUS" = "healthy" ] && break
sleep 2
done
[ "$STATUS" != "healthy" ] && exit 1
# 👉 SWITCH ULTRA SIMPLE
echo "bemeal-api-$TARGET" > /opt/caddy/active
docker exec caddy caddy reload