# SPDX-FileCopyrightText: 2023 Marlon W (Mawoka)
#
# SPDX-License-Identifier: MPL-2.0

version: "3"

services:
  frontend:
    restart: always
    build:
      context: ./frontend
      dockerfile: Dockerfile
    depends_on:
      - redis
      - api
    environment:
      REDIS_URL: redis://redis:6379/0?decode_responses=True
      API_URL: http://api:80
  api:
    build: &build_cfg
      context: .
      dockerfile: Dockerfile
    restart: &restart always
    depends_on: &depends
      - db
      - redis

    environment: &env_vars
      # --- DON'T CHANGE FROM HERE ---
      DB_URL: "postgresql://postgres:classquiz@db:5432/classquiz" # DON'T CHANGE
      REDIS: "redis://redis:6379/0?decode_responses=True" # DON'T CHANGE
      SECRET_KEY: "TOP_SECRET" # Don't change it manually, use the one-liner provided in the documentation
      MAX_WORKERS: "1" # Very important and DON'T CHANGE
      ACCESS_TOKEN_EXPIRE_MINUTES: 30  # DON'T CHANGE
      MEILISEARCH_URL: "http://meilisearch:7700" # DON'T CHANGE
      # -- DON'T CHANGE TILL HERE ---

      # --- GENERAL CONFIG ---
      ROOT_ADDRESS: "https://classquiz.de" # CHANGE IT (without a "/" at the end)

      # --- MAIL CONFIG ---
      MAIL_PORT: "587"
      MAIL_ADDRESS: "email@email@email.email"
      MAIL_PASSWORD: "PASSWORT"
      MAIL_USERNAME: "email@email@email.email"
      MAIL_SERVER: "smtp.email.email"
      SKIP_EMAIL_VERIFICATION: "True" # Does the user have to confirm its email by clicking a link?

      # --- EXTERNAL API CONFIG ---
      # HCAPTCHA_KEY: ""
      # PIXABAY_API_KEY: "" # Get it from here: https://pixabay.com/api/docs/
      # RECAPTCHA_KEY: "" Get it from Google for the Captcha.

      # -- STORAGE CONFIG ---
      STORAGE_BACKEND: "local" # Could also be s3
      STORAGE_PATH: "/app/data" # When s3 is used, this isn't needed.
      # If STORAGE_BACKEND is "s3"
      #S3_ACCESS_KEY: "YOUR_ACCESS_KEY"
      #S3_SECRET_KEY: "YOUR_SECRET_KEY"
      #S3_BASE_URL: "YOUR_S3_BASE_URL"

      # --- GOOGLE_AUTH ---
      #GOOGLE_CLIENT_ID: "" # Your Google-Client ID, or leave it unset if you don't want it.
      #GOOGLE_CLIENT_SECRET: "" # Your Google-Client Secret, or leave it unset if you don't want it.

      # --- GITHUB_AUTH ---
      #GITHUB_CLIENT_ID: "" # Your GitHub-Client ID, or leave it unset if you don't want it.
      #GITHUB_CLIENT_SECRET: "" # Your GitHub-Client Secret, or leave it unset if you don't want it.

      # --- Custom OpenID ---
      #CUSTOM_OPENID_PROVIDER__CLIENT_ID: "" # Adjust if needed
      #CUSTOM_OPENID_PROVIDER__CLIENT_SECRET: "" # Adjust if needed
      #CUSTOM_OPENID_PROVIDER__SERVER_METADATA_URL: "/.well-known/openid-configuration" # Adjust if needed

    volumes: # Only needed if you chose the "local" storage-backend
      - ./uploads:/app/data

  redis:
    image: redis:alpine
    restart: always
    healthcheck:
      test: [ "CMD", "redis-cli","ping" ]

  db:
    image: postgres:14-alpine
    restart: always
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres" ]
      interval: 5s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_PASSWORD: "classquiz"
      POSTGRES_DB: "classquiz"
    volumes:
      - data:/var/lib/postgresql/data
  proxy:
    image: caddy:alpine
    restart: always
    volumes:
      - ./Caddyfile-docker:/etc/caddy/Caddyfile
    ports:
      - "8000:8080" # The 8000 can be changed.
  meilisearch:
    image: getmeili/meilisearch:v0.28.0
    restart: always
    environment:
      MEILI_NO_ANALYTICS: "true"
    volumes:
      - meilisearch-data:/data.ms
  worker:
    build: *build_cfg
    environment: *env_vars
    depends_on: *depends
    restart: *restart
    command: arq classquiz.worker.WorkerSettings


volumes:
  data:
  meilisearch-data:
