-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable substitution for arbitrary Consul keys in Docker image field #5191
Comments
Hi @eigengrau -- great question! Templating the Docker job "example" {
datacenters = ["dc1"]
group "cache" {
task "redis" {
driver = "docker"
config {
image = "${IMAGE}" # <--- Interpolate "IMAGE" env var created below here
port_map {
db = 6379
}
}
template {
data = <<EOF
IMAGE={{ key "image" }} # <--- Pull Consul key "image" into env var "IMAGE" here
EOF
# A destination file is written even for env templates to aide in debugging
destination = "image.env"
# env = true exposes the IMAGE variable inside the config stanza
env = true
}
# resources and service stanzas removed for brevity
}
}
} If you start the job before the
If you run
If you update the Consul key with
(Note that Task Events may change slightly between releases, so your output may not match this precisely.) By default template's have a 5 second Alternative: DeploymentsThere is a high potential for a service outage with the above approach due to 2 factors:
Nomad Deployments are meant to address these two issues and are configured via the job's To use deployments with CI/CD you would use Consul template or a similar tool to template your job files before submitting them to Nomad. That way your CD tool controls when a deployment happens and what image is being deployed. The downside to this approach being that there are more services to configure than just Nomad and Consul. I hope this helps! |
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. |
For a simple-and-stupid approach to CD, it would be convenient to give variable interpolation access to Consul keys. The use-case I’m interested in would place a reference to a Consul key within the Docker driver’s
config.image
. A CI job could then write Docker image hashes into that key and thus trigger a re-deployment, without needing to communicate with Nomad directly.As a work-around, Consul Template may be sufficient, but nesting multiple levels of templating is a bit awkward even when different syntactic markers are being used.
This issue may overlap with #1185, but that ticket (at least the ticket topic) refers to expanding references using the local environment. Feel free to close as dupe if appropriate.
Thank you kindly for making Nomad!
The text was updated successfully, but these errors were encountered: