ci: add automated deploy.sh script for server deployment
This commit is contained in:
parent
54581305dd
commit
b508d2dc09
39
deploy.sh
Executable file
39
deploy.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/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!"
|
||||||
Loading…
Reference in New Issue
Block a user