Update docker configuration files
This commit is contained in:
@@ -1,202 +1,180 @@
|
||||
version: "3.9"
|
||||
|
||||
# A single compose file that supports development and production.
|
||||
# Switch modes by setting APP_ENV and COMPOSE_PROFILES to either
|
||||
# "development" (default) or "production" before running docker compose up.
|
||||
|
||||
x-backend-common: &backend-common
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
APP_ENV: ${APP_ENV:-development}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
LIVEKIT_URL: ${LIVEKIT_URL}
|
||||
LIVEKIT_API_KEY: ${LIVEKIT_API_KEY}
|
||||
LIVEKIT_API_SECRET: ${LIVEKIT_API_SECRET}
|
||||
restart: unless-stopped
|
||||
|
||||
x-frontend-common: &frontend-common
|
||||
build:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
APP_ENV: ${APP_ENV:-development}
|
||||
# Server-side calls from Next.js hit the backend by container name
|
||||
BACKEND_URL: http://backend:8000
|
||||
restart: unless-stopped
|
||||
|
||||
x-postgres-common: &postgres-common
|
||||
image: pgvector/pgvector:pg16
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-app}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-app}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
|
||||
x-livekit-common: &livekit-common
|
||||
image: livekit/livekit-server:latest
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
# Keys are passed in via env; LiveKit will refuse to start without them.
|
||||
LIVEKIT_KEYS: "${LIVEKIT_API_KEY:-devkey}:${LIVEKIT_API_SECRET:-devsecret}"
|
||||
LIVEKIT_PORT: 7880
|
||||
LIVEKIT_RTC_PORT_RANGE_START: 50000
|
||||
LIVEKIT_RTC_PORT_RANGE_END: 60000
|
||||
restart: unless-stopped
|
||||
#
|
||||
# APP DOCKER COMPOSE
|
||||
#
|
||||
# This file defines the application services for avaaz.ai. It is designed
|
||||
# to work in both development and production environments, controlled by the
|
||||
# `COMPOSE_PROFILES` environment variable.
|
||||
#
|
||||
# Profiles:
|
||||
# - `dev`: For local development. Exposes ports to localhost, mounts local
|
||||
# code for hot-reloading, and uses development-specific commands.
|
||||
# - `prod`: For production. Does not expose ports directly (relies on the
|
||||
# `proxy` network), uses production-ready commands, and enables
|
||||
# restarts.
|
||||
#
|
||||
# To run in development:
|
||||
# > COMPOSE_PROFILES=dev docker compose up --build
|
||||
#
|
||||
# To run in production:
|
||||
# > COMPOSE_PROFILES=prod docker compose up --build -d
|
||||
#
|
||||
# For more details, see: ./docs/architecture.md
|
||||
#
|
||||
|
||||
services:
|
||||
backend-dev:
|
||||
<<: *backend-common
|
||||
profiles: ["development"]
|
||||
container_name: backend
|
||||
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
||||
ports:
|
||||
- "8000:8000"
|
||||
# --------------------------------------------------------------------------
|
||||
# Next.js Frontend
|
||||
# --------------------------------------------------------------------------
|
||||
frontend:
|
||||
# Service name matches the Caddyfile reverse_proxy directive.
|
||||
container_name: frontend
|
||||
build:
|
||||
context: ./frontend
|
||||
# The Dockerfile is expected to handle multi-stage builds for both
|
||||
# development and production.
|
||||
dockerfile: Dockerfile
|
||||
# The application is stateless, so no volume is needed for the container
|
||||
# itself. A bind mount is used in development for hot-reloading.
|
||||
volumes:
|
||||
# Mount source for hot reload; keep venv inside image
|
||||
- ./backend:/app
|
||||
# Mounts the local frontend source code into the container for
|
||||
# hot-reloading during development.
|
||||
- if:
|
||||
- COMPOSE_PROFILES=dev
|
||||
type: bind
|
||||
source: ./frontend
|
||||
target: /app
|
||||
# Environment variables are loaded from the shared .env file.
|
||||
env_file: .env
|
||||
# Restart policy is only applied in production. In development, we
|
||||
# typically want the container to stop on errors for debugging.
|
||||
restart: ${DOCKER_RESTART_POLICY:-unless-stopped}
|
||||
profiles:
|
||||
- dev
|
||||
- prod
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# FastAPI Backend
|
||||
# --------------------------------------------------------------------------
|
||||
backend:
|
||||
# Service name matches the Caddyfile reverse_proxy directive.
|
||||
container_name: backend
|
||||
build:
|
||||
context: ./backend
|
||||
# The Dockerfile should contain stages for both development (with
|
||||
# debugging tools) and production (a lean, optimized image).
|
||||
dockerfile: Dockerfile
|
||||
# The application is stateless. A bind mount is used in development.
|
||||
volumes:
|
||||
# Mounts the local backend source code for hot-reloading with uvicorn.
|
||||
- if:
|
||||
- COMPOSE_PROFILES=dev
|
||||
type: bind
|
||||
source: ./backend
|
||||
target: /app
|
||||
# Environment variables provide configuration for database connections,
|
||||
# API keys, and other secrets.
|
||||
env_file: .env
|
||||
# Explicitly depend on postgres to ensure it starts first.
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
livekit:
|
||||
condition: service_started
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["backend"]
|
||||
|
||||
backend-prod:
|
||||
<<: *backend-common
|
||||
profiles: ["production"]
|
||||
container_name: backend
|
||||
# Use development-specific command for auto-reloading.
|
||||
command:
|
||||
- gunicorn
|
||||
- app.main:app
|
||||
- -k
|
||||
- uvicorn.workers.UvicornWorker
|
||||
- --bind
|
||||
- 0.0.0.0:8000
|
||||
- --workers
|
||||
- "4"
|
||||
- --timeout
|
||||
- "120"
|
||||
expose:
|
||||
- "8000"
|
||||
depends_on:
|
||||
postgres-prod:
|
||||
condition: service_healthy
|
||||
livekit-prod:
|
||||
condition: service_started
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["backend"]
|
||||
proxy:
|
||||
aliases: ["backend"]
|
||||
- if:
|
||||
- COMPOSE_PROFILES=dev
|
||||
# Uvicorn with --reload watches for file changes.
|
||||
content: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
||||
- else:
|
||||
# Gunicorn is a battle-tested WSGI server for production.
|
||||
content: gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000
|
||||
restart: ${DOCKER_RESTART_POLICY:-unless-stopped}
|
||||
profiles:
|
||||
- dev
|
||||
- prod
|
||||
|
||||
frontend-dev:
|
||||
<<: *frontend-common
|
||||
build:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile
|
||||
target: dev
|
||||
profiles: ["development"]
|
||||
container_name: frontend
|
||||
command: ["npm", "run", "dev"]
|
||||
ports:
|
||||
- "3000:3000"
|
||||
# --------------------------------------------------------------------------
|
||||
# PostgreSQL Database
|
||||
# --------------------------------------------------------------------------
|
||||
postgres:
|
||||
# Standard service name for a PostgreSQL database.
|
||||
container_name: postgres
|
||||
# Use the latest official Postgres image with pgvector support.
|
||||
image: pgvector/pgvector:pg16
|
||||
# A volume is essential to persist database data across container
|
||||
# restarts and deployments.
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
- frontend_node_modules:/app/node_modules
|
||||
depends_on:
|
||||
backend:
|
||||
condition: service_started
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["frontend"]
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
env_file: .env
|
||||
# The healthcheck ensures that other services don't start until the
|
||||
# database is ready to accept connections.
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-postgres}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: ${DOCKER_RESTART_POLICY:-unless-stopped}
|
||||
profiles:
|
||||
- dev
|
||||
- prod
|
||||
|
||||
frontend-prod:
|
||||
<<: *frontend-common
|
||||
build:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile
|
||||
target: runner
|
||||
profiles: ["production"]
|
||||
container_name: frontend
|
||||
# Uses the standalone Next.js output from the Dockerfile
|
||||
command: ["node", "server.js"]
|
||||
expose:
|
||||
- "3000"
|
||||
depends_on:
|
||||
backend-prod:
|
||||
condition: service_started
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["frontend"]
|
||||
proxy:
|
||||
aliases: ["frontend"]
|
||||
|
||||
postgres-dev:
|
||||
<<: *postgres-common
|
||||
profiles: ["development"]
|
||||
container_name: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["postgres"]
|
||||
|
||||
postgres-prod:
|
||||
<<: *postgres-common
|
||||
profiles: ["production"]
|
||||
container_name: postgres
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["postgres"]
|
||||
|
||||
livekit-dev:
|
||||
<<: *livekit-common
|
||||
profiles: ["development"]
|
||||
# --------------------------------------------------------------------------
|
||||
# LiveKit Real-Time Server
|
||||
# --------------------------------------------------------------------------
|
||||
livekit:
|
||||
# Service name matches the Caddyfile reverse_proxy directive.
|
||||
container_name: livekit
|
||||
# Use the latest official LiveKit server image.
|
||||
image: livekit/livekit-server:latest
|
||||
# The command starts the server with a configuration file. The file is
|
||||
# generated on startup based on environment variables.
|
||||
command: --config /etc/livekit.yaml
|
||||
# In development, ports are exposed for direct connection. In production,
|
||||
# Caddy handles this.
|
||||
ports:
|
||||
- "7880:7880"
|
||||
- "50000-60000:50000-60000/udp"
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["livekit"]
|
||||
|
||||
livekit-prod:
|
||||
<<: *livekit-common
|
||||
profiles: ["production"]
|
||||
container_name: livekit
|
||||
# UDP media must be published even in production; signaling stays internal.
|
||||
ports:
|
||||
- "50000-60000:50000-60000/udp"
|
||||
networks:
|
||||
app_internal:
|
||||
aliases: ["livekit"]
|
||||
proxy:
|
||||
aliases: ["livekit"]
|
||||
# WebRTC signaling (TCP/WS)
|
||||
- target: 7880
|
||||
published: 7880
|
||||
protocol: tcp
|
||||
mode: host
|
||||
# WebRTC media (UDP)
|
||||
- target: 50000-60000
|
||||
published: 50000-60000
|
||||
protocol: udp
|
||||
mode: host
|
||||
environment:
|
||||
# The livekit.yaml is generated from environment variables.
|
||||
# This allows easy configuration without managing a separate file.
|
||||
LIVEKIT_KEYS: "${LIVEKIT_API_KEY}:${LIVEKIT_API_SECRET}"
|
||||
LIVEKIT_PORT: 7880
|
||||
LIVEKIT_LOG_LEVEL: info
|
||||
LIVEKIT_RTC_UDP_PORT: 7881
|
||||
LIVEKIT_RTC_TCP_PORT: 7881
|
||||
LIVEKIT_TURN_ENABLED: "true"
|
||||
LIVEKIT_TURN_PORT: 3478
|
||||
env_file: .env
|
||||
restart: ${DOCKER_RESTART_POLICY:-unless-stopped}
|
||||
profiles:
|
||||
- dev
|
||||
- prod
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Volumes
|
||||
# ----------------------------------------------------------------------------
|
||||
# Defines the named volume for persisting PostgreSQL data.
|
||||
volumes:
|
||||
postgres_data:
|
||||
frontend_node_modules:
|
||||
postgres-data:
|
||||
driver: local
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Networks
|
||||
# ----------------------------------------------------------------------------
|
||||
# Defines the networks used by the services.
|
||||
networks:
|
||||
app_internal:
|
||||
# Private app network for service-to-service traffic
|
||||
driver: bridge
|
||||
default:
|
||||
# The default network for internal communication between app services.
|
||||
name: app_network
|
||||
proxy:
|
||||
# External network provided by the infra stack (Caddy attaches here)
|
||||
# This external network connects services to the Caddy reverse proxy
|
||||
# defined in `infra/docker-compose.yml`.
|
||||
name: proxy
|
||||
external: true
|
||||
|
||||
Reference in New Issue
Block a user