services:
  db:
    image: postgres:17
    container_name: db
    restart: unless-stopped
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    volumes:
      - ./data/db:/var/lib/postgresql/data
    networks:
      - proxy
    env_file:
      - ./.env
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  api:
    build: .
    container_name: api
    restart: unless-stopped
    command: bash -c "uvicorn library_service.main:app --host 0.0.0.0 --port 8000 --forwarded-allow-ips=*"
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    networks:
      - proxy
    ports:
      - 8000:8000
    env_file:
      - ./.env
    volumes:
      - .:/code
    depends_on:
      db:
        condition: service_healthy

  tests:
    container_name: tests
    build: .
    command: bash -c "pytest tests"
    restart: no
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    networks:
      - proxy
    env_file:
      - ./.env
    volumes:
      - .:/code
    depends_on:
        db:
          condition: service_healthy

networks:
  proxy: # Рекомендуется использовать через реверс-прокси
    name: proxy
    external: true
