# Lab3 level 3: single public entry point (nginx) -> 2 interchangeable API replicas # -> one shared PostgreSQL database. Sessions and the idempotency ledger live in the DB. services: db: image: postgres:16-alpine restart: unless-stopped environment: POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set a synthetic local password in .env} POSTGRES_DB: ${POSTGRES_DB:-messenger} volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-messenger}"] interval: 3s timeout: 3s retries: 20 minio: image: bitnamilegacy/minio:latest restart: unless-stopped user: "0:0" # Bitnami setup chowns the named volume, then drops to its own user environment: MINIO_ROOT_USER: ${S3_ACCESS_KEY:-messenger} MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env} MINIO_DATA_DIR: /data MINIO_DEFAULT_BUCKETS: ${S3_BUCKET:-messenger} MINIO_CONSOLE_PORT_NUMBER: "9001" volumes: - s3data:/data healthcheck: test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/minio/health/live > /dev/null"] interval: 5s timeout: 3s retries: 30 api1: build: . restart: unless-stopped environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 APP_ENV: lab INSTANCE_ALIAS: api1 DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL in .env} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} S3_ENDPOINT: http://minio:9000 S3_BUCKET: ${S3_BUCKET:-messenger} S3_ACCESS_KEY: ${S3_ACCESS_KEY:-messenger} S3_SECRET_KEY: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env} depends_on: db: condition: service_healthy minio: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import os,urllib.request; urllib.request.urlopen('http://127.0.0.1:%s/health/ready' % os.environ.get('APP_PORT','8080'), timeout=2)"] interval: 5s timeout: 3s retries: 20 api2: build: . restart: unless-stopped environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 APP_ENV: lab INSTANCE_ALIAS: api2 DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL in .env} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} S3_ENDPOINT: http://minio:9000 S3_BUCKET: ${S3_BUCKET:-messenger} S3_ACCESS_KEY: ${S3_ACCESS_KEY:-messenger} S3_SECRET_KEY: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env} depends_on: db: condition: service_healthy minio: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import os,urllib.request; urllib.request.urlopen('http://127.0.0.1:%s/health/ready' % os.environ.get('APP_PORT','8080'), timeout=2)"] interval: 5s timeout: 3s retries: 20 lb: image: nginx:1.27-alpine restart: unless-stopped volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro ports: - "8080:8080" depends_on: api1: condition: service_healthy api2: condition: service_healthy volumes: pgdata: s3data: