Files
mtusi2026lab2/compose.yaml
T
2026-10-21 11:48:36 +03:00

110 lines
3.1 KiB
YAML

name: messenger-lab2
services:
secrets-init:
image: alpine:3.20.3
volumes:
- secrets:/secrets
command:
- sh
- -ec
- |
cd /secrets
[ -s pg_password ] || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > pg_password
printf 'postgresql://messenger:%s@postgres:5432/messenger?connection_limit=10&pool_timeout=5&connect_timeout=5&socket_timeout=10&application_name=api&options=-c%%20statement_timeout%%3D5000' "$$(cat pg_password)" > database_url
[ -s redis_password ] || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > redis_password
printf 'redis://:%s@redis:6379/0' "$$(cat redis_password)" > cache_url
chmod 0444 pg_password database_url redis_password cache_url
postgres:
image: postgres:17.2-alpine
environment:
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
volumes:
- pgdata:/var/lib/postgresql/data
- secrets:/run/secrets:ro
healthcheck:
test: ["CMD", "pg_isready", "-U", "messenger", "-d", "messenger"]
interval: 5s
timeout: 3s
retries: 10
depends_on:
secrets-init:
condition: service_completed_successfully
restart: unless-stopped
redis:
image: redis:7.4.1-alpine
user: redis
command:
- sh
- -c
- exec redis-server --save '' --appendonly no --maxmemory 64mb --maxmemory-policy allkeys-lru --requirepass "$$(cat /run/secrets/redis_password)"
volumes:
- secrets:/run/secrets:ro
healthcheck:
test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$(cat /run/secrets/redis_password)\" ping | grep -q PONG"]
interval: 5s
timeout: 3s
retries: 10
depends_on:
secrets-init:
condition: service_completed_successfully
restart: unless-stopped
migrate:
build:
context: .
target: migrate
image: mtusi-messenger-lab2-migrate:dev
environment:
DATABASE_URL_FILE: /run/secrets/database_url
volumes:
- secrets:/run/secrets:ro
depends_on:
postgres:
condition: service_healthy
api:
build:
context: .
target: runtime
image: mtusi-messenger-lab2-api:dev
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
APP_ENV: ${APP_ENV:-lab}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
- secrets:/run/secrets:ro
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_started
restart: unless-stopped
tools:
profiles: [tools]
build:
dockerfile_inline: |
FROM docker:27.3.1-cli
RUN apk add --no-cache python3 make git && git config --global --add safe.directory /work
WORKDIR /work
image: mtusi-messenger-lab2-tools:dev
environment:
BASE_URL: http://api:8080
volumes:
- .:/work
- /var/run/docker.sock:/var/run/docker.sock
volumes:
pgdata:
secrets: