From b508d2dc09641b6b1f1e6946a5c771af189fbdf7 Mon Sep 17 00:00:00 2001 From: Abdulkadyr Karagishiev Date: Fri, 16 Oct 2026 12:51:35 +0300 Subject: [PATCH] ci: add automated deploy.sh script for server deployment --- deploy.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..2f7c4e1 --- /dev/null +++ b/deploy.sh @@ -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!"