version: '3.8'

# Единый docker-compose для всех приложений в одном образе
# Использует корневой .env файл

services:
  # База данных PostgreSQL
  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"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-playeng}"]
      interval: 10s
      timeout: 5s
      retries: 5
    env_file:
      - .env

  # Backend сервер (Go)
  backend:
    build:
      context: .
      dockerfile: ./play-life-backend/Dockerfile
    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:
      - ./play-life-backend/migrations:/migrations
      - ./uploads:/app/uploads
    env_file:
      - .env

  # Frontend приложение play-life-web
  play-life-web:
    build:
      context: ./play-life-web
      dockerfile: Dockerfile
    container_name: play-life-web
    ports:
      - "${WEB_PORT:-3001}:80"
    restart: unless-stopped
    depends_on:
      - backend
    env_file:
      - .env

volumes:
  postgres_data:
    name: play-life_postgres_data

networks:
  default:
    name: play-life-network

