services:

  caddy-main:
    image: caddy:alpine
    container_name: caddy-main
    restart: always
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
    ports:
      - "443:443"
      - "80:80"
    depends_on:
      - nise-nginx

  # Shared services which are used by others
  redis:
    image: redis:alpine
    container_name: redis
    restart: always

  postgres:
    image: postgres:alpine
    container_name: postgres
    restart: always
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASS}
    volumes:
      - postgres-data:/var/lib/postgresql/data

 # ------------------------------------------------------------------

  nise-nginx:
    image: nginx:latest
    container_name: nise-nginx
    restart: always
    volumes:
      - ./nise-data/nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - nise-backend
      - nise-frontend

  nise-circleguard:
    image: code.stedos.dev/stedos/nise-circleguard:latest
    container_name: nise-circleguard
    environment:
      OSU_API_KEY: ${OSU_API_KEY}
    restart: always
    volumes:
      - ./nise-data/beatmaps:/app/dbs

  nise-backend:
    image: code.stedos.dev/stedos/nise-backend:latest
    container_name: nise-backend
    environment:
      SPRING_PROFILES_ACTIVE: postgres,import:scores,import:users,fix:scores
      # App configuration
      OLD_SCORES_PAGE_SIZE: 1000
      # Postgres
      POSTGRES_HOST: ${DB_HOST}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASS: ${DB_PASS}
      POSTGRES_DB: ${DB_NAME}
      # redis
      REDIS_DB: 4
      # Discord
      WEBHOOK_URL: ${WEBHOOK_URL}
      SCORES_WEBHOOK_URL: ${SCORES_WEBHOOK_URL}
      # osu!api
      OSU_API_KEY: ${OSU_API_KEY}
      OSU_CLIENT_ID: ${OSU_CLIENT_ID}
      OSU_CLIENT_SECRET: ${OSU_CLIENT_SECRET}
      OSU_CALLBACK: "https://nise.stedos.dev/api/login/oauth2/code/osu"
      # Metabase
      METABASE_API_KEY: ${METABASE_API_KEY}
      # Internal API
      CIRCLEGUARD_API_URL: http://nise-circleguard:5000
      # Auth
      ORIGIN: "https://nise.stedos.dev"
      REPLAY_ORIGIN: "https://replay.nise.moe"
      COOKIE_SECURE: false
      BEATMAPS_PATH: "/app/dbs"
      # Replay cache
      REPLAY_CACHE_ENABLED: ${REPLAY_CACHE_ENABLED}
      REPLAY_CACHE_HOST: ${REPLAY_CACHE_HOST}
      REPLAY_CACHE_PORT: ${REPLAY_CACHE_PORT}
      REPLAY_CACHE_DB: ${REPLAY_CACHE_DB}
      REPLAY_CACHE_USER: ${REPLAY_CACHE_USER}
      REPLAY_CACHE_PASS: ${REPLAY_CACHE_PASS}
    restart: always
    volumes:
        - ./nise-data/beatmaps:/app/dbs
    depends_on:
      - postgres
      - redis
      - nise-circleguard

  nise-frontend:
    image: code.stedos.dev/stedos/nise-frontend:latest
    container_name: nise-frontend
    restart: always

  nise-replay-viewer:
    image: code.stedos.dev/stedos/nise-replay-viewer:latest
    container_name: nise-replay-viewer
    restart: always

volumes:
  postgres-data:
