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

  group "caddy" {
    count = 1

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

    volume "caddy-data" {
      type      = "host"
      read_only = false
      source    = "caddy-data"
    }

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

    network {
      port "http" {
        static       = 80
        to           = 80
	    host_network = "public"
      }

      port "https" {
        static       = 443
        to           = 443
	    host_network = "public"
      }

      port "config" {
        static = 2019
        to     = 2019
      }

      dns {
        servers = ["100.80.195.56"]
      }
    }

    ###
    # CADDY
    ###

    task "caddy" {
      driver = "docker"

      volume_mount {
        volume      = "caddyfile"
        destination = "/etc/caddy/Caddyfile"
        read_only   = false
      }

      volume_mount {
        volume      = "caddy-data"
        destination = "/data"
        read_only   = false
      }

      env {
      }

      config {
        image = "caddy:2.3.0-alpine"
        ports = ["http", "https", "config"]
	    volumes = [
          "/mnt/vatnajokull/lajuntament-web:/sites/lajuntament-web",
          "/mnt/vatnajokull/folkugat-web:/sites/folkugat-web",
        ]
      }

      resources {
        cpu    = 500
        memory = 128
      }

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

