4 Commits

Author SHA1 Message Date
Joyce
49dbc786e9 fix: use SYNC_DATABASE_URL env var for alembic migrations
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 17:24:41 -05:00
Joyce
922b6f31d1 add static serve 2026-01-21 16:36:40 -05:00
Joyce
f02b6ca886 chore: rename compose files - production as default
- docker-compose.yml → production (Coolify default)
- docker-compose.dev.yml → local development

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 15:25:05 -05:00
Joyce
cd62d7f94b chore: improve production deployment flexibility
- Switch frontend from nginx to caddy for consistency with Coolify
- Make VITE_API_URL optional, auto-derive from window.location.origin/api
- Remove hardcoded port mappings, let Coolify/Traefik handle routing
- Simplifies deployment configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 15:25:05 -05:00
6 changed files with 101 additions and 83 deletions

View File

@@ -1,3 +1,4 @@
import os
from logging.config import fileConfig from logging.config import fileConfig
from alembic import context from alembic import context
@@ -9,6 +10,10 @@ config = context.config
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
target_metadata = Base.metadata target_metadata = Base.metadata
# Use SYNC_DATABASE_URL env var if set, otherwise fall back to alembic.ini
if os.getenv("SYNC_DATABASE_URL"):
config.set_main_option("sqlalchemy.url", os.getenv("SYNC_DATABASE_URL"))
def run_migrations_offline(): def run_migrations_offline():
url = config.get_main_option("sqlalchemy.url") url = config.get_main_option("sqlalchemy.url")

50
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,50 @@
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: availability
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
backend:
build:
context: ./backend
dockerfile: Dockerfile
environment:
DATABASE_URL: postgresql+asyncpg://postgres:postgres@db:5432/availability
SYNC_DATABASE_URL: postgresql://postgres:postgres@db:5432/availability
env_file:
- .env
ports:
- "8001:8000"
depends_on:
db:
condition: service_healthy
volumes:
- ./backend/src:/app/src
- ./backend/alembic:/app/alembic
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "5174:8080"
environment:
VITE_API_URL: http://localhost:8001
depends_on:
- backend
volumes:
- ./frontend/src:/app/src
volumes:
postgres_data:

View File

@@ -1,52 +0,0 @@
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD required}
POSTGRES_DB: ${POSTGRES_DB:-availability}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
backend:
build:
context: ./backend
dockerfile: Dockerfile
environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-availability}
SYNC_DATABASE_URL: postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-availability}
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-587}
SMTP_USER: ${SMTP_USER:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
ZULIP_SITE: ${ZULIP_SITE:-}
ZULIP_EMAIL: ${ZULIP_EMAIL:-}
ZULIP_API_KEY: ${ZULIP_API_KEY:-}
ZULIP_STREAM: ${ZULIP_STREAM:-general}
ports:
- "8000:8000"
depends_on:
db:
condition: service_healthy
restart: unless-stopped
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.prod
args:
VITE_API_URL: ${VITE_API_URL:-}
ports:
- "8080:8080"
depends_on:
- backend
restart: unless-stopped
volumes:
postgres_data:

View File

@@ -2,49 +2,49 @@ services:
db: db:
image: postgres:16-alpine image: postgres:16-alpine
environment: environment:
POSTGRES_USER: postgres POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD required}
POSTGRES_DB: availability POSTGRES_DB: ${POSTGRES_DB:-availability}
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
ports:
- "5433:5432"
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"] test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s interval: 5s
timeout: 5s timeout: 5s
retries: 5 retries: 5
restart: unless-stopped
backend: backend:
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
environment: environment:
DATABASE_URL: postgresql+asyncpg://postgres:postgres@db:5432/availability DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-availability}
SYNC_DATABASE_URL: postgresql://postgres:postgres@db:5432/availability SYNC_DATABASE_URL: postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-availability}
env_file: SMTP_HOST: ${SMTP_HOST:-}
- .env SMTP_PORT: ${SMTP_PORT:-587}
ports: SMTP_USER: ${SMTP_USER:-}
- "8001:8000" SMTP_PASSWORD: ${SMTP_PASSWORD:-}
ZULIP_SITE: ${ZULIP_SITE:-}
ZULIP_EMAIL: ${ZULIP_EMAIL:-}
ZULIP_API_KEY: ${ZULIP_API_KEY:-}
ZULIP_STREAM: ${ZULIP_STREAM:-general}
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
volumes: restart: unless-stopped
- ./backend/src:/app/src
- ./backend/alembic:/app/alembic
frontend: frontend:
build: build:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile.prod
ports: args:
- "5174:8080" VITE_API_URL: ${VITE_API_URL:-}
environment:
VITE_API_URL: http://localhost:8001
depends_on: depends_on:
- backend - backend
volumes: restart: unless-stopped
- ./frontend/src:/app/src expose:
- '80'
volumes: volumes:
postgres_data: postgres_data:

View File

@@ -15,18 +15,14 @@ ENV VITE_API_URL=${VITE_API_URL}
RUN npm run build RUN npm run build
# Production stage # Production stage
FROM caddy:alpine FROM nginx:alpine
# Copy built assets # Copy built assets
COPY --from=builder /app/dist /srv COPY --from=builder /app/dist /usr/share/nginx/html
# Caddyfile for SPA routing # Copy nginx config
RUN echo ':8080 { \ COPY nginx.conf /etc/nginx/conf.d/default.conf
root * /srv \
file_server \
try_files {path} /index.html \
}' > /etc/caddy/Caddyfile
EXPOSE 8080 EXPOSE 80
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"] CMD ["nginx", "-g", "daemon off;"]

19
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,19 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 6;
}