variable "version" {
  type = string
}

variable "secret_access_key" {
  type = string
}

job "adriano.fyi" {
  datacenters = ["dc1"]
  namespace = "default"

  group "task" {
    count = 2

    network {
      port "http" {
        to = 3000
        host_network = "private"
      }
    }

    task "webserver" {
      driver = "docker"

      artifact {
        source = "s3://us-east-1.linodeobjects.com/adriano-fyi-static-site/adriano_fyi-${var.version}.tar"
        options {
          aws_access_key_id     = "6P583LDF5TH38MV4D1Y1"
          aws_access_key_secret = var.secret_access_key
          # Leave the archive in tar format
          archive = false
        }
      }

      config {
        load = "adriano_fyi-${var.version}.tar"
        image = "adriano_fyi:${var.version}"
        ports = ["http"]
      }

      resources {
        cpu = 128
        memory = 128
      }

      service {
        port = "http"
        name = "adriano-fyi"
        provider = "nomad"
      }
    }
  }
}
