-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (63 loc) · 2.78 KB
/
deploy.yml
File metadata and controls
79 lines (63 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Build and Deploy
on:
push:
branches: [ main ]
permissions:
contents: read
packages: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/lrfoster03/featureflags:latest
- name: Deploy on Droplet
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.DROPLET_HOST }}
username: root
key: ${{ secrets.DROPLET_SSH_KEY }}
script: |
set -euo pipefail
cd /root/FeatureFlags
PREVIOUS_IMAGE_ID=""
if docker compose ps -q featureflags >/dev/null 2>&1; then
CURRENT_CONTAINER_ID=$(docker compose ps -q featureflags || true)
if [ -n "$CURRENT_CONTAINER_ID" ]; then
PREVIOUS_IMAGE_ID=$(docker inspect --format='{{.Image}}' "$CURRENT_CONTAINER_ID" || true)
fi
fi
echo "Pulling latest repository and image..."
git pull
docker compose pull featureflags
echo "Starting updated app container..."
docker compose up -d --no-deps featureflags
echo "Waiting for app health check..."
for i in $(seq 1 30); do
if docker run --rm --network featureflags_default curlimages/curl:8.10.1 -fsS http://featureflags:8080/healthz >/dev/null; then
echo "Health check passed."
docker image prune -f
exit 0
fi
echo "Health check attempt $i failed; retrying..."
sleep 2
done
echo "Deployment failed health check. Rolling back..."
if [ -n "$PREVIOUS_IMAGE_ID" ]; then
docker tag "$PREVIOUS_IMAGE_ID" ghcr.io/lrfoster03/featureflags:latest
docker compose up -d --no-deps featureflags
fi
echo "Rollback attempted. Current featureflags logs:"
docker compose logs --tail=100 featureflags
exit 1