Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Production

on:
workflow_run:
workflows: ["CI"]
branches: [main]
types:
- completed

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}

runs-on: ubuntu-latest

steps:
- name: Deploy to VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}

script: |
set -e

cd /Hs_codes_api

echo "Pulling latest images..."
docker compose pull

echo "Starting updated containers..."
docker compose up -d

echo "Waiting for application..."
sleep 15

echo "Running migrations..."
docker compose exec -T web python manage.py migrate --noinput

echo "Checking health endpoint..."

for i in $(seq 1 20); do
if curl -fsS http://localhost:8001/api/v1/health/ > /dev/null; then
echo "Health check passed"
exit 0
fi

echo "Waiting for healthy container..."
sleep 5
done

echo "Health check failed"
exit 1
65 changes: 65 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: "3.9"

services:
db:
image: postgres:16-alpine
container_name: hs_postgres

restart: unless-stopped

environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}

volumes:
- postgres_data:/var/lib/postgresql/data

healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s

networks:
- backend

web:
image: ghcr.io/casymoyo-spec/hs-api:latest
container_name: hs_api

restart: unless-stopped

env_file:
- .env

depends_on:
db:
condition: service_healthy

ports:
- "8001:8001"

healthcheck:
test:
[
"CMD",
"python",
"-c",
"import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health/')"
]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s

networks:
- backend

volumes:
postgres_data:

networks:
backend:
driver: bridge