-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·69 lines (57 loc) · 1.88 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·69 lines (57 loc) · 1.88 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
#!/usr/bin/env bash
# deploy.sh - 同步程式碼到本地 deploy 目錄並重啟服務
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEPLOY_DIR="$SCRIPT_DIR/deploy"
PUBLIC_PORT="${PUBLIC_PORT:-8900}"
echo "🚀 Deploying Cat App..."
mkdir -p "$DEPLOY_DIR"
# 同步程式碼(排除資料目錄與 git 相關)
rsync -av --delete \
--exclude='backend/data/' \
--exclude='data/' \
--exclude='deploy/' \
--exclude='.git/' \
--exclude='__pycache__/' \
--exclude='*.pyc' \
--exclude='.env' \
--exclude='flutter_app/' \
--exclude='*.md' \
--exclude='.claude/' \
--exclude='.gitignore' \
"$SCRIPT_DIR/" "$DEPLOY_DIR/"
echo "📦 Building & restarting services..."
cd "$DEPLOY_DIR"
PUBLIC_PORT="$PUBLIC_PORT" docker compose build --no-cache api sync
PUBLIC_PORT="$PUBLIC_PORT" docker compose up -d api nginx
echo "✅ Deploy done!"
echo ""
HEALTH_URL="http://localhost:${PUBLIC_PORT}/health"
HEALTH_TIMEOUT_SECONDS=30
HEALTH_BACKOFF_SECONDS=1
HEALTH_MAX_BACKOFF_SECONDS=5
HEALTH_DEADLINE=$((SECONDS + HEALTH_TIMEOUT_SECONDS))
while true; do
health_response="$(mktemp)"
if curl --fail --silent --show-error "$HEALTH_URL" > "$health_response"; then
if python3 -m json.tool < "$health_response"; then
rm -f "$health_response"
exit 0
fi
echo "Health probe returned invalid JSON, retrying..."
else
echo "Health probe failed, retrying..."
fi
rm -f "$health_response"
if (( SECONDS >= HEALTH_DEADLINE )); then
echo "ERROR: health probe did not succeed within ${HEALTH_TIMEOUT_SECONDS}s: $HEALTH_URL" >&2
exit 1
fi
sleep "$HEALTH_BACKOFF_SECONDS"
if (( HEALTH_BACKOFF_SECONDS < HEALTH_MAX_BACKOFF_SECONDS )); then
HEALTH_BACKOFF_SECONDS=$((HEALTH_BACKOFF_SECONDS * 2))
if (( HEALTH_BACKOFF_SECONDS > HEALTH_MAX_BACKOFF_SECONDS )); then
HEALTH_BACKOFF_SECONDS=$HEALTH_MAX_BACKOFF_SECONDS
fi
fi
done