From 87184591b88ff469b81308480626bb409e258d2c Mon Sep 17 00:00:00 2001 From: casper moyo Date: Tue, 2 Jun 2026 13:43:07 +0200 Subject: [PATCH] docker compose --- .github/workflows/deploy.yml | 55 ++++++++++++++++++++++++++++++ docker-compose.yml | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 docker-compose.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b79bcb9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a3e5ad7 --- /dev/null +++ b/docker-compose.yml @@ -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