services: postgres: image: postgres:16.10-alpine restart: unless-stopped environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} volumes: [postgres_data:/var/lib/postgresql/data] healthcheck: test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 3s timeout: 2s retries: 20 redis: image: redis:7.4.6-alpine restart: unless-stopped command: ["redis-server", "--appendonly", "yes"] volumes: [redis_data:/data] healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 3s timeout: 2s retries: 20 migrate: build: . environment: DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable RUN_MIGRATIONS_ONLY: "1" depends_on: postgres: {condition: service_healthy} restart: "no" api1: build: . restart: unless-stopped environment: &api_env APP_HOST: 0.0.0.0 APP_PORT: "8080" DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable REDIS_URL: redis://redis:6379/0 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} INSTANCE_ID: api1 depends_on: migrate: {condition: service_completed_successfully} redis: {condition: service_healthy} healthcheck: &api_health test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] interval: 3s timeout: 2s retries: 10 api2: build: . restart: unless-stopped environment: <<: *api_env INSTANCE_ID: api2 depends_on: migrate: {condition: service_completed_successfully} redis: {condition: service_healthy} healthcheck: *api_health lb: image: nginx:1.29-alpine restart: unless-stopped ports: ["127.0.0.1:8080:8080"] volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro depends_on: api1: {condition: service_healthy} api2: {condition: service_healthy} volumes: postgres_data: redis_data: