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

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

    task "frontend" {
      driver = "docker"

      config {
        image = "docker.io/netboxcommunity/netbox:v3.7-2.8.0"
        ports = ["http"]
        volumes = [
          "/data/services/netbox/configuration:/etc/netbox/config:z,ro",
          "/data/services/netbox/media:/opt/netbox/media",
          "/data/services/netbox/reports:/opt/netbox/reports",
          "/data/services/netbox/files:/opt/netbox/scripts",
        ]
      }

      env {
        DB_HOST = "postgres.service.consul"
        DB_NAME = "netbox"
        DB_USER = "netbox"
        DB_PASSWORD = "ik1chah5ae9Un7oozeiX"
        EMAIL_FROM = "netbox@paler.net"
        EMAIL_SERVER = "192.168.1.1"
        GRAPHQL_ENABLED = "true"
        HOUSEKEEPING_INTERVAL = "86400"
        MEDIA_ROOT = "/opt/netbox/netbox/media"
        REDIS_CACHE_HOST = "redis.service.consul"
        REDIS_HOST = "redis.service.consul"
        SECRET_KEY = "&EqXd#NTzIb2d2mvYxcOv5)&78fH5*Gq1&mstMGUaIyBfp-z+9"

        REMOTE_AUTH_ENABLED = "true"
        REMOTE_AUTH_BACKEND = "social_core.backends.open_id_connect.OpenIdConnectAuth"

        SOCIAL_AUTH_OIDC_ENDPOINT = "https://pocket-id.v.paler.net/"
        SOCIAL_AUTH_OIDC_KEY = "6ce1f1bb-d5e8-4ba5-b136-2643dc8bcbcf"
        SOCIAL_AUTH_OIDC_SECRET = "Af7sJvCn9BuijoJXrB5aWv6fTmEqLCAf"
        LOGOUT_REDIRECT_URL = "https://pocket-id.v.paler.net/logout"
      }

      resources {
        memory = 512
      }

      service {
        name = "netbox"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.netbox.entryPoints=websecure",
        ]
      }
    }

    task "worker" {
      driver = "docker"

      config {
        image = "docker.io/netboxcommunity/netbox:v3.7-2.8.0"
        command = "/opt/netbox/venv/bin/python"
        args = [
          "/opt/netbox/netbox/manage.py",
          "rqworker",
        ]
        volumes = [
          "/data/services/netbox/configuration:/etc/netbox/config:z,ro",
          "/data/services/netbox/media:/opt/netbox/media",
          "/data/services/netbox/reports:/opt/netbox/reports",
          "/data/services/netbox/files:/opt/netbox/scripts",
        ]
      }

      env {
        DB_HOST = "postgres.service.consul"
        DB_NAME = "netbox"
        DB_USER = "netbox"
        DB_PASSWORD = "ik1chah5ae9Un7oozeiX"
        EMAIL_FROM = "netbox@paler.net"
        EMAIL_SERVER = "192.168.1.1"
        GRAPHQL_ENABLED = "true"
        HOUSEKEEPING_INTERVAL = "86400"
        MEDIA_ROOT = "/opt/netbox/netbox/media"
        REDIS_CACHE_HOST = "redis.service.consul"
        REDIS_HOST = "redis.service.consul"
        SECRET_KEY = "&EqXd#NTzIb2d2mvYxcOv5)&78fH5*Gq1&mstMGUaIyBfp-z+9"
      }
    }

    task "housekeeping" {
      driver = "docker"

      config {
        image = "docker.io/netboxcommunity/netbox:v3.7-2.8.0"
        command = "/opt/netbox/housekeeping.sh"
        volumes = [
          "/data/services/netbox/configuration:/etc/netbox/config:z,ro",
          "/data/services/netbox/media:/opt/netbox/media",
          "/data/services/netbox/reports:/opt/netbox/reports",
          "/data/services/netbox/files:/opt/netbox/scripts",
        ]
      }

      env {
        DB_HOST = "postgres.service.consul"
        DB_NAME = "netbox"
        DB_USER = "netbox"
        DB_PASSWORD = "ik1chah5ae9Un7oozeiX"
        EMAIL_FROM = "netbox@paler.net"
        EMAIL_SERVER = "192.168.1.1"
        GRAPHQL_ENABLED = "true"
        HOUSEKEEPING_INTERVAL = "86400"
        MEDIA_ROOT = "/opt/netbox/netbox/media"
        REDIS_CACHE_HOST = "redis.service.consul"
        REDIS_HOST = "redis.service.consul"
        SECRET_KEY = "&EqXd#NTzIb2d2mvYxcOv5)&78fH5*Gq1&mstMGUaIyBfp-z+9"
      }
    }
  }
}
