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

  meta {
    uuid = uuidv4()
  }

  group "db" {
    # Run on primary storage node (zippy) for local disk performance
    constraint {
      attribute = "${meta.storage_role}"
      value     = "primary"
    }

    network {
      port "redis" {
        static = 6379
      }
      port "exporter" {
        to = 9121
      }
    }

    task "server" {
      driver = "docker"

      config {
        image = "redis:alpine"
        ports = ["redis"]
        volumes = [ "/data/services/redis:/data" ]
      }

      service {
        name = "redis"
        port = "redis"
        check {
          type = "tcp"
          port = "redis"
          interval = "30s"
          timeout = "2s"
        }
      }

      resources {
        cpu = 300
        memory = 300
      }
    }

    task "exporter" {
      driver = "docker"

      config {
        image = "oliver006/redis_exporter:alpine"
        ports = ["exporter"]
      }

      env {
        REDIS_ADDR = "redis://${NOMAD_ADDR_redis}"
      }

      service {
        name = "redis-exporter"
        port = "exporter"
        tags = ["metrics"]
      }
    }
  }
}
