Files
mtusi2026lab2/docker-compose.yaml
T
2026-10-08 13:08:31 +03:00

93 lines
2.3 KiB
YAML

services:
db:
image: postgres:16-alpine
container_name: messenger-db
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
redis:
image: redis:7.4-alpine
container_name: messenger-redis
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
api:
build:
context: .
dockerfile: Dockerfile
container_name: messenger-api
restart: unless-stopped
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
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_PROFILES_ACTIVE: ${APP_ENV:-lab}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-400}
SESSION_STORE: ${SESSION_STORE:-postgres}
SPRING_DATA_REDIS_HOST: redis
SPRING_DATA_REDIS_PORT: 6379
ports:
- "127.0.0.1:8080:8080"
secrets:
- postgres_user
- postgres_password
networks:
- messenger-net
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
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