github.com/hernad/nomad@v1.6.112/ui/app/utils/default_jobs/service-discovery.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  export default `job "service-discovery-example" {
     7    // Specifies the datacenter where this job should be run
     8    // This can be omitted and it will default to ["*"]
     9    datacenters = ["*"]
    10  
    11    group "client" {
    12      task "curl" {
    13        driver = "docker"
    14  
    15        config {
    16          image   = "curlimages/curl:7.87.0"
    17          command = "/bin/ash"
    18          args    = ["local/script.sh"]
    19        }
    20  
    21        template {
    22          data        = <<EOF
    23  #!/usr/bin/env ash
    24  
    25  while true; do
    26  {{range nomadService "nomad-service-discovery-example-server"}}
    27    curl -L -v http://{{.Address}}:{{.Port}}/
    28  {{end}}
    29    sleep 3
    30  done
    31  EOF
    32          destination = "local/script.sh"
    33        }
    34  
    35        resources {
    36          cpu    = 10
    37          memory = 50
    38        }
    39      }
    40    }
    41  
    42    group "server" {
    43      network {
    44        port "www" {
    45          to = 8001
    46        }
    47      }
    48  
    49      task "http" {
    50        driver = "docker"
    51  
    52        service {
    53          name     = "nomad-service-discovery-example-server"
    54          provider = "nomad"
    55          port     = "www"
    56          // If you're running Nomad in dev mode, uncomment the following address_mode line to allow this service to be discovered
    57          // address_mode = "driver"
    58  
    59          check {
    60            type     = "http"
    61            path     = "/"
    62            interval = "5s"
    63            timeout  = "1s"
    64          }
    65        }
    66  
    67        config {
    68          image   = "busybox:1"
    69          command = "httpd"
    70          args    = ["-v", "-f", "-p", "\${NOMAD_PORT_www}", "-h", "/local"]
    71          ports   = ["www"]
    72        }
    73  
    74        template {
    75          data        = <<EOF
    76  hello world
    77  EOF
    78          destination = "local/index.html"
    79        }
    80  
    81        resources {
    82          cpu    = 10
    83          memory = 50
    84        }
    85      }
    86    }
    87  }`;