Files
mtusi2026lab3/docker-compose.yaml

106 lines
2.1 KiB
YAML

services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: app
POSTGRES_DB: app
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app -d app"]
interval: 5s
timeout: 3s
retries: 5
networks:
- lab3net
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
api1:
build:
context: .
dockerfile: Dockerfile
environment:
APP_INSTANCE_ID: api1
APP_PORT: "8080"
DATABASE_URL: postgres://app:app@postgres:5432/app?sslmode=disable
expose:
- "8080"
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
stop_grace_period: 15s
networks:
- lab3net
deploy:
resources:
limits:
cpus: "1.0"
memory: 256M
api2:
build:
context: .
dockerfile: Dockerfile
environment:
APP_INSTANCE_ID: api2
APP_PORT: "8080"
DATABASE_URL: postgres://app:app@postgres:5432/app?sslmode=disable
expose:
- "8080"
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
stop_grace_period: 15s
networks:
- lab3net
deploy:
resources:
limits:
cpus: "1.0"
memory: 256M
haproxy:
image: haproxy:2.9-alpine
ports:
- "8080:8080"
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api1:
condition: service_healthy
api2:
condition: service_healthy
networks:
- lab3net
deploy:
resources:
limits:
cpus: "0.5"
memory: 128M
networks:
lab3net:
driver: bridge
volumes:
pgdata: