ci: fix deploy workflow - use GITHUB_WORKSPACE env var and robust healthcheck
Some checks failed
Deploy to Production / Build and Deploy (push) Has been cancelled
Some checks failed
Deploy to Production / Build and Deploy (push) Has been cancelled
Made-with: Cursor
This commit is contained in:
@@ -8,44 +8,52 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Build and Deploy
|
name: Build and Deploy
|
||||||
# "docker-host" label = runs directly on the host (192.168.1.190)
|
|
||||||
runs-on: docker-host
|
runs-on: docker-host
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Sync code to deploy directory
|
- name: Verify env file exists on host
|
||||||
run: |
|
run: |
|
||||||
rsync -a --delete \
|
if [ ! -f /opt/memento/.env.docker ]; then
|
||||||
--exclude '.git' \
|
echo "ERROR: /opt/memento/.env.docker introuvable sur le serveur."
|
||||||
--exclude 'node_modules' \
|
echo "Créer ce fichier une seule fois manuellement sur 192.168.1.190."
|
||||||
--exclude '.next' \
|
exit 1
|
||||||
--exclude 'memento-note/node_modules' \
|
fi
|
||||||
--exclude 'mcp-server/node_modules' \
|
echo "env file OK"
|
||||||
${{ github.workspace }}/ /opt/memento/
|
|
||||||
|
- name: Sync source to /opt/memento
|
||||||
|
run: |
|
||||||
|
mkdir -p /opt/memento
|
||||||
|
# cp -a préserve les fichiers existants (.env.docker) non trackés par git
|
||||||
|
cp -a "$GITHUB_WORKSPACE"/. /opt/memento/
|
||||||
|
echo "Sync done"
|
||||||
|
|
||||||
- name: Build and deploy
|
- name: Build and deploy
|
||||||
working-directory: /opt/memento
|
working-directory: /opt/memento
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
docker compose build --parallel
|
echo "=== Building memento-note ==="
|
||||||
|
docker compose build memento-note
|
||||||
|
echo "=== Starting containers ==="
|
||||||
docker compose up -d --remove-orphans
|
docker compose up -d --remove-orphans
|
||||||
|
echo "=== Running containers ==="
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
- name: Wait for healthchecks
|
- name: Wait for app to be ready
|
||||||
working-directory: /opt/memento
|
|
||||||
run: |
|
run: |
|
||||||
echo "Waiting for containers..."
|
echo "Waiting up to 120s for memento-web to respond..."
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 24); do
|
||||||
UNHEALTHY=$(docker compose ps --format '{{.Status}}' | grep -cv "healthy" || true)
|
STATUS=$(docker inspect --format='{{.State.Health.Status}}' memento-web 2>/dev/null || echo "unknown")
|
||||||
if [ "$UNHEALTHY" -eq 0 ]; then
|
if [ "$STATUS" = "healthy" ]; then
|
||||||
echo "All containers healthy!"
|
echo "memento-web is healthy after $((i * 5))s"
|
||||||
docker compose ps
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 2
|
echo " [$((i * 5))s] status=$STATUS"
|
||||||
|
sleep 5
|
||||||
done
|
done
|
||||||
echo "Timeout waiting for healthchecks"
|
echo "Timeout. Last logs:"
|
||||||
docker compose ps
|
docker logs memento-web --tail=30
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
- name: Cleanup old images
|
- name: Cleanup old images
|
||||||
|
|||||||
Reference in New Issue
Block a user