levant icon indicating copy to clipboard operation
levant copied to clipboard

Add ability to include other files into a jobspec

Open cconstantine opened this issue 7 years ago • 1 comments

This is a feature request for a method for including other files into a jobspec.

I would like to deploy a number of services into a single job, and each one requires a static configuration file to run. I could use heredocs with a template stanza to configure them, but that means putting ALL of the configuration files contents into a single file.

In addition to allowing me to put service configuration files into multiple files, it would generally allow people to split up large or complicated job specs into multiple pieces, and re-use repeated portions of a jobspec.

Example Nomad Job Template This is an example interface for including files. I have no attachment to the specific method names or formats for how this would work, but this would satisfy me.

variables.yml:

---
configurationVariables:
  variable: someValue

job.tpl:

job "foo" {
  ...
  group "someGroup" {
    task "someTask" {
      template {
        data = <<EOF
[[ include "configuration.yml.tpl" .configurationVariables ]]
EOF
        destination = "configuration.yml"
      }
    }
  }
}

configuration.yml.tpl:

---
some: rather
large: configuration
file: [[ .variable ]]

Output of running levant render with the above files:

job "foo" {
  ...
  group "someGroup" {
    task "someTask" {
      template {
        data = <<EOF
---
some: rather
large: configuration
file: someValue
EOF
        destination = "configuration.yml"
      }
    }
  }
}

cconstantine avatar Dec 14 '18 19:12 cconstantine

Thanks for the request @cconstantine. The ability to have a template function which attempts to read the file and then add the contents to the section should be doable. Having those contents contain a variable required for substitution will be interesting, that depends heavy on the order of the template rendering which I will attempt to test when working on this for you.

jrasell avatar Dec 17 '18 11:12 jrasell