169 lines
5.0 KiB
YAML
169 lines
5.0 KiB
YAML
# ==============================================================================
|
|
# Agriculture Trading Backoffice (ATB) - Production Docker Compose Stack
|
|
# Multi-tenant Architecture per UP-AI v1.5 / tech-profile.yaml
|
|
# ==============================================================================
|
|
name: atb-production
|
|
|
|
services:
|
|
# ---- Primary Relational Database with Row-Level Security (PostgreSQL 17) ----
|
|
postgres:
|
|
image: ${POSTGRES_IMAGE:-postgres:17-alpine}
|
|
container_name: atb-prod-postgres
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-atb}
|
|
POSTGRES_USER: ${POSTGRES_USER:-atb}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env.prod}
|
|
KEYCLOAK_DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD:?Set KEYCLOAK_DB_PASSWORD in .env.prod}
|
|
volumes:
|
|
- postgres_prod_data:/var/lib/postgresql/data
|
|
- ./docker/postgres/init/01-create-keycloak-db.sh:/docker-entrypoint-initdb.d/01-create-keycloak-db.sh:ro
|
|
networks:
|
|
- atb-internal-net
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 15s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "2.0"
|
|
memory: 2048M
|
|
reservations:
|
|
cpus: "0.5"
|
|
memory: 512M
|
|
|
|
# ---- High-Performance Cache & Message Streams (Valkey) ----
|
|
valkey:
|
|
image: ${VALKEY_IMAGE:-valkey/valkey:8-alpine}
|
|
container_name: atb-prod-valkey
|
|
restart: unless-stopped
|
|
command: ["valkey-server", "--save", "60", "1", "--appendonly", "yes"]
|
|
volumes:
|
|
- valkey_prod_data:/data
|
|
networks:
|
|
- atb-internal-net
|
|
healthcheck:
|
|
test: ["CMD", "valkey-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 5
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
|
|
# ---- Enterprise Identity & Access Management (Keycloak 26) ----
|
|
keycloak:
|
|
image: ${KEYCLOAK_IMAGE:-quay.io/keycloak/keycloak:26.8.0}
|
|
container_name: atb-prod-keycloak
|
|
restart: unless-stopped
|
|
command: ["start-dev", "--health-enabled=true"]
|
|
environment:
|
|
KC_DB: postgres
|
|
KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
|
|
KC_DB_USERNAME: keycloak
|
|
KC_DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD:?Set KEYCLOAK_DB_PASSWORD in .env.prod}
|
|
KC_BOOTSTRAP_ADMIN_USERNAME: ${KEYCLOAK_BOOTSTRAP_ADMIN_USERNAME:-admin}
|
|
KC_BOOTSTRAP_ADMIN_PASSWORD: ${KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD:?Set KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD in .env.prod}
|
|
KC_HTTP_RELATIVE_PATH: /auth
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
networks:
|
|
- atb-internal-net
|
|
healthcheck:
|
|
test:
|
|
- CMD-SHELL
|
|
- >-
|
|
bash -c 'exec 3<>/dev/tcp/127.0.0.1/9000;
|
|
printf "GET /health/ready HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" >&3;
|
|
grep -q "200 OK" <&3'
|
|
interval: 15s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 30s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "2.0"
|
|
memory: 1536M
|
|
|
|
# ---- Core Trading Backoffice FastAPI Backend ----
|
|
backend:
|
|
build:
|
|
context: .
|
|
dockerfile: docker/Dockerfile.backend
|
|
image: atb-backend:1.0.0
|
|
container_name: atb-prod-backend
|
|
restart: unless-stopped
|
|
environment:
|
|
DATABASE_URL: postgresql://${POSTGRES_USER:-atb}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-atb}
|
|
VALKEY_URL: valkey://valkey:6379/0
|
|
KEYCLOAK_ISSUER: ${KEYCLOAK_ISSUER:-http://keycloak:8080/auth/realms/atb}
|
|
KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID:-atb-portal}
|
|
KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET:-}
|
|
USE_IDENTITY_MOCK: "False"
|
|
ENVIRONMENT: "production"
|
|
LOG_LEVEL: "INFO"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
valkey:
|
|
condition: service_healthy
|
|
networks:
|
|
- atb-internal-net
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -f http://127.0.0.1:8000/health || exit 1"]
|
|
interval: 15s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 15s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "2.0"
|
|
memory: 1024M
|
|
reservations:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
|
|
# ---- Hardened Frontend Web Portal (Nginx Reverse Proxy & React SPA) ----
|
|
frontend:
|
|
build:
|
|
context: .
|
|
dockerfile: docker/Dockerfile.frontend
|
|
image: atb-frontend:1.0.0
|
|
container_name: atb-prod-frontend
|
|
restart: unless-stopped
|
|
ports:
|
|
- "${PORTAL_PORT:-80}:80"
|
|
depends_on:
|
|
backend:
|
|
condition: service_healthy
|
|
networks:
|
|
- atb-internal-net
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget --quiet --tries=1 --spider http://127.0.0.1/healthz || exit 1"]
|
|
interval: 15s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 256M
|
|
|
|
networks:
|
|
atb-internal-net:
|
|
driver: bridge
|
|
|
|
volumes:
|
|
postgres_prod_data:
|
|
valkey_prod_data:
|
|
|