Files
mtusi2026lab3/compose.yaml
T
2026-11-12 20:23:11 +03:00

107 lines
2.6 KiB
YAML

services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: messenger
POSTGRES_PASSWORD: lab3password
POSTGRES_DB: messenger
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger"]
interval: 5s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
expose:
- "5432"
migrate:
image: postgres:15-alpine
volumes:
- ./migrations:/migrations:ro
entrypoint: ["sh", "-c", "psql postgresql://messenger:lab3password@postgres:5432/messenger -f /migrations/001_init.sql"]
depends_on:
postgres:
condition: service_healthy
restart: "no"
api1:
build: .
env_file: .env
environment:
INSTANCE_ID: api-instance-1
DATABASE_URL: postgresql://messenger:lab3password@postgres:5432/messenger
CACHE_URL: redis://redis:6379/0
depends_on:
postgres:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request,sys; r=urllib.request.urlopen('http://localhost:8080/health/ready'); sys.exit(0 if r.status==200 else 1)"]
interval: 5s
timeout: 3s
retries: 5
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
expose:
- "8080"
api2:
build: .
env_file: .env
environment:
INSTANCE_ID: api-instance-2
DATABASE_URL: postgresql://messenger:lab3password@postgres:5432/messenger
CACHE_URL: redis://redis:6379/0
depends_on:
postgres:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request,sys; r=urllib.request.urlopen('http://localhost:8080/health/ready'); sys.exit(0 if r.status==200 else 1)"]
interval: 5s
timeout: 3s
retries: 5
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
expose:
- "8080"
nginx:
image: nginx:1.25-alpine
ports:
- "8080:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api1:
condition: service_healthy
api2:
condition: service_healthy
deploy:
resources:
limits:
cpus: '0.25'
memory: 128M
volumes:
postgres_data: