---
version: "{{ skylab_compose_version }}"


networks:
  vikunja:
    name: vikunja
    driver: overlay
    ipam:
      driver: default
      config:
        - subnet: {{ app.networks.ext }}


volumes:
{% for key, value in app.volumes.items() %}
  vikunja-{{ key }}:
    name: datastore{{ value }}
    driver: glusterfs
{% endfor %}


services:
  database:
    image: mariadb:{{ app.versions.database }}
    hostname: database
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - vikunja
    volumes:
      - type: volume
        source: vikunja-database
        target: /var/lib/mysql
        read_only: false
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "true"
      MYSQL_USER: vikunja
      MYSQL_PASSWORD: {{ app.settings.database_password }}
      MYSQL_DATABASE: vikunja
    deploy:
      replicas: 1

  cache:
    image: redis:{{ app.versions.cache }}
    hostname: cache
    networks:
      - vikunja
    deploy:
      replicas: 1

  proxy:
    image: nginx:{{ app.versions.proxy }}
    hostname: proxy
    networks:
      - vikunja
    ports:
      - published: {{ app.ports.80 }}
        target: 80
        protocol: tcp
        mode: ingress
    volumes:
      - type: volume
        source: vikunja-nginx
        target: /etc/nginx/conf.d
        read_only: true
    deploy:
      replicas: 1

  api:
    image: vikunja/api:{{ app.versions.api }}
    hostname: api
    networks:
      - vikunja
    depends_on:
      - database
      - cache
    volumes:
      - type: volume
        source: vikunja-files
        target: /app/vikunja/files
        read_only: false
    environment:
      VIKUNJA_DATABASE_HOST: database
      VIKUNJA_DATABASE_PASSWORD: {{ app.settings.database_password }}
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_REDIS_ENABLED: "1"
      VIKUNJA_REDIS_HOST: cache:6379
      VIKUNJA_CACHE_ENABLED: "1"
      VIKUNJA_CACHE_TYPE: redis
      VIKUNJA_FILES_MAXSIZE: 50MB
    deploy:
      replicas: 1

  web:
    image: vikunja/frontend:{{ app.versions.web }}
    hostname: web
    networks:
      - vikunja
    depends_on:
      - database
      - cache
      - proxy
    environment:
      VIKUNJA_API_URL: https://{{ app.publish.domain }}/api/v1
    deploy:
      replicas: 1
