Skip to content

Commit 869aec0

Browse files
baijumclaude
andcommitted
fix: resolve multi-app deployment blockers
- Add .env existence guard to fail fast on first deploy if not configured - Auto-create per-app database via platform postgres (e.g., todo_app_db) - Generate Caddyfile with literal domain and project-prefixed container name instead of symlinking (fixes env var and container name ambiguity) - Update env.template with placeholders and comments for multi-app setup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent af15595 commit 869aec0

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,36 @@ jobs:
2727
username: ${{ secrets.SERVER_USER }}
2828
key: ${{ secrets.SERVER_SSH_KEY }}
2929
script: |
30-
cd /opt/apps/${{ github.event.repository.name }}
30+
APP_NAME="${{ github.event.repository.name }}"
31+
cd /opt/apps/${APP_NAME}
3132
git pull origin main
33+
34+
# Verify app .env exists
35+
if [ ! -f deploy/.env ]; then
36+
echo "ERROR: deploy/.env not found. Create it from deploy/env.template first."
37+
exit 1
38+
fi
39+
40+
# Create app-specific database if it doesn't exist
41+
APP_DB=$(echo "${APP_NAME}" | tr '-' '_')_db
42+
docker compose -f /opt/platform/docker-compose.yml exec -T postgres \
43+
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '${APP_DB}'" | grep -q 1 \
44+
|| docker compose -f /opt/platform/docker-compose.yml exec -T postgres \
45+
psql -U postgres -c "CREATE DATABASE ${APP_DB}"
46+
47+
# Build and start app containers
3248
docker compose -f deploy/docker-compose.yml up -d --build
49+
50+
# Run database migrations
3351
docker compose -f deploy/docker-compose.yml exec -T app alembic -c app/alembic.ini upgrade head
52+
53+
# Health check
3454
bash scripts/health-check.sh https://${{ secrets.APP_DOMAIN }}/health
35-
# Register app with platform Caddy
36-
ln -sf /opt/apps/${{ github.event.repository.name }}/deploy/Caddyfile /opt/platform/caddy-apps/${{ github.event.repository.name }}.caddy
55+
56+
# Generate rendered Caddyfile for platform Caddy
57+
cat > /opt/platform/caddy-apps/${APP_NAME}.caddy <<CADDYEOF
58+
${{ secrets.APP_DOMAIN }} {
59+
reverse_proxy ${APP_NAME}-app-1:8000
60+
}
61+
CADDYEOF
3762
docker compose -f /opt/platform/docker-compose.yml exec -T caddy caddy reload --config /etc/caddy/Caddyfile

deploy/env.template

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# Copy this file to .env and fill in real values before first deploy.
2+
# Credentials come from /opt/platform/.env on the server.
3+
14
APP_DOMAIN=app.example.com
2-
DATABASE_URL=postgresql://postgres:password@postgres:5432/app_db
5+
DATABASE_URL=postgresql://postgres:<password>@postgres:5432/<app_name>_db
36
REDIS_URL=redis://redis:6379
47
S3_ENDPOINT=http://minio:9000
5-
S3_BUCKET=uploads
6-
S3_ACCESS_KEY=minioadmin
7-
S3_SECRET_KEY=minioadmin
8+
S3_BUCKET=<app_name>-uploads
9+
S3_ACCESS_KEY=<minio_root_user>
10+
S3_SECRET_KEY=<minio_root_password>

0 commit comments

Comments
 (0)