-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (51 loc) · 2.22 KB
/
Copy pathdeploy.yml
File metadata and controls
62 lines (51 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Run tests
run: |
pip install -r requirements.txt
pip install pytest
pytest --tb=short || echo "No tests found, skipping"
- name: Deploy to server
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
APP_NAME="${{ github.event.repository.name }}"
cd /opt/apps/${APP_NAME}
git pull origin main
# Verify app .env exists
if [ ! -f deploy/.env ]; then
echo "ERROR: deploy/.env not found. Create it from deploy/env.template first."
exit 1
fi
# Create app-specific database if it doesn't exist
APP_DB=$(echo "${APP_NAME}" | tr '-' '_')_db
docker compose -f /opt/platform/docker-compose.yml exec -T postgres \
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '${APP_DB}'" | grep -q 1 \
|| docker compose -f /opt/platform/docker-compose.yml exec -T postgres \
psql -U postgres -c "CREATE DATABASE ${APP_DB}"
# Build and start app containers (project name = app name for predictable container names)
docker compose -p ${APP_NAME} -f deploy/docker-compose.yml up -d --build
# Run database migrations
docker compose -p ${APP_NAME} -f deploy/docker-compose.yml exec -T app alembic -c app/alembic.ini upgrade head
# Health check
bash scripts/health-check.sh https://${{ secrets.APP_DOMAIN }}/health
# Generate rendered Caddyfile for platform Caddy
cat > /opt/platform/caddy-apps/${APP_NAME}.caddy <<CADDYEOF
${{ secrets.APP_DOMAIN }} {
reverse_proxy ${APP_NAME}-app-1:8000
}
CADDYEOF
docker compose -f /opt/platform/docker-compose.yml exec -T caddy caddy reload --config /etc/caddy/Caddyfile