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:
|
||||
deploy:
|
||||
name: Build and Deploy
|
||||
# "docker-host" label = runs directly on the host (192.168.1.190)
|
||||
runs-on: docker-host
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Sync code to deploy directory
|
||||
- name: Verify env file exists on host
|
||||
run: |
|
||||
rsync -a --delete \
|
||||
--exclude '.git' \
|
||||
--exclude 'node_modules' \
|
||||
--exclude '.next' \
|
||||
--exclude 'memento-note/node_modules' \
|
||||
--exclude 'mcp-server/node_modules' \
|
||||
${{ github.workspace }}/ /opt/memento/
|
||||
if [ ! -f /opt/memento/.env.docker ]; then
|
||||
echo "ERROR: /opt/memento/.env.docker introuvable sur le serveur."
|
||||
echo "Créer ce fichier une seule fois manuellement sur 192.168.1.190."
|
||||
exit 1
|
||||
fi
|
||||
echo "env file OK"
|
||||
|
||||
- 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
|
||||
working-directory: /opt/memento
|
||||
run: |
|
||||
set -e
|
||||
docker compose build --parallel
|
||||
echo "=== Building memento-note ==="
|
||||
docker compose build memento-note
|
||||
echo "=== Starting containers ==="
|
||||
docker compose up -d --remove-orphans
|
||||
|
||||
- name: Wait for healthchecks
|
||||
working-directory: /opt/memento
|
||||
run: |
|
||||
echo "Waiting for containers..."
|
||||
for i in $(seq 1 30); do
|
||||
UNHEALTHY=$(docker compose ps --format '{{.Status}}' | grep -cv "healthy" || true)
|
||||
if [ "$UNHEALTHY" -eq 0 ]; then
|
||||
echo "All containers healthy!"
|
||||
echo "=== Running containers ==="
|
||||
docker compose ps
|
||||
|
||||
- name: Wait for app to be ready
|
||||
run: |
|
||||
echo "Waiting up to 120s for memento-web to respond..."
|
||||
for i in $(seq 1 24); do
|
||||
STATUS=$(docker inspect --format='{{.State.Health.Status}}' memento-web 2>/dev/null || echo "unknown")
|
||||
if [ "$STATUS" = "healthy" ]; then
|
||||
echo "memento-web is healthy after $((i * 5))s"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
echo " [$((i * 5))s] status=$STATUS"
|
||||
sleep 5
|
||||
done
|
||||
echo "Timeout waiting for healthchecks"
|
||||
docker compose ps
|
||||
echo "Timeout. Last logs:"
|
||||
docker logs memento-web --tail=30
|
||||
exit 1
|
||||
|
||||
- name: Cleanup old images
|
||||
|
||||
Reference in New Issue
Block a user