This commit is contained in:
@@ -33,9 +33,11 @@ jobs:
|
||||
docker build -t robot-market:${{ steps.vars.outputs.sha }} .
|
||||
|
||||
- name: Save previous tag for rollback
|
||||
id: backup
|
||||
run: |
|
||||
if [ -f /opt/robot-market-front/.env ]; then
|
||||
cp /opt/robot-market-front/.env /opt/robot-market-front/.env.previous
|
||||
echo "available=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Point compose at this build
|
||||
@@ -43,12 +45,14 @@ jobs:
|
||||
echo "IMAGE_TAG=${{ steps.vars.outputs.sha }}" > /opt/robot-market-front/.env
|
||||
|
||||
- name: Deploy via compose
|
||||
id: deploy
|
||||
run: |
|
||||
docker compose --env-file /opt/robot-market-front/.env \
|
||||
-f /opt/robot-market-front/docker-compose.yml \
|
||||
up -d --force-recreate
|
||||
|
||||
- name: Health check (retries for ~30s)
|
||||
id: health
|
||||
run: |
|
||||
for i in $(seq 1 15); do
|
||||
if docker exec robot-market node -e "
|
||||
@@ -65,8 +69,8 @@ jobs:
|
||||
echo "Health check failed after 30s"
|
||||
exit 1
|
||||
|
||||
- name: Roll back to previous version on failed health check
|
||||
if: failure()
|
||||
- name: Roll back after deployment or health check failure
|
||||
if: ${{ failure() && steps.backup.outputs.available == 'true' && (steps.deploy.outcome == 'failure' || steps.health.outcome == 'failure') }}
|
||||
run: |
|
||||
if [ -f /opt/robot-market-front/.env.previous ]; then
|
||||
cp /opt/robot-market-front/.env.previous /opt/robot-market-front/.env
|
||||
@@ -96,4 +100,4 @@ jobs:
|
||||
echo "Removing old image robot-market:$tag"
|
||||
docker rmi "robot-market:$tag" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user