version: '3.8'

services:
  db:
    image: postgres:15-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${DB_USER:-playeng}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-playeng}
      POSTGRES_DB: ${DB_NAME:-playeng}
    ports:
      - "${DB_PORT:-5432}:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-playeng}"]
      interval: 10s
      timeout: 5s
      retries: 5
    env_file:
      - ../.env
      - .env  # Локальный .env имеет приоритет

  backend:
    build: .
    ports:
      - "${PORT:-8080}:8080"
    environment:
      DB_HOST: db
      DB_PORT: 5432
      DB_USER: ${DB_USER:-playeng}
      DB_PASSWORD: ${DB_PASSWORD:-playeng}
      DB_NAME: ${DB_NAME:-playeng}
      PORT: ${PORT:-8080}
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./migrations:/migrations
    env_file:
      - ../.env
      - .env  # Локальный .env имеет приоритет

