212 lines
5.4 KiB
YAML
212 lines
5.4 KiB
YAML
services:
|
|
postgres:
|
|
image: postgres:16.8-alpine
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'pg_isready -U messenger -d messenger']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${POSTGRES_CPU_LIMIT:-1.0}'
|
|
memory: '${POSTGRES_MEMORY_LIMIT:-1G}'
|
|
|
|
redis:
|
|
image: redis:7.4.2-alpine
|
|
command: ['redis-server', '--appendonly', 'yes', '--appendfsync', 'everysec']
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ['CMD', 'redis-cli', 'ping']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${REDIS_CPU_LIMIT:-0.5}'
|
|
memory: '${REDIS_MEMORY_LIMIT:-256M}'
|
|
|
|
minio:
|
|
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
entrypoint: ['/bin/sh', '/infra/minio-entrypoint.sh']
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
volumes:
|
|
- minio_data:/data
|
|
- ./infra/minio-entrypoint.sh:/infra/minio-entrypoint.sh:ro
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'curl -fsS http://127.0.0.1:9000/minio/health/ready >/dev/null']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${MINIO_CPU_LIMIT:-1.0}'
|
|
memory: '${MINIO_MEMORY_LIMIT:-1G}'
|
|
|
|
minio-bootstrap:
|
|
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
entrypoint: ['/bin/sh', '/infra/minio-bootstrap.sh']
|
|
environment:
|
|
S3_BUCKET: messenger-attachments
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
volumes:
|
|
- ./infra/minio-bootstrap.sh:/infra/minio-bootstrap.sh:ro
|
|
- ./infra/s3-policy.json:/infra/s3-policy.json:ro
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
restart: 'no'
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${BOOTSTRAP_CPU_LIMIT:-0.25}'
|
|
memory: '${BOOTSTRAP_MEMORY_LIMIT:-128M}'
|
|
|
|
migrate:
|
|
build: .
|
|
command: ['python', 'scripts/migrate.py']
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: 'no'
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${MIGRATE_CPU_LIMIT:-0.5}'
|
|
memory: '${MIGRATE_MEMORY_LIMIT:-256M}'
|
|
|
|
api:
|
|
build: .
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_STORE: redis
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL: redis://redis:6379/0
|
|
S3_ENDPOINT: http://minio:9000
|
|
S3_REGION: ${S3_REGION:-us-east-1}
|
|
S3_BUCKET: messenger-attachments
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
|
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
|
MAX_CONCURRENT_UPLOADS: ${MAX_CONCURRENT_UPLOADS:-16}
|
|
secrets:
|
|
- database_url
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-bootstrap:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test:
|
|
[
|
|
'CMD',
|
|
'python',
|
|
'-c',
|
|
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)",
|
|
]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 10s
|
|
stop_grace_period: 15s
|
|
restart: unless-stopped
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: '${API_CPU_LIMIT:-1.0}'
|
|
memory: '${API_MEMORY_LIMIT:-512M}'
|
|
|
|
nginx:
|
|
image: nginx:1.27.5-alpine
|
|
ports:
|
|
- '${APP_PORT:-8080}:8080'
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
networks:
|
|
- frontend
|
|
- backend
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${NGINX_CPU_LIMIT:-0.5}'
|
|
memory: '${NGINX_MEMORY_LIMIT:-256M}'
|
|
|
|
networks:
|
|
frontend:
|
|
backend:
|
|
internal: true
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
minio_data:
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
minio_root_user:
|
|
file: ./secrets/minio_root_user
|
|
minio_root_password:
|
|
file: ./secrets/minio_root_password
|
|
s3_access_key_id:
|
|
file: ./secrets/s3_access_key_id
|
|
s3_secret_access_key:
|
|
file: ./secrets/s3_secret_access_key
|