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

  meta {
    uuid = uuidv4()
  }

  group "web" {
    network {
      port "http" {
        to = 3000
      }
      port "ssh" {
        to = 2222
      }
    }

    task "server" {
      driver = "docker"

      config {
        image = "gitea/gitea:latest-rootless"
        ports = [
          "http",
          "ssh",
        ]
        volumes = [
          "/data/services/gitea/data:/var/lib/gitea",
          "/data/services/gitea/config:/etc/gitea",
          "/etc/timezone:/etc/timezone:ro",
          "/etc/localtime:/etc/localtime:ro",
        ]
      }

      env {
        GITEA__database__DB_TYPE = "postgres"
        GITEA__database__HOST = "postgres.service.consul:5432"
        GITEA__database__NAME = "gitea"
        GITEA__database__USER = "gitea"
        GITEA__database__PASSWD = "thu3AhkeisoohaeXuKee"
        GITEA__mailer__ENABLED = "true"
        GITEA__mailer__FROM = "gitea@paler.net"
        GITEA__mailer__PROTOCOL = "smtp"
        GITEA__mailer__SMTP_ADDR = "192.168.1.1"
      }

      service {
        name = "gitea"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.gitea.entryPoints=websecure",
          "traefik.http.services.gitea.loadBalancer.serversTransport=gitea-transport@file",
        ]
      }

      service {
        name = "gitea-ssh"
        port = "ssh"

        tags = [
          "traefik.enable=true",
          "traefik.tcp.routers.gitea-ssh.rule=HostSNI(`*`)",
          "traefik.tcp.routers.gitea-ssh.entryPoints=ssh",
          "traefik.tcp.routers.gitea-ssh.service=gitea-ssh",
        ]
      }

      resources {
        memory = 500
      }
    }
  }
}
