dana-medical-site/deploy.sh
2026-10-16 12:51:35 +03:00

40 lines
1.1 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..."
git fetch origin main
git reset --hard 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 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"
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
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
echo "[$(date --iso-8601=seconds)] Deployment completed successfully!"