-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·48 lines (41 loc) · 1.8 KB
/
deploy.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.8 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
#!/usr/bin/env bash
set -euo pipefail
# GitHub Store Backend — deploy to production VPS
# Usage: ./deploy.sh <server-ip>
SERVER_IP="${1:?Usage: ./deploy.sh <server-ip>}"
SSH_USER="root"
REMOTE_DIR="/opt/github-store-backend"
echo "==> Deploying to $SERVER_IP..."
# Sync project files to VPS (excludes dev/build artifacts)
rsync -avz --delete \
--exclude '.git/' \
--exclude '.gradle/' \
--exclude 'build/' \
--exclude '.idea/' \
--exclude '.env' \
--exclude 'docker-compose.override.yml' \
--exclude '.DS_Store' \
--exclude '.claude/' \
./ "$SSH_USER@$SERVER_IP:$REMOTE_DIR/"
echo "==> Building and starting services..."
ssh "$SSH_USER@$SERVER_IP" "cd $REMOTE_DIR && docker compose -f docker-compose.prod.yml up -d --build"
# Caddyfile is mounted as a volume, so changes on disk don't auto-reload the
# running Caddy process. Gracefully reload if the file changed since last deploy.
# (Reload, not restart — avoids a TLS reconnect blip for live traffic.)
echo "==> Reloading Caddy config..."
ssh "$SSH_USER@$SERVER_IP" "docker compose -f $REMOTE_DIR/docker-compose.prod.yml exec -T caddy caddy reload --config /etc/caddy/Caddyfile || docker compose -f $REMOTE_DIR/docker-compose.prod.yml restart caddy"
# Poll /v1/health until it returns 200, with a hard 60s ceiling.
# A failing curl must fail the deploy script — the previous `|| echo`
# version swallowed the non-zero exit and reported "Deploy complete" on
# unhealthy boots.
echo "==> Waiting for health check..."
for i in $(seq 1 30); do
if ssh "$SSH_USER@$SERVER_IP" "docker exec github-store-backend-app-1 curl -sf http://localhost:8080/v1/health" >/dev/null 2>&1; then
echo "==> Healthy after $((i*2))s"
echo "==> Deploy complete!"
exit 0
fi
sleep 2
done
echo "Health check failed after 60s" >&2
exit 1