job "odm" {
  datacenters = ["alo"]
  meta {
    uuid = uuidv4()
  }

  group "admin" {
    network {
      # webodm
      port "ui" {
        to = 8000
      }

      # clusterodm
      port "cluster" {
        to = 10000
      }
      port "cli" {
        static = 18080
        to = 8080
      }
      port "api" {
        static = 3001
        to = 3000
      }
    }

    task "web" {
      driver = "docker"

      config {
        image = "opendronemap/webodm_webapp"
        ports = ["ui"]
        command = "/webodm/start.sh"
        volumes = [
          "/data/services/webodm:/webodm/app/media",
          "local/local_settings.py:/webodm/webodm/local_settings.py:ro",
        ]
      }

      env {
        WO_DEBUG = "NO"
        WO_DEV = "NO"
        WO_SSL = "NO"
        WO_BROKER = "redis://redis.service.consul"
      }

      template {
        data = <<EOH
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'webodm',
        'USER': 'webodm',
        'PASSWORD': 'ura3quohguzeikaiCaab',
        'HOST': 'postgres.service.consul',
        'PORT': '5432',
    }
}
EOH
        destination = "local/local_settings.py"
      }

      resources {
        cpu = 500
        memory = 1200
      }

      service {
        name = "webodm"
        port = "ui"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.webodm.entryPoints=websecure",
          "traefik.http.routers.webodm.middlewares=oidc-auth@file",
        ]
      }
    }

    task "cluster" {
      driver = "docker"

      config {
        image = "opendronemap/clusterodm"
        ports = [
          "cluster",
          "cli",
          "api",
        ]
      }

      service {
        name = "clusterodm"
        port = "cluster"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.clusterodm.entryPoints=websecure",
          "traefik.http.routers.clusterodm.middlewares=oidc-auth@file",
        ]
      }

      service {
        name = "clusterodm-api"
        port = "api"
      }

      service {
        name = "clusterodm-cli"
        port = "cli"
      }
    }
  }

  group "worker" {
    count = 1
    spread {
      attribute = "${node.unique.id}"
    }
    constraint {
      distinct_hosts = true
    }

    network {
      port "api" {
        static = 3000
      }
    }

    task "celery" {
      driver = "docker"

      config {
        image = "opendronemap/webodm_webapp"
        command = "/webodm/worker.sh"
        args = ["start"]
        volumes = [
          "/data/services/webodm:/webodm/app/media",
          "local/local_settings.py:/webodm/webodm/local_settings.py:ro",
        ]
      }

      env {
        WO_DEBUG = "NO"
        WO_DEV = "NO"
        WO_SSL = "NO"
        WO_BROKER = "redis://redis.service.consul"
      }

      template {
        data = <<EOH
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'webodm',
        'USER': 'webodm',
        'PASSWORD': 'ura3quohguzeikaiCaab',
        'HOST': 'postgres.service.consul',
        'PORT': '5432',
    }
}
EOH
        destination = "local/local_settings.py"
      }

      resources {
        cpu = 200
        memory = 512
      }
    }

    task "node" {
      driver = "docker"

      config {
        image = "opendronemap/nodeodm"
        ports = ["api"]
      }

      resources {
        cpu = 1000
        memory = 3000
      }

      service {
        port = "api"
      }
    }
  }
}
