-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_script.sh
More file actions
47 lines (34 loc) · 940 Bytes
/
Copy pathdeploy_script.sh
File metadata and controls
47 lines (34 loc) · 940 Bytes
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
#!/bin/bash
set -euo pipefail
APP_DIR="/opt/myapp"
LOG_FILE="/var/log/deploy.log"
HEALTH_URL="http://localhost:8080/health"
MAX_RETRIES=5
DELAY=2
log() {
echo "[$(date '+%F %T')] $*" | tee -a "$LOG_FILE"
}
log "===== Deployment Started ====="
cd "$APP_DIR"
log "Pulling latest code..."
git pull
log "Pulling Docker images..."
docker compose pull
log "Starting containers..."
docker compose up -d
log "Running health check..."
for ((i=1; i<=MAX_RETRIES; i++)); do
if curl -fs "$HEALTH_URL" >/dev/null; then
log "Health check passed."
log "===== Deployment Successful ====="
exit 0
fi
log "Health check failed (attempt $i/$MAX_RETRIES). Retrying in ${DELAY}s..."
sleep "$DELAY"
DELAY=$((DELAY * 2))
done
log "Health check failed after $MAX_RETRIES retries."
log "Recent container logs:"
docker compose logs --tail=50 | tee -a "$LOG_FILE"
log "===== Deployment Failed ====="
exit 1