-
CONSUL
is the address of our Consul cluster. This defaults to just"consul"
if used by local Docker linked containers. -
Only if the env var
CONSUL_AGENT
is available do we want to run theconsul-agent
job. This runs theconsul
agent process inside our container which ourcontainerpilot
process will use to communicate with our external Consul cluster. We also wantconsul-agent
to have ahealth
check as well. -
Run the
preStart
job. This can be used to preconfigure the "main" service of a container like setting an IP address inside a configuration file. -
Caveat: If we're given
CONSUL_AGENT
than ourpreStart
will run after theconsul-agent
job ishealthy
. -
Run our
nomad
job once ourpreStart
job has run. This job is configured with service registration at port4646
on interfaceinet
. We want this job to restart anunlimited
amount of times. We also have ahealth
check setup as well given ourinterval
andttl
settings. -
When the
nomad
isstopping
we run ourpreStop
job. This script can handle any clean-up that is required when shutting down ournomad
job.
Last active
November 29, 2017 03:05
-
-
Save jwreagor/14976fa5da7b86168102d1adadd479e5 to your computer and use it in GitHub Desktop.
Example ContainerPilot 3 Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
consul: '{{ if .CONSUL_AGENT }}localhost{{ else }}{{ .CONSUL | default "consul"}}{{ end }}:8500', | |
logging: { | |
level: '{{ .LOG_LEVEL | default "INFO" }}' | |
}, | |
jobs: [ | |
{ | |
name: "preStart", | |
exec: ["/usr/bin/nomad-manage", "preStart"], | |
{{ if .CONSUL_AGENT }} | |
when: { | |
source: "consul-agent", | |
once: "healthy", | |
} | |
{{ end }} | |
}, { | |
name: "nomad", | |
port: 4646, | |
interfaces: ["inet"], | |
restarts: "unlimited", | |
exec: [ | |
"/usr/bin/nomad", "agent", | |
"-dev", | |
"-config=/etc/nomad", | |
], | |
when: { | |
source: "preStart", | |
once: "exitSuccess", | |
}, | |
health: { | |
exec: ["/usr/bin/nomad-manage", "health"], | |
interval: 10, | |
ttl: 25, | |
} | |
}, { | |
name: "preStop", | |
exec: ["/usr/bin/nomad-manage", "preStop"], | |
when: { | |
source: "nomad", | |
once: "stopping", | |
} | |
},{{ if .CONSUL_AGENT }}{ | |
name: "consul-agent", | |
restarts: "unlimited", | |
exec: [ | |
"/usr/bin/consul", "agent", | |
"-data-dir=/data/consul", | |
"-config-dir=/etc/consul", | |
"-log-level=err", | |
"-rejoin", | |
"-retry-join", '{{ .CONSUL | default "consul" }}', | |
"-retry-max", "10", | |
"-retry-interval", "10s", | |
], | |
health: { | |
exec: "curl -so /dev/null http://localhost:8500", | |
interval: 10, | |
ttl: 25, | |
} | |
}{{ end }} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment