| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- name: Deploy
- on:
- push:
- branches: [main, master]
- workflow_dispatch:
- permissions:
- contents: read
- packages: write
- concurrency:
- group: ${{ github.workflow }}-${{ github.ref }}
- cancel-in-progress: true
- jobs:
- deploy-check:
- name: Pre-deployment Checks
- runs-on: ubuntu-latest
- timeout-minutes: 10
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v6
- - name: Set up Python
- uses: actions/setup-python@v5
- with:
- python-version: "3.11"
- cache: 'pip'
- - name: Install system dependencies
- run: |
- sudo apt-get update
- sudo apt-get install -y build-essential libssl-dev libicapapi-dev python3-dev libpq-dev
- - name: Install dependencies
- run: |
- python -m pip install --upgrade pip
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- - name: Run deployment checks
- run: |
- # Check if all required environment variables are documented
- echo "Checking environment variables..."
- python -c "
- import os
- required_vars = ['FLASK_ENV', 'DATABASE_URL']
- missing_vars = []
-
- for var in required_vars:
- if not os.getenv(var):
- missing_vars.append(var)
-
- if missing_vars:
- print(f'⚠️ Missing env vars (should be set in production): {missing_vars}')
- else:
- print('✅ All required environment variables are documented')
- "
- - name: Test database connection
- run: |
- python -c "
- import sys
- import os
- sys.path.insert(0, os.getcwd())
-
- try:
- from database.database import get_engine, create_dynamic_tables
- engine = get_engine()
- create_dynamic_tables(engine)
- except Exception as e:
- print(f'❌ Database connection test failed: {e}')
- sys.exit(1)
- "
- - name: Test application startup
- run: |
- timeout 10s python app.py &
- sleep 5
- if pgrep -f "python app.py" > /dev/null; then
- echo "✅ Application starts successfully"
- pkill -f "python app.py"
- else
- echo "❌ Application failed to start"
- exit 1
- fi
- build-docker:
- name: Build Docker Image
- runs-on: ubuntu-latest
- timeout-minutes: 20
- needs: deploy-check
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v6
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - name: Login to GitHub Container Registry
- uses: docker/login-action@v3
- with:
- registry: ghcr.io
- username: ${{ github.actor }}
- password: ${{ secrets.GITHUB_TOKEN }}
- - name: Extract metadata
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ghcr.io/${{ github.repository_owner }}/squidstats
- tags: |
- type=ref,event=branch
- type=sha,prefix={{branch}}-
- type=raw,value=latest,enable={{is_default_branch}}
- - name: Build and push Docker image
- uses: docker/build-push-action@v5
- with:
- context: .
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
- cache-from: type=gha
- cache-to: type=gha,mode=max
- - name: Test Docker image
- run: |
- docker run --rm -d --name squidstats-test -p 5000:5000 ghcr.io/${{ github.repository_owner }}/squidstats:latest
- sleep 10
- if docker ps | grep -q squidstats-test; then
- echo "✅ Docker image runs successfully"
- docker stop squidstats-test
- else
- echo "❌ Docker image failed to run"
- docker logs squidstats-test || true
- exit 1
- fi
|