| Filename | Output | |
|---|---|---|
| ${status} | ${file} | ${maybeOut} |
node.unique.id: {{ env "node.unique.id" }}
node.datacenter: {{ env "node.datacenter" }}
node.unique.name: {{ env "node.unique.name" }}
node.class: {{ env "node.class" }}
attr.cpu.arch: {{ env "attr.cpu.arch" }}
attr.cpu.numcores: {{ env "attr.cpu.numcores" }}
attr.cpu.totalcompute: {{ env "attr.cpu.totalcompute" }}
attr.consul.datacenter: {{ env "attr.consul.datacenter" }}
attr.unique.hostname: {{ env "attr.unique.hostname" }}
attr.unique.network.ip-address: {{ env "attr.unique.network.ip-address" }}
attr.kernel.name: {{ env "attr.kernel.name" }}
attr.kernel.version: {{ env "attr.kernel.version" }}
attr.platform.aws.ami-id: {{ env "attr.platform.aws.ami-id" }}
attr.platform.aws.instance-type: {{ env "attr.platform.aws.instance-type" }}
attr.os.name: {{ env "attr.os.name" }}
attr.os.version: {{ env "attr.os.version" }}
NOMAD_ALLOC_DIR: {{env "NOMAD_ALLOC_DIR"}}
NOMAD_TASK_DIR: {{env "NOMAD_TASK_DIR"}}
NOMAD_SECRETS_DIR: {{env "NOMAD_SECRETS_DIR"}}
NOMAD_MEMORY_LIMIT: {{env "NOMAD_MEMORY_LIMIT"}}
NOMAD_CPU_LIMIT: {{env "NOMAD_CPU_LIMIT"}}
NOMAD_ALLOC_ID: {{env "NOMAD_ALLOC_ID"}}
NOMAD_ALLOC_NAME: {{env "NOMAD_ALLOC_NAME"}}
NOMAD_ALLOC_INDEX: {{env "NOMAD_ALLOC_INDEX"}}
NOMAD_TASK_NAME: {{env "NOMAD_TASK_NAME"}}
NOMAD_GROUP_NAME: {{env "NOMAD_GROUP_NAME"}}
NOMAD_JOB_NAME: {{env "NOMAD_JOB_NAME"}}
NOMAD_DC: {{env "NOMAD_DC"}}
NOMAD_REGION: {{env "NOMAD_REGION"}}
VAULT_TOKEN: {{env "VAULT_TOKEN"}}
GOMAXPROCS: {{env "GOMAXPROCS"}}
HOME: {{env "HOME"}}
LANG: {{env "LANG"}}
LOGNAME: {{env "LOGNAME"}}
NOMAD_ADDR_export: {{env "NOMAD_ADDR_export"}}
NOMAD_ADDR_exstat: {{env "NOMAD_ADDR_exstat"}}
NOMAD_ALLOC_DIR: {{env "NOMAD_ALLOC_DIR"}}
NOMAD_ALLOC_ID: {{env "NOMAD_ALLOC_ID"}}
NOMAD_ALLOC_INDEX: {{env "NOMAD_ALLOC_INDEX"}}
NOMAD_ALLOC_NAME: {{env "NOMAD_ALLOC_NAME"}}
NOMAD_CPU_LIMIT: {{env "NOMAD_CPU_LIMIT"}}
NOMAD_DC: {{env "NOMAD_DC"}}
NOMAD_GROUP_NAME: {{env "NOMAD_GROUP_NAME"}}
NOMAD_HOST_PORT_export: {{env "NOMAD_HOST_PORT_export"}}
NOMAD_HOST_PORT_exstat: {{env "NOMAD_HOST_PORT_exstat"}}
NOMAD_IP_export: {{env "NOMAD_IP_export"}}
NOMAD_IP_exstat: {{env "NOMAD_IP_exstat"}}
NOMAD_JOB_NAME: {{env "NOMAD_JOB_NAME"}}
NOMAD_MEMORY_LIMIT: {{env "NOMAD_MEMORY_LIMIT"}}
NOMAD_PORT_export: {{env "NOMAD_PORT_export"}}
NOMAD_PORT_exstat: {{env "NOMAD_PORT_exstat"}}
NOMAD_REGION: {{env "NOMAD_REGION"}}
NOMAD_SECRETS_DIR: {{env "NOMAD_SECRETS_DIR"}}
NOMAD_TASK_DIR: {{env "NOMAD_TASK_DIR"}}
NOMAD_TASK_NAME: {{env "NOMAD_TASK_NAME"}}
PATH: {{env "PATH"}}
PWD: {{env "PWD"}}
SHELL: {{env "SHELL"}}
SHLVL: {{env "SHLVL"}}
USER: {{env "USER"}}
VAULT_TOKEN: {{env "VAULT_TOKEN"}}
concat key: service/fabio/{{ env "NOMAD_JOB_NAME" }}/listeners
key: {{ keyOrDefault ( printf "service/fabio/%s/listeners" ( env "NOMAD_JOB_NAME" ) ) ":9999" }}
{{ define "custom" }}service/fabio/{{env "NOMAD_JOB_NAME" }}/listeners{{ end }}
key: {{ keyOrDefault (executeTemplate "custom") ":9999" }}
math - alloc_id + 1: {{env "NOMAD_ALLOC_INDEX" | parseInt | add 1}}
EOH
destination = "local/template.out"
}
}
}
}
================================================
FILE: http_echo/template/ets3.nomad
================================================
job "http-echo" {
datacenters = ["dc1"]
type = "service"
update {
max_parallel = 1
}
group "web" {
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
network {
port "http" {}
}
task "server" {
driver = "exec"
config {
command = "/bin/bash"
args = [
"-c",
"local/http-echo -listen :${NOMAD_PORT_http} -text \"`env`\""
]
}
artifact {
source = "https://github.com/hashicorp/http-echo/releases/download/v0.2.3/http-echo_0.2.3_linux_amd64.tar.gz"
options {
checksum = "sha256:e30b29b72ad5ec1f6dfc8dee0c2fcd162f47127f2251b99e47b9ae8af1d7b917"
}
}
template {
destination = "local/template.out"
data = <
node.unique.id: {{ env "node.unique.id" }}
node.datacenter: {{ env "node.datacenter" }}
node.unique.name: {{ env "node.unique.name" }}
node.class: {{ env "node.class" }}
attr.cpu.arch: {{ env "attr.cpu.arch" }}
attr.cpu.numcores: {{ env "attr.cpu.numcores" }}
attr.cpu.totalcompute: {{ env "attr.cpu.totalcompute" }}
attr.consul.datacenter: {{ env "attr.consul.datacenter" }}
attr.unique.hostname: {{ env "attr.unique.hostname" }}
attr.unique.network.ip-address: {{ env "attr.unique.network.ip-address" }}
attr.kernel.name: {{ env "attr.kernel.name" }}
attr.kernel.version: {{ env "attr.kernel.version" }}
attr.platform.aws.ami-id: {{ env "attr.platform.aws.ami-id" }}
attr.platform.aws.instance-type: {{ env "attr.platform.aws.instance-type" }}
attr.os.name: {{ env "attr.os.name" }}
attr.os.version: {{ env "attr.os.version" }}
NOMAD_ALLOC_DIR: {{env "NOMAD_ALLOC_DIR"}}
NOMAD_TASK_DIR: {{env "NOMAD_TASK_DIR"}}
NOMAD_SECRETS_DIR: {{env "NOMAD_SECRETS_DIR"}}
NOMAD_MEMORY_LIMIT: {{env "NOMAD_MEMORY_LIMIT"}}
NOMAD_CPU_LIMIT: {{env "NOMAD_CPU_LIMIT"}}
NOMAD_ALLOC_ID: {{env "NOMAD_ALLOC_ID"}}
NOMAD_ALLOC_NAME: {{env "NOMAD_ALLOC_NAME"}}
NOMAD_ALLOC_INDEX: {{env "NOMAD_ALLOC_INDEX"}}
NOMAD_TASK_NAME: {{env "NOMAD_TASK_NAME"}}
NOMAD_GROUP_NAME: {{env "NOMAD_GROUP_NAME"}}
NOMAD_JOB_NAME: {{env "NOMAD_JOB_NAME"}}
NOMAD_DC: {{env "NOMAD_DC"}}
NOMAD_REGION: {{env "NOMAD_REGION"}}
VAULT_TOKEN: {{env "VAULT_TOKEN"}}
GOMAXPROCS: {{env "GOMAXPROCS"}}
HOME: {{env "HOME"}}
LANG: {{env "LANG"}}
LOGNAME: {{env "LOGNAME"}}
NOMAD_ADDR_export: {{env "NOMAD_ADDR_export"}}
NOMAD_ADDR_exstat: {{env "NOMAD_ADDR_exstat"}}
NOMAD_ALLOC_DIR: {{env "NOMAD_ALLOC_DIR"}}
NOMAD_ALLOC_ID: {{env "NOMAD_ALLOC_ID"}}
NOMAD_ALLOC_INDEX: {{env "NOMAD_ALLOC_INDEX"}}
NOMAD_ALLOC_NAME: {{env "NOMAD_ALLOC_NAME"}}
NOMAD_CPU_LIMIT: {{env "NOMAD_CPU_LIMIT"}}
NOMAD_DC: {{env "NOMAD_DC"}}
NOMAD_GROUP_NAME: {{env "NOMAD_GROUP_NAME"}}
NOMAD_HOST_PORT_export: {{env "NOMAD_HOST_PORT_export"}}
NOMAD_HOST_PORT_exstat: {{env "NOMAD_HOST_PORT_exstat"}}
NOMAD_IP_export: {{env "NOMAD_IP_export"}}
NOMAD_IP_exstat: {{env "NOMAD_IP_exstat"}}
NOMAD_JOB_NAME: {{env "NOMAD_JOB_NAME"}}
NOMAD_MEMORY_LIMIT: {{env "NOMAD_MEMORY_LIMIT"}}
NOMAD_PORT_export: {{env "NOMAD_PORT_export"}}
NOMAD_PORT_exstat: {{env "NOMAD_PORT_exstat"}}
NOMAD_REGION: {{env "NOMAD_REGION"}}
NOMAD_SECRETS_DIR: {{env "NOMAD_SECRETS_DIR"}}
NOMAD_TASK_DIR: {{env "NOMAD_TASK_DIR"}}
NOMAD_TASK_NAME: {{env "NOMAD_TASK_NAME"}}
PATH: {{env "PATH"}}
PWD: {{env "PWD"}}
SHELL: {{env "SHELL"}}
SHLVL: {{env "SHLVL"}}
USER: {{env "USER"}}
VAULT_TOKEN: {{env "VAULT_TOKEN"}}
concat key: service/fabio/{{ env "NOMAD_JOB_NAME" }}/listeners
key: {{ keyOrDefault ( printf "service/fabio/%s/listeners" ( env "NOMAD_JOB_NAME" ) ) ":9999" }}
{{ define "custom" }}service/fabio/{{env "NOMAD_JOB_NAME" }}/listeners{{ end }}
key: {{ keyOrDefault (executeTemplate "custom") ":9999" }}
math - alloc_id + 1: {{env "NOMAD_ALLOC_INDEX" | parseInt | add 1}}
EOH
}
}
}
}
================================================
FILE: httpd_site/README.md
================================================
# httpd site
This job will download a website tarball into the allocation and spin up
the Apache webserver docker image (2.4-alpine) and mount this container
into place.
================================================
FILE: httpd_site/httpd.nomad
================================================
job "httpd_site" {
datacenters = ["dc1"]
type = "service"
update {
stagger = "5s"
max_parallel = 1
}
group "httpd" {
count = 1
network {
port "http" {
to = 80
}
}
task "httpd-docker" {
artifact {
source = "https://raw.githubusercontent.com/angrycub/nomad_example_jobs/master/httpd_site/site-content.tgz"
destination = "tarball"
}
driver = "docker"
config {
image = "httpd:2.4-alpine"
volumes = [
"tarball:/usr/local/apache2/htdocs"
]
ports = ["http"]
}
resources {
cpu = 200
memory = 32
}
}
}
}
================================================
FILE: httpd_site/make_site.sh
================================================
#!/bin/sh
echo "📦 Creating site tarball..."
cd site-content &&
tar -zcvf ../site-content.tgz * &&
cd ..
================================================
FILE: httpd_site/site-content/about.html
================================================
This repository that contains this job can be found on GitHub at
angrycub/nomad_example_jobs/httpd_site. The specific site code is in the site-content folder.
Return to Home.
================================================ FILE: httpd_site/site-content/css/style.css ================================================ body { font-family: "Helvetica Neue","Helvetica","Arial", sans-serif; } h1 { color: white; text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue; width: auto; border-bottom: 1px solid #333; } code { background: #EEE; border: 1px solid #CCC; border-radius: 5px; padding: 3px; } ================================================ FILE: httpd_site/site-content/index.html ================================================This is an example site to demonstrate fetching a resource as a tarball into a Nomad job and mounting it to a Docker Container.
There's an About page too, for fun.
================================================
FILE: ipv6/SimpleHTTPServer/sample.nomad
================================================
# This job will create a SimpleHTTPServer that is IPV6 enabled. This will allow
# a user to browse around in an alloc dir. Not spectacularly useful, but is a
# reasonable facsimile of a real workload.
job http6 {
datacenters = ["dc1"]
group "group" {
count = 1
task "server" {
template {
data = <Welcome to the Bar Service.
You are on ${NOMAD_IP_http}.",
]
}
artifact {
source = "https://github.com/hashicorp/http-echo/releases/download/v0.2.3/http-echo_0.2.3_linux_amd64.tar.gz"
options {
checksum = "sha256:e30b29b72ad5ec1f6dfc8dee0c2fcd162f47127f2251b99e47b9ae8af1d7b917"
}
}
}
}
}
================================================
FILE: nginx-fabio-clone/e.ct
================================================
{{- range services -}}
{{- $name := .Name -}}
{{- $service := service .Name -}}
{{- if ne $name "nginx-wdg-lb-aus" -}}
{{- if ne $name "nginx-wdg-lb" }}
upstream {{$name}} {
{{- range $service }}
server {{ .Address }}:{{ .Port }} max_fails=3 fail_timeout=60 weight=1;
{{- end }}
}
{{- end -}}
{{- end -}}
{{- end }}
{{- range $tag, $services := services | byTag -}}
{{- if $tag | regexMatch "urlprefix-[^:]" -}}
{{- $opts := ($tag | replaceAll "urlprefix-" "urlprefix=") -}}
{{- range $opt := $opts | split " " -}}
{{- $splitOpt := $opt | split "=" -}}
{{- scratch.Set (index $splitOpt 0) (index $splitOpt 1) -}}
{{- end -}}
location {{ scratch.Get "urlprefix" }}
{{- if scratch.Key "strip" -}}
{{- $regex := ( scratch.Get "strip" | regexReplaceAll "(.*)" "^$1" ) -}}
{{- scratch.Set "urlprefix" ( scratch.Get "urlprefix" | regexReplaceAll $regex "" ) -}}
rewrite
{{- end }}
proxy-pass http://{{ scratch.Get "urlprefix" }}
{{ end -}}
{{- end -}}
================================================
FILE: nginx-fabio-clone/e.out
================================================
upstream bar-service {
server 10.0.0.172:31815 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:24839 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:31970 max_fails=3 fail_timeout=60 weight=1;
}
upstream consul {
server 10.0.0.52:8300 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.132:8300 max_fails=3 fail_timeout=60 weight=1;
}
upstream foo-service {
server 10.0.0.172:24438 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:25861 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:24545 max_fails=3 fail_timeout=60 weight=1;
}
upstream foo-service-2 {
server 10.0.0.172:24438 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:25861 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:24545 max_fails=3 fail_timeout=60 weight=1;
}
upstream nomad {
server 10.0.0.89:4647 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.89:4648 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.89:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4647 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4648 max_fails=3 fail_timeout=60 weight=1;
}
upstream nomad-client {
server 10.0.0.172:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:4646 max_fails=3 fail_timeout=60 weight=1;
}
-------------
upstream bar-service {
server 10.0.0.172:31815 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:24839 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:31970 max_fails=3 fail_timeout=60 weight=1;
}
upstream consul {
server 10.0.0.52:8300 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.132:8300 max_fails=3 fail_timeout=60 weight=1;
}
upstream foo-service {
server 10.0.0.172:24438 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:25861 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:24545 max_fails=3 fail_timeout=60 weight=1;
}
upstream foo-service-2 {
server 10.0.0.172:24438 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:25861 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:24545 max_fails=3 fail_timeout=60 weight=1;
}
upstream nomad {
server 10.0.0.89:4647 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.89:4648 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.89:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4647 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.208:4648 max_fails=3 fail_timeout=60 weight=1;
}
upstream nomad-client {
server 10.0.0.172:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.108:4646 max_fails=3 fail_timeout=60 weight=1;
server 10.0.0.128:4646 max_fails=3 fail_timeout=60 weight=1;
}
================================================
FILE: nginx-fabio-clone/example.nomad
================================================
job "nginx" {
datacenters = ["dc1"]
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "3m"
auto_revert = false
canary = 0
}
group "group" {
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
network {
port "http" {
to = 80
}
}
service {
name = "nginx"
tags = ["lb"]
port = "http"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
task "nginx_docker" {
driver = "docker"
config {
image = "nginx:1.13.11"
volumes = ["local/nginx.conf:/etc/nginx/conf.d/default.conf"]
ports = ["http"]
}
template {
destination = "local/nginx.conf"
change_mode = "signal"
change_signal = "SIGHUP"
data = <Welcome to the Foo Service.
You are on ${NOMAD_IP_http}.