version: "3.7"
services:
  monica:
    image: monica:4.0.0
    container_name: monica
    depends_on:
      - monica-db
    ports:
      - ${APP_PORT}:80
    environment:
      - APP_KEY=${MONICA_APP_KEY}
      - DB_HOST=monica-db
      - DB_USERNAME=usermonica
      - DB_PASSWORD=${MONICA_DB_PASS}
    volumes:
      - ${APP_DATA_DIR}/data:/var/www/html/storage
    restart: unless-stopped
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.monica-web-redirect.redirectscheme.scheme: https
      traefik.http.services.monica.loadbalancer.server.port: 80
      # Web
      traefik.http.routers.monica-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.monica-insecure.entrypoints: web
      traefik.http.routers.monica-insecure.service: monica
      traefik.http.routers.monica-insecure.middlewares: monica-web-redirect
      # Websecure
      traefik.http.routers.monica.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.monica.entrypoints: websecure
      traefik.http.routers.monica.service: monica
      traefik.http.routers.monica.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.monica-local-insecure.rule: Host(`monica.${LOCAL_DOMAIN}`)
      traefik.http.routers.monica-local-insecure.entrypoints: web
      traefik.http.routers.monica-local-insecure.service: monica
      traefik.http.routers.monica-local-insecure.middlewares: monica-web-redirect
      # Local domain secure
      traefik.http.routers.monica-local.rule: Host(`monica.${LOCAL_DOMAIN}`)
      traefik.http.routers.monica-local.entrypoints: websecure
      traefik.http.routers.monica-local.service: monica
      traefik.http.routers.monica-local.tls: true

  monica-db:
    image: mariadb:10.6.11
    container_name: monica-db
    environment:
      - TZ=${TZ}
      - MARIADB_RANDOM_ROOT_PASSWORD=true
      - MARIADB_DATABASE=monica
      - MARIADB_USER=usermonica
      - MARIADB_PASSWORD=${MONICA_DB_PASS}
    volumes:
      - ${APP_DATA_DIR}/mysql:/var/lib/mysql
    restart: unless-stopped
    networks:
      - tipi_main_network
