# documentation: https://docs.newapi.pro/en/getting-started/
# slogan: The next-generation LLM gateway and AI asset management system supports multiple languages.
# category: api
# tags: api, openai, llm, api-gateway, api-management
# logo: svgs/newapi.png
# port: 3000

services:
  new-api:
    image: calciumion/new-api:v0.9.2.0
    depends_on:
      postgresql:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - SERVICE_URL_NEW_API_3000
      - SQL_DSN=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgresql:5432/${POSTGRES_DATABASE:-newapi}?sslmode=disable&TimeZone=${TZ:-Asia/Shanghai}
      - REDIS_CONN_STRING=redis://redis:6379
      - TZ=${TZ:-Asia/Shanghai}
      - SESSION_SECRET=$SERVICE_BASE64_64_SESSION_SECRET
      - ERROR_LOG_ENABLED=${ERROR_LOG_ENABLED:-true}
    healthcheck:
      test:
        - CMD-SHELL
        - "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' | awk -F: '{print $2}'"
      interval: 30s
      timeout: 10s
      retries: 3
  postgresql:
    image: postgres:16-alpine
    environment:
      - POSTGRES_USER=$SERVICE_USER_POSTGRES
      - POSTGRES_PASSWORD=$SERVICE_PASSWORD_POSTGRES
      - POSTGRES_DB=${POSTGRES_DATABASE:-newapi}
    volumes:
      - postgresql-data:/var/lib/postgresql/data
    healthcheck:
      test:
        - CMD-SHELL
        - "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB:-newapi}"
      interval: 5s
      timeout: 10s
      retries: 20
  redis:
    image: redis:7-alpine
    volumes:
      - redis-data:/data
    healthcheck:
      test:
        - CMD
        - redis-cli
        - PING
      interval: 5s
      timeout: 10s
      retries: 20
