feat(07-02): Add CI/CD deployment scripts
- scripts/deploy.sh: Full deploy flow with fresh builds (--no-cache) - scripts/build-check.sh: Pre-flight staleness check - Docker labels for build tracking (git commit + timestamp) - Prevents stale container bug from recurring
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
# Gravl deployment script
|
||||
# Prevents stale containers by always building fresh with --no-cache
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
LOG_FILE="$REPO_DIR/logs/deploy.log"
|
||||
BACKEND_HEALTH="http://localhost:3001/api/health"
|
||||
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
mkdir -p "$REPO_DIR/logs"
|
||||
cd "$REPO_DIR"
|
||||
|
||||
log "=== Deploy started ==="
|
||||
|
||||
# Pull latest code
|
||||
log "Pulling latest code..."
|
||||
git pull
|
||||
|
||||
# Capture build metadata
|
||||
GIT_COMMIT=$(git rev-parse HEAD)
|
||||
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
log "Commit: $(git rev-parse --short HEAD) | Date: $BUILD_DATE"
|
||||
|
||||
# Build fresh images — no-cache prevents stale assets
|
||||
log "Building images (--no-cache)..."
|
||||
export GIT_COMMIT BUILD_DATE
|
||||
docker compose build --no-cache
|
||||
|
||||
# Restart containers with new images
|
||||
log "Starting containers..."
|
||||
docker compose up -d --force-recreate
|
||||
|
||||
# Health check: wait up to 60s for backend
|
||||
log "Health check..."
|
||||
for i in $(seq 1 12); do
|
||||
if curl -sf "$BACKEND_HEALTH" >/dev/null 2>&1; then
|
||||
log "Backend healthy"
|
||||
break
|
||||
fi
|
||||
[ "$i" -eq 12 ] && { log "ERROR: Health check failed after 60s"; exit 1; }
|
||||
log "Waiting... ($i/12)"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
log "=== Deploy complete: ${GIT_COMMIT:0:7} ==="
|
||||
Reference in New Issue
Block a user