version: '3.7'
services:
  vikunja-db:
    container_name: vikunja-db
    image: postgres:14
    environment:
      POSTGRES_PASSWORD: ${VIKUNJA_DB_PASSWORD}
      POSTGRES_USER: tipi
      POSTGRES_DB: vikunja
    volumes:
      - ${APP_DATA_DIR}/data/db:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB']
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - tipi_main_network
  vikunja-api:
    container_name: vikunja-api
    image: vikunja/api:0.22.0
    environment:
      VIKUNJA_DATABASE_HOST: vikunja-db
      VIKUNJA_DATABASE_PASSWORD: ${VIKUNJA_DB_PASSWORD}
      VIKUNJA_DATABASE_TYPE: postgres
      VIKUNJA_DATABASE_USER: tipi
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_SERVICE_JWTSECRET: ${VIKUNJA_SERVICE_SECRET}
      VIKUNJA_SERVICE_FRONTENDURL: ${APP_PROTOCOL:-http}://${APP_DOMAIN}/
    volumes:
      - ${APP_DATA_DIR}/data/files:/app/vikunja/files
    restart: unless-stopped
    depends_on:
      vikunja-db:
        condition: service_healthy
    networks:
      - tipi_main_network
  vikunja:
    image: vikunja/frontend:0.22.0
    restart: unless-stopped
    container_name: vikunja
    networks:
      - tipi_main_network
  vikunja-proxy:
    image: nginx
    container_name: vikunja-proxy
    ports:
      - ${APP_PORT}:80
    volumes:
      - ${APP_DATA_DIR}/data/proxy/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - vikunja-api
      - vikunja
    restart: unless-stopped
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.vikunja-web-redirect.redirectscheme.scheme: https
      traefik.http.services.vikunja.loadbalancer.server.port: 80
      # Web
      traefik.http.routers.vikunja-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.vikunja-insecure.entrypoints: web
      traefik.http.routers.vikunja-insecure.service: vikunja
      traefik.http.routers.vikunja-insecure.middlewares: vikunja-web-redirect
      # Websecure
      traefik.http.routers.vikunja.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.vikunja.entrypoints: websecure
      traefik.http.routers.vikunja.service: vikunja
      traefik.http.routers.vikunja.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.vikunja-local-insecure.rule: Host(`vikunja.${LOCAL_DOMAIN}`)
      traefik.http.routers.vikunja-local-insecure.entrypoints: web
      traefik.http.routers.vikunja-local-insecure.service: vikunja
      traefik.http.routers.vikunja-local-insecure.middlewares: vikunja-web-redirect
      # Local domain secure
      traefik.http.routers.vikunja-local.rule: Host(`vikunja.${LOCAL_DOMAIN}`)
      traefik.http.routers.vikunja-local.entrypoints: websecure
      traefik.http.routers.vikunja-local.service: vikunja
      traefik.http.routers.vikunja-local.tls: true
