Files
mtusi2026lab3/docker-compose.yml
2026-10-17 08:59:12 +03:00

172 lines
4.2 KiB
YAML

services:
db:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB_FILE: /run/secrets/postgres_db
POSTGRES_USER_FILE: /run/secrets/postgres_user
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
secrets:
- postgres_db
- postgres_user
- postgres_password
networks:
- messenger-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$(cat /run/secrets/postgres_user) -d $$(cat /run/secrets/postgres_db)"]
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
redis:
image: redis:7.4-alpine
restart: unless-stopped
command: >
redis-server
--appendonly yes
--appendfsync everysec
--save ""
volumes:
- redisdata:/data
networks:
- messenger-net
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
migrate:
build:
context: .
dockerfile: Dockerfile
entrypoint: ["sh", "-c"]
command:
- "exec java -Dfile.encoding=UTF-8 -Dspring.main.web-application-type=none -jar app.jar"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
SPRING_DATASOURCE_USERNAME_FILE: /run/secrets/postgres_user
SPRING_DATASOURCE_PASSWORD_FILE: /run/secrets/postgres_password
SPRING_FLYWAY_ENABLED: "true"
secrets:
- postgres_user
- postgres_password
depends_on:
db:
condition: service_healthy
restart: "no"
networks:
- messenger-net
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 128M
api:
stop_grace_period: 40s
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
entrypoint:
- "sh"
- "-c"
- "export INSTANCE_ID=\"$$(cat /etc/hostname)\"; exec java -Dfile.encoding=UTF-8 $$JAVA_OPTS -jar app.jar"
environment:
RATE_PER_MINUTE: ${RATE_PER_MINUTE:-100000}
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
SPRING_DATASOURCE_USERNAME_FILE: /run/secrets/postgres_user
SPRING_DATASOURCE_PASSWORD_FILE: /run/secrets/postgres_password
SPRING_PROFILES_ACTIVE: ${APP_ENV:-lab}
SPRING_FLYWAY_ENABLED: "false"
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-400}
SESSION_STORE: ${SESSION_STORE:-postgres}
SPRING_DATA_REDIS_HOST: redis
SPRING_DATA_REDIS_PORT: 6379
MAX_MESSAGES_PER_CHAT: ${MAX_MESSAGES_PER_CHAT:-10000}
secrets:
- postgres_user
- postgres_password
networks:
- messenger-net
deploy:
replicas: 2
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/health/ready | grep -q '\"status\":\"ok\"'"]
interval: 5s
timeout: 3s
retries: 20
start_period: 40s
lb:
image: nginx:1.27-alpine
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api:
condition: service_healthy
networks:
- messenger-net
deploy:
resources:
limits:
cpus: '0.5'
memory: 128M
reservations:
cpus: '0.1'
memory: 32M
volumes:
pgdata:
redisdata:
networks:
messenger-net:
driver: bridge
secrets:
postgres_db:
file: ./secrets/postgres_db.txt
postgres_user:
file: ./secrets/postgres_user.txt
postgres_password:
file: ./secrets/postgres_password.txt