| 1 |
/* |
| 2 |
https://www.nomadproject.io/docs/job-specification/index.html |
| 3 |
*/ |
| 4 |
|
| 5 |
# This declares a job named "docs". There can be exactly one |
| 6 |
# job declaration per job file. |
| 7 |
job "docs" { |
| 8 |
# Specify this job should run in the region named "us". Regions |
| 9 |
# are defined by the Nomad servers' configuration. |
| 10 |
region = "us" |
| 11 |
|
| 12 |
# Spread the tasks in this job between us-west-1 and us-east-1. |
| 13 |
datacenters = ["us-west-1", "us-east-1"] |
| 14 |
|
| 15 |
# Run this job as a "service" type. Each job type has different |
| 16 |
# properties. See the documentation below for more examples. |
| 17 |
type = "service" |
| 18 |
|
| 19 |
# Specify this job to have rolling updates, two-at-a-time, with |
| 20 |
# 30 second intervals. |
| 21 |
update { |
| 22 |
stagger = "30s" |
| 23 |
max_parallel = 2 |
| 24 |
} |
| 25 |
|
| 26 |
# A group defines a series of tasks that should be co-located |
| 27 |
# on the same client (host). All tasks within a group will be |
| 28 |
# placed on the same host. |
| 29 |
group "webs" { |
| 30 |
# Specify the number of these tasks we want. |
| 31 |
count = 5 |
| 32 |
|
| 33 |
# Create an individual task (unit of work). This particular |
| 34 |
# task utilizes a Docker container to front a web application. |
| 35 |
task "frontend" { |
| 36 |
# Specify the driver to be "docker". Nomad supports |
| 37 |
# multiple drivers. |
| 38 |
driver = "docker" |
| 39 |
|
| 40 |
# Configuration is specific to each driver. |
| 41 |
config { |
| 42 |
image = "hashicorp/web-frontend" |
| 43 |
} |
| 44 |
|
| 45 |
# The service block tells Nomad how to register this service |
| 46 |
# with Consul for service discovery and monitoring. |
| 47 |
service { |
| 48 |
# This tells Consul to monitor the service on the port |
| 49 |
# labelled "http". Since Nomad allocates high dynamic port |
| 50 |
# numbers, we use labels to refer to them. |
| 51 |
port = "http" |
| 52 |
|
| 53 |
check { |
| 54 |
type = "http" |
| 55 |
path = "/health" |
| 56 |
interval = "10s" |
| 57 |
timeout = "2s" |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
# It is possible to set environment variables which will be |
| 62 |
# available to the task when it runs. |
| 63 |
env { |
| 64 |
"DB_HOST" = "db01.example.com" |
| 65 |
"DB_USER" = "web" |
| 66 |
"DB_PASS" = "loremipsum" |
| 67 |
} |
| 68 |
|
| 69 |
# Specify the maximum resources required to run the task, |
| 70 |
# include CPU, memory, and bandwidth. |
| 71 |
resources { |
| 72 |
cpu = 500 # MHz |
| 73 |
memory = 128 # MB |
| 74 |
|
| 75 |
network { |
| 76 |
mbits = 100 |
| 77 |
|
| 78 |
# This requests a dynamic port named "http". This will |
| 79 |
# be something like "46283", but we refer to it via the |
| 80 |
# label "http". |
| 81 |
port "http" {} |
| 82 |
|
| 83 |
# This requests a static port on 443 on the host. This |
| 84 |
# will restrict this task to running once per host, since |
| 85 |
# there is only one port 443 on each host. |
| 86 |
port "https" { |
| 87 |
static = 443 |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |