-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (77 loc) · 2.96 KB
/
Copy pathdeploy.yml
File metadata and controls
93 lines (77 loc) · 2.96 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Deploy to VPS
on:
push:
branches: [main]
concurrency:
group: deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout source
uses: actions/checkout@v5
- name: Upload clean release
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: 443
timeout: 60s
command_timeout: 5m
source: "Dockerfile,docker-compose.yml,.dockerignore,package.json,package-lock.json,next.config.ts,tsconfig.json,postcss.config.mjs,eslint.config.mjs,public,src"
target: /tmp/7uanf-release
rm: true
overwrite: true
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: 443
timeout: 60s
command_timeout: 15m
script: |
set -Eeuo pipefail
RELEASE_ROOT=/tmp/7uanf-release
COMPOSE_PROJECT=7uanf
IMAGE_NAME=7uanf-web:latest
ROLLBACK_IMAGE=7uanf-web:rollback
cd "$RELEASE_ROOT"
docker compose -p "$COMPOSE_PROJECT" config --quiet
# Preserve the currently running image for an automatic rollback.
if docker image inspect "$IMAGE_NAME" >/dev/null 2>&1; then
docker image tag "$IMAGE_NAME" "$ROLLBACK_IMAGE"
fi
docker compose -p "$COMPOSE_PROJECT" build
docker compose -p "$COMPOSE_PROJECT" up -d --force-recreate --remove-orphans
echo "Waiting for health check..."
healthy=false
for i in $(seq 1 45); do
if curl --fail --silent --show-error http://127.0.0.1:3002/api/health >/dev/null; then
healthy=true
break
fi
sleep 2
done
if [ "$healthy" != true ]; then
echo "Health check failed. Rolling back..."
docker compose -p "$COMPOSE_PROJECT" logs --tail=80
if docker image inspect "$ROLLBACK_IMAGE" >/dev/null 2>&1; then
docker image tag "$ROLLBACK_IMAGE" "$IMAGE_NAME"
docker compose -p "$COMPOSE_PROJECT" up -d --force-recreate --no-build
curl --retry 15 --retry-delay 2 --retry-connrefused --fail \
http://127.0.0.1:3002/api/health >/dev/null
echo "Rollback completed successfully."
fi
exit 1
fi
echo "App is healthy."
docker image rm "$ROLLBACK_IMAGE" >/dev/null 2>&1 || true
# Keep disk usage bounded without touching active images or volumes.
docker image prune -f
docker builder prune -f --filter "until=168h"
df -h /