#!/bin/bash set -e echo "=== Deploy app01 ===" # 0. Configure git safe directory git config --global --add safe.directory /home/nplx/gch3n-infra/data/gitea/git/repositories/gch3n/app01.git 2>/dev/null || true # 1. Clone repo rm -rf /tmp/app01-build mkdir -p /tmp/app01-build git clone /home/nplx/gch3n-infra/data/gitea/git/repositories/gch3n/app01.git /tmp/app01-build # 2. Build Docker image cd /tmp/app01-build docker build -t app01:latest . # 3. Stop old container docker stop app01-blue 2>/dev/null || true docker rm app01-blue 2>/dev/null || true # 4. Start new container docker run -d \ --name app01-blue \ --restart unless-stopped \ -p 127.0.0.1:8001:8000 \ -e PORT=8000 \ app01:latest # 5. Health check sleep 5 if curl -sf http://localhost:8001/health > /dev/null; then echo "Health check passed" # Update Caddy upstream echo "upstream app_backend { server 127.0.0.1:8001; }" | sudo tee /etc/caddy/upstream.conf sudo systemctl reload caddy echo "Deploy success: https://app.gch3n.online" else echo "Health check failed" docker stop app01-blue && docker rm app01-blue exit 1 fi # 6. Cleanup rm -rf /tmp/app01-build