File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Deploy Production
2+
3+ on :
4+ workflow_run :
5+ workflows : ["CI"]
6+ branches : [main]
7+ types :
8+ - completed
9+
10+ jobs :
11+ deploy :
12+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
13+
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Deploy to VPS
18+ uses : appleboy/ssh-action@v1.0.3
19+ with :
20+ host : ${{ secrets.VPS_HOST }}
21+ username : ${{ secrets.VPS_USER }}
22+ key : ${{ secrets.VPS_SSH_KEY }}
23+ port : ${{ secrets.VPS_PORT }}
24+
25+ script : |
26+ set -e
27+
28+ cd /Hs_codes_api
29+
30+ echo "Pulling latest images..."
31+ docker compose pull
32+
33+ echo "Starting updated containers..."
34+ docker compose up -d
35+
36+ echo "Waiting for application..."
37+ sleep 15
38+
39+ echo "Running migrations..."
40+ docker compose exec -T web python manage.py migrate --noinput
41+
42+ echo "Checking health endpoint..."
43+
44+ for i in $(seq 1 20); do
45+ if curl -fsS http://localhost:8001/api/v1/health/ > /dev/null; then
46+ echo "Health check passed"
47+ exit 0
48+ fi
49+
50+ echo "Waiting for healthy container..."
51+ sleep 5
52+ done
53+
54+ echo "Health check failed"
55+ exit 1
Original file line number Diff line number Diff line change 1+ version : " 3.9"
2+
3+ services :
4+ db :
5+ image : postgres:16-alpine
6+ container_name : hs_postgres
7+
8+ restart : unless-stopped
9+
10+ environment :
11+ POSTGRES_DB : ${DB_NAME}
12+ POSTGRES_USER : ${DB_USER}
13+ POSTGRES_PASSWORD : ${DB_PASSWORD}
14+
15+ volumes :
16+ - postgres_data:/var/lib/postgresql/data
17+
18+ healthcheck :
19+ test : ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
20+ interval : 10s
21+ timeout : 5s
22+ retries : 5
23+ start_period : 10s
24+
25+ networks :
26+ - backend
27+
28+ web :
29+ image : ghcr.io/casymoyo-spec/hs-api:latest
30+ container_name : hs_api
31+
32+ restart : unless-stopped
33+
34+ env_file :
35+ - .env
36+
37+ depends_on :
38+ db :
39+ condition : service_healthy
40+
41+ ports :
42+ - " 8001:8001"
43+
44+ healthcheck :
45+ test :
46+ [
47+ " CMD" ,
48+ " python" ,
49+ " -c" ,
50+ " import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health/')"
51+ ]
52+ interval : 30s
53+ timeout : 10s
54+ retries : 3
55+ start_period : 30s
56+
57+ networks :
58+ - backend
59+
60+ volumes :
61+ postgres_data :
62+
63+ networks :
64+ backend :
65+ driver : bridge
You can’t perform that action at this time.
0 commit comments