Skip to content

Commit a25ea9b

Browse files
committed
feat: enhance deployment process with health check and update docker compose and nginx
1 parent 5752312 commit a25ea9b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

.github/workflows/ci_cd.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ jobs:
148148
needs: build_and_push_docker_image
149149
if: github.ref == 'refs/heads/main'
150150
steps:
151+
- name: Checkout code
152+
uses: actions/checkout@v4
153+
154+
- name: Copy docker-compose.yml to server
155+
uses: appleboy/[email protected]
156+
with:
157+
host: ${{ secrets.SERVER_HOST }}
158+
username: ${{ secrets.SERVER_USER }}
159+
key: ${{ secrets.SERVER_SSH_KEY }}
160+
source: "docker-compose.yml,nginx.conf"
161+
target: "/root"
162+
151163
- name: Deploy to server
152164
uses: appleboy/[email protected]
153165
with:
@@ -156,6 +168,26 @@ jobs:
156168
key: ${{ secrets.SERVER_SSH_KEY }}
157169
script: |
158170
cd /root
159-
docker compose pull rails
160-
docker compose up -d rails
171+
docker compose pull
172+
docker compose up -d
173+
# Clean up old images from ghcr.io registry (keep only the latest)
174+
docker images 'ghcr.io/oddsteam/dailynews-e-newspaper' --format '{{.ID}} {{.Tag}}' | grep -v 'latest' | awk '{print $1}' | xargs -r docker rmi -f || true
175+
176+
- name: Health check
177+
run: |
178+
echo "Waiting for services to start..."
179+
sleep 15
180+
181+
echo "Checking application health..."
182+
for i in {1..5}; do
183+
if curl -f -s http://${{ secrets.SERVER_HOST }}/up > /dev/null; then
184+
echo "✓ Health check passed!"
185+
exit 0
186+
fi
187+
echo "Attempt $i failed, retrying in 10 seconds..."
188+
sleep 10
189+
done
190+
191+
echo "✗ Health check failed after 5 attempts"
192+
exit 1
161193

0 commit comments

Comments
 (0)