version: '3.8'

services:
  user-postgres:
    image: docker.io/library/postgres:15-alpine
    container_name: user-postgres
    environment:
      POSTGRES_DB: users
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5433:5432"
    volumes:
      - user_postgres_data:/var/lib/postgresql/data
      - ./migrations:/docker-entrypoint-initdb.d:Z
    networks:
      - user-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d users"]
      interval: 10s
      timeout: 5s
      retries: 5

  user-service:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: user-service
    depends_on:
      user-postgres:
        condition: service_healthy
    environment:
      DB_HOST: user-postgres
      DB_PORT: 5432
      DB_NAME: users
      DB_USER: postgres
      DB_PASSWORD: postgres
      DB_SSLMODE: disable
      SERVER_HOST: 0.0.0.0
      SERVER_PORT: 8090
      APP_ENV: development
      LOG_LEVEL: debug
      AUTH_PROVIDER: header
      AUTH_HEADER_USER_EMAIL: X-User-Email
    ports:
      - "8090:8090"
    networks:
      - user-network
    # healthcheck:
    #   test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8090/health"]
    #   interval: 30s
    #   timeout: 5s
    #   retries: 3
    restart: unless-stopped

networks:
  user-network:

volumes:
  user_postgres_data:
