Files
2026-11-16 17:38:53 +03:00

218 lines
5.8 KiB
YAML

services:
postgres:
image: postgres:15.5-alpine3.19
environment:
POSTGRES_DB: messenger
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
volumes:
- pgdata:/var/lib/postgresql/data
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
reservations:
cpus: '0.10'
memory: 128M
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d messenger"]
interval: 3s
timeout: 3s
retries: 5
redis:
image: redis:7.2.4-alpine
command: redis-server --appendonly yes --appendfsync everysec --loglevel warning
volumes:
- redisdata:/data
deploy:
resources:
limits:
cpus: '0.25'
memory: 256M
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 3s
timeout: 3s
retries: 5
migrate:
image: postgres:15.5-alpine3.19
environment:
PGPASSWORD: ${POSTGRES_PASSWORD}
volumes:
- ./migrations:/migrations
command: >
sh -c "until pg_isready -h postgres -U postgres; do sleep 1; done;
psql -h postgres -U postgres -d messenger -f /migrations/init.sql"
depends_on:
postgres:
condition: service_healthy
restart: "no"
s3:
image: chrislusf/seaweedfs:latest
command: ["server", "-s3", "-dir=/data", "-s3.port=8333"]
environment:
- AWS_ACCESS_KEY_ID=appuser
- AWS_SECRET_ACCESS_KEY=appsecretpassword
volumes:
- s3data:/data
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8333/healthz || exit 1"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
s3-init:
image: python:3.11.7-slim-bookworm
volumes:
- ./scripts:/scripts
- ./requirements.txt:/requirements.txt
environment:
- S3_ENDPOINT=http://s3:8333
- S3_BUCKET=messenger-attachments
- S3_ROOT_ACCESS_KEY=appuser
- S3_ROOT_SECRET_KEY=appsecretpassword
command: >
sh -c "pip install --no-cache-dir -r /requirements.txt &&
python /scripts/bootstrap_s3.py"
depends_on:
s3:
condition: service_healthy
restart: "no"
api-1:
build: .
stop_grace_period: 15s
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/messenger
- REDIS_URL=redis://redis:6379/0
- SESSION_TTL_SECONDS=3600
- INSTANCE_ID=api-replica-1
- SECRET_HMAC_KEY=${SECRET_HMAC_KEY}
- S3_ENDPOINT=http://s3:8333
- S3_BUCKET=messenger-attachments
- S3_ACCESS_KEY_ID=appuser
- S3_SECRET_ACCESS_KEY=appsecretpassword
- BROKER_STREAM=attachment_jobs
deploy:
resources:
limits:
cpus: '0.50'
memory: 256M
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready')"]
interval: 5s
timeout: 3s
retries: 3
api-2:
build: .
stop_grace_period: 15s
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/messenger
- REDIS_URL=redis://redis:6379/0
- SESSION_TTL_SECONDS=3600
- INSTANCE_ID=api-replica-2
- SECRET_HMAC_KEY=${SECRET_HMAC_KEY}
- S3_ENDPOINT=http://s3:8333
- S3_BUCKET=messenger-attachments
- S3_ACCESS_KEY_ID=appuser
- S3_SECRET_ACCESS_KEY=appsecretpassword
- BROKER_STREAM=attachment_jobs
deploy:
resources:
limits:
cpus: '0.50'
memory: 256M
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready')"]
interval: 5s
timeout: 3s
retries: 3
worker:
build: .
command: ["python", "worker.py"]
stop_grace_period: 15s
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/messenger
- REDIS_URL=redis://redis:6379/0
- S3_ENDPOINT=http://s3:8333
- S3_BUCKET=messenger-attachments
- S3_ACCESS_KEY_ID=appuser
- S3_SECRET_ACCESS_KEY=appsecretpassword
- BROKER_STREAM=attachment_jobs
- BROKER_GROUP=attachment_workers
- JOB_MAX_ATTEMPTS=5
- MAX_IMAGE_PIXELS=40000000
deploy:
resources:
limits:
cpus: '0.50'
memory: 256M
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import os, redis; redis.Redis.from_url(os.environ['REDIS_URL']).ping()"]
interval: 5s
timeout: 3s
retries: 3
nginx:
image: nginx:1.25.4-alpine
ports:
- "8080:8080"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
deploy:
resources:
limits:
cpus: '0.25'
memory: 128M
depends_on:
- api-1
- api-2
healthcheck:
test: ["CMD", "nginx", "-t"]
interval: 5s
timeout: 3s
retries: 3
volumes:
pgdata:
redisdata:
s3data: