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 chmod 0444 pg_password database_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 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 ports: - "127.0.0.1:${APP_PORT:-8080}:8080" volumes: - secrets:/run/secrets:ro depends_on: migrate: condition: service_completed_successfully restart: unless-stopped tools: profiles: [tools] build: dockerfile_inline: | FROM docker:27.3.1-cli RUN apk add --no-cache python3 make 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: