58 lines
1.7 KiB
Bash
Executable File
58 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
DEPLOY_DIR="/home/mikail/dana-medical"
|
|
|
|
echo "[$(date --iso-8601=seconds)] Starting deployment for dana-medical..."
|
|
|
|
cd "$DEPLOY_DIR"
|
|
|
|
# 1. Pull latest code from Gitea
|
|
echo "Pulling latest changes from origin/main..."
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
echo "Deployment refused: working tree contains changes" >&2
|
|
exit 1
|
|
fi
|
|
git fetch origin main
|
|
git merge --ff-only origin/main
|
|
|
|
# 2. Build and restart API container
|
|
echo "Building and restarting api service..."
|
|
docker compose -p dana-medical -f docker-compose.prod.yml build api
|
|
docker compose -p dana-medical -f docker-compose.prod.yml up -d --no-deps api
|
|
|
|
# 3. Check health status
|
|
echo "Verifying health..."
|
|
api_id="$(docker compose -p dana-medical -f docker-compose.prod.yml ps -q api)"
|
|
test -n "$api_id"
|
|
|
|
healthy=false
|
|
for i in $(seq 1 30); do
|
|
status="$(docker inspect --format '{{.State.Health.Status}}' "$api_id" 2>/dev/null || echo "starting")"
|
|
if [ "$status" = "healthy" ]; then
|
|
healthy=true
|
|
echo "API service is healthy!"
|
|
break
|
|
fi
|
|
if [ "$status" = "unhealthy" ]; then
|
|
echo "API service is unhealthy! Dumping logs:" >&2
|
|
docker logs --tail 50 "$api_id" >&2
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
if [ "$healthy" != true ]; then
|
|
echo "API health check timed out" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Outbound-only 1C polling supersedes the legacy bridge. Retain the stopped
|
|
# container for rollback, but do not let it return on a Docker daemon restart.
|
|
if docker inspect dana-1c-bridge >/dev/null 2>&1; then
|
|
docker update --restart=no dana-1c-bridge >/dev/null
|
|
docker stop --time 15 dana-1c-bridge >/dev/null
|
|
fi
|
|
|
|
echo "[$(date --iso-8601=seconds)] Deployment completed successfully!"
|