Skip to content

Commit

Permalink
docs: add nomad services template jobspec example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Apr 8, 2022
1 parent daa9824 commit 1bb34ee
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions website/content/docs/job-specification/template.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,38 @@ task "task" {
}
```
## Nomad Integration
### Nomad Services
Nomad service registrations can be queried using the `nomadService` and
`nomadServices` functions. The requests are tied to the same namespace as the
job which contains the template stanza.
```hcl
template {
data = <<EOF
# Configuration for a single NGINX upstream service.
upstream my_app {
{{- range nomadService "my-app" }}
server {{ .Address }}:{{ .Port }};{{- end }}
}

# Configuration for all services registered in Nomad as an NGINX upstream
# service.
{{ range nomadServices }}
# Configuration for service {{ .Name }}.
upstream {{ .Name | toLower }} {
{{- range nomadService .Name }}
server {{ .Address}}:{{ .Port }};{{- end }}
}
{{ end -}}
EOF

destination = "local/nginx.conf"
}
```
## Consul Integration
### Consul KV
Expand Down Expand Up @@ -315,22 +347,18 @@ the [`connect`][ct_api_connect] function.
data = <<EOF
# Configuration for a single upstream service.
upstream my_app {
{{range service "my_app"}}
server {{.Address}}:{{.Port}};
{{end}}
{{- range service "my-app" }}
server {{ .Address }}:{{ .Port }};{{- end }}
}

# Configuration for all services in the catalog.
{{range services}}
{{with service .Name}}
{{with index . 0}}
# Configuration for service {{.Name}}.
upstream {{.Name | toLower}} {
{{range service .Name}}
server {{.Address}}:{{.Port}};
{{end}}
{{ range services }}
# Configuration for service {{ .Name }}.
upstream {{ .Name | toLower }} {
{{- range service .Name }}
server {{ .Address}}:{{ .Port }};{{- end }}
}
{{end}}{{end}}{{end}}
{{ end -}}
EOF

destination = "local/nginx.conf"
Expand Down

0 comments on commit 1bb34ee

Please sign in to comment.