job "maps" {
  datacenters = ["alo"]

  meta {
    uuid = uuidv4()
  }

  group "qgis" {
    network {
      port "http" {
        to = 8080
      }
    }

    task "py-server" {
      driver = "docker"

      config {
        image = "3liz/qgis-map-server:3.44"
        ports = ["http"]
        volumes = [
          "/data/shared/alo_gis:/srv/projects/alo_gis",
          "/data/services/maps/qgis-server-plugins:/plugins",
        ]
      }

      env {
        QGIS_SERVER_LIZMAP_REVEAL_SETTINGS = "yes"
        QGSRV_API_ENABLED_LIZMAP = "yes"
        QGSRV_CACHE_SIZE = "20"
        QGSRV_CACHE_STRICT_CHECK = "no"
        QGSRV_CACHE_ROOTDIR = "/srv/projects"
        QGSRV_LOGGING_LEVEL = "INFO"
        QGSRV_SERVER_PLUGINPATH = "/plugins"
        QGSRV_SERVER_WORKERS = 4
        QGSRV_API_ENDPOINTS_LIZMAP = "/ows/lizmap"
        QGSRV_API_ENABLED_LANDING_PAGE = "yes"
        QGSRV_SERVER_HTTP_PROXY = "yes"
        #QGSRV_SERVER_PROXY_URL = "https://mapserver.v.paler.net"
        QGSRV_TRUST_LAYER_METADATA = "yes"
        QGSRV_DISABLE_GETPRINT = "yes"
      }

      service {
        name = "mapserver"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.mapserver.entryPoints=websecure",
          #"traefik.http.routers.mapserver.middlewares=authentik@file",
        ]
      }

      resources {
        memory = 3000
        cpu = 4000
      }
    }
  }

  group "lizmap" {
    network {
      port "http" {
        to = 80
      }
      port "php" {
        static = 9000
      }
    }

    task "php" {
      driver = "docker"

      config {
        image = "3liz/lizmap-web-client:3.9"
        ports = ["php"]
        volumes = [
          "/data/shared/alo_gis:/srv/projects/alo_gis",
          "/data/services/maps/var/lizmap-theme-config:/www/lizmap/var/lizmap-theme-config",
          "/data/services/maps/var/lizmap-config:/www/lizmap/var/config",
          "/data/services/maps/var/lizmap-db:/www/lizmap/var/db",
          "/data/services/maps/var/lizmap-log:/www/lizmap/var/log",
          "/data/services/maps/www:/www/lizmap/www",
          "/data/services/maps/var/lizmap-modules:/www/lizmap/var/lizmap-modules",
          "/data/services/maps/var/lizmap-my-packages:/www/lizmap/var/my-packages",
          "/data/services/maps/etc:/srv/etc:ro",
        ]

        command = "php-fpm"
      }

      env {
        LIZMAP_CACHEREDISDB = "1"
        LIZMAP_CACHEREDISHOST = "redis.service.consul"
        LIZMAP_CACHESTORAGETYPE = "redis"
        LIZMAP_HOME = "/srv/lizmap"
        LIZMAP_WMSSERVERURL = "https://mapserver.v.paler.net/ows"
        LIZMAP_CONFIG_INCLUDE = "/srv/etc"
      }

      service {
        name = "lizmap-php"
        port = "php"
      }

      resources {
        memory = 2000
        cpu = 1000
      }
    }

    task "web" {
      driver = "docker"

      config {
        image = "nginx:alpine"
        ports = ["http"]
        volumes = [
          "/data/services/maps/etc/nginx.conf:/etc/nginx/nginx.conf:ro",
          "/data/services/maps/var/nginx-log:/var/log/nginx",
          "/data/services/maps/var/nginx-cache:/var/cache/nginx",
          "/data/services/maps/www:/srv/lizmap/www",
        ]
      }

      service {
        name = "lizmap"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.lizmap.entryPoints=websecure",
          "traefik.http.routers.lizmap.rule=Host(`map.alo.land`)"
        ]
      }
    }
  }
}
