services:
  postgres:
    image: postgres:17-alpine
    restart: unless-stopped
    env_file: [.env.production]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
      interval: 5s
      timeout: 5s
      retries: 20
    volumes:
      - kiln_postgres:/var/lib/postgresql/data
    networks: [internal]

  app:
    build:
      context: .
      args:
        NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-https://kiln.spb.ru}
        NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.npmmirror.com}
    restart: unless-stopped
    env_file: [.env.production]
    ports:
      - "127.0.0.1:3100:3000"
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - /var/www/html/kiln/uploads:/app/public/uploads
    networks: [internal, bot_api]

volumes:
  kiln_postgres:

networks:
  internal:
    name: kiln_internal
  bot_api:
    name: kiln_bot_api
    internal: true
