job "minecraft" {
  region      = "global"
  datacenters = ["samfelag"]
  type        = "service"

  group "minecraft" {
    count = 1

    volume "minecraft" {
      type      = "host"
      read_only = false
      source    = "minecraft"
    }

    restart {
      attempts = 2
      interval = "2m"
      delay    = "1m"
      mode     = "fail"
    }

    network {
      port "server" {
        static       = 25565
        to           = 25565
	host_network = "minecraft"
      }
    }

    ###
    # MINECRAFT SERVER
    ###

    task "minecraft" {
      driver = "docker"

      volume_mount {
        volume      = "minecraft"
        destination = "/data"
        read_only   = false
      }

      env {
        EULA = "TRUE"
        TZ   = "Europe/Madrid"
      }

      config {
        image = "itzg/minecraft-server"
        ports = ["server"]
      }

      resources {
        cpu    = 2800
        memory = 1900
      }

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

