Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
126 lines (112 loc) · 4.91 KB
/
Copy pathdocker-compose.yml
File metadata and controls
126 lines (112 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# docker-compose.yml — Ambiente de desenvolvimento/teste do AI Provider Pool.
#
# Traz PostgreSQL + app + (opcional) KEK dev com `docker compose up`.
# Migrations + admin bootstrap são automáticos no startup do app em DEV_MODE.
#
# === Uso rápido ===
#
# cp .env.docker.example .env.docker
# # (opcional) ./scripts/gen-kek.sh # gera KEK dev
# docker compose --env-file .env.docker up --build
#
# Acesso: http://localhost:8088
# Login: $AIPP_BOOTSTRAP_ADMIN_USERNAME / $AIPP_BOOTSTRAP_ADMIN_PASSWORD
# (defaults: admin / ChangeMeNow!StrongDevPassword123)
#
# Substituir no .env.docker em qualquer uso além do primeiro teste local.
#
# === Healthcheck da app ===
# A imagem final é distroless/base-debian12 (sem shell, sem wget/curl).
# Por isso NÃO há `healthcheck:` na app neste compose. Verificação manual:
# curl http://localhost:8088/healthz → 200 {"status":"ok"}
# curl http://localhost:8088/readyz → 200 {"status":"ready",...}
# Em produção, o Helm chart define probes (liveness/readiness/startup).
#
# Para um quick check de "app subiu", observe os logs do container `app-1`:
# docker compose logs -f app | grep "http server listening"
services:
postgres:
image: postgres:16-alpine
# Tag pinada por major (16) — patches automáticos. Para pin total,
# use postgres:16.4-alpine@sha256:... (recomendado em prod).
container_name: ai-pool-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-aipp}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-aipp}
POSTGRES_DB: ${POSTGRES_DB:-aipp}
# Ajusta o locale/encoding (default já é UTF8, mas explícito é melhor).
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C.UTF-8"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
# pg_isready aguarda o Postgres aceitar conexões.
# $$ escapa para o compose não interpolar; postgres precisa do literal.
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 10
start_period: 5s
# Sem `ports:` — o PostgreSQL só é acessível pela rede interna do compose
# (o service `app` conecta via host "postgres"). Nenhuma porta exposta no host.
app:
build:
context: .
dockerfile: Dockerfile
image: ai-provider-pool:dev
container_name: ai-pool-app
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
# === HTTP ===
HTTP_ADDR: ":8080"
HTTP_READ_HEADER_TIMEOUT: "10s"
# === Database ===
# Hostname "postgres" resolve para o service acima.
DATABASE_URL: "postgres://${POSTGRES_USER:-aipp}:${POSTGRES_PASSWORD:-aipp}@postgres:5432/${POSTGRES_DB:-aipp}?sslmode=disable"
DB_MAX_CONNS: "10"
DB_MIN_CONNS: "2"
# === DEV mode: ativa migrations automáticas + bootstrap admin + SSRF http ===
DEV_MODE: "true"
SSRF_ALLOW_HTTP: "true"
# === Observabilidade ===
LOG_LEVEL: "${LOG_LEVEL:-info}"
LOG_FORMAT: "${LOG_FORMAT:-text}"
# === Segredos DEV ===
# Pepper para HMAC dos tokens sk-... (32+ bytes).
# VALOR EXEMPLO — INSEGURO PARA PROD. Substitua no .env.docker.
AIPP_TOKEN_PEPPER: "${AIPP_TOKEN_PEPPER:-DEV_MODE_INSECURE_PEPPER_32_BYTES_LONG_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}"
# KEK_PATH: se vazio, app usa IdentityDecryptor (plaintext no DB).
# Para usar AES-GCM: ./scripts/gen-kek.sh e descomente o volume abaixo.
KEK_PATH: "${KEK_PATH:-}"
# === Bootstrap admin (idempotente no startup em DEV_MODE) ===
AIPP_BOOTSTRAP_ADMIN_USERNAME: "${AIPP_BOOTSTRAP_ADMIN_USERNAME:-admin}"
# Mínimo 12 caracteres (validação no app).
AIPP_BOOTSTRAP_ADMIN_PASSWORD: "${AIPP_BOOTSTRAP_ADMIN_PASSWORD:-ChangeMeNow!StrongDevPassword123}"
# === Defaults de afinidade/rate-limit (pode sobrescrever via env) ===
AFFINITY_TTL: "30m"
AFFINITY_MAX_PER_USER: "50"
RATE_LIMIT_BURST: "10"
RATE_LIMIT_PER_MIN: "60"
DEFAULT_ORG_ID: "1"
# URL pública usada em links de convite (fallback: Host do request).
AIPP_PUBLIC_URL: "${AIPP_PUBLIC_URL:-http://localhost:8088}"
ENABLE_METRICS: "false"
ports:
- "${APP_PORT:-8088}:8080"
# === Volume opcional: KEK dev (gerado por ./scripts/gen-kek.sh) ===
# Para habilitar AES-GCM envelope encryption em dev, descomente o bloco
# `volumes:` abaixo. Antes: rode ./scripts/gen-kek.sh e sete KEK_PATH=/run/secrets/kek
# no .env.docker.
#
# volumes:
# - ./kek-dev.key:/run/secrets/kek:ro
# Sem healthcheck da app (distroless sem shell). Ver nota no topo do arquivo.
# depends_on postgres healthy garante DB pronto antes do app iniciar.
volumes:
pgdata:
name: ai-pool-pgdata
# Volume nomeado persiste o /var/lib/postgresql/data entre `docker compose down/up`.
# Para resetar completamente (apagar dados): `docker compose down -v`.