Hi there, I’m trying to figure out a way to create a nomad script which creates a docker container that holds a file with a specific path name. I’ve looked at some websites which mentions the use of artifacts, however im not exactly sure how to use it, for example the source will be a file called ‘config.yml’ which is in the same folder as the nomad script and not a http:// url (which is suggested here) . Can I do that?
Also, I’m not 100% sure on how artifacts work, would the file need to be made into an artifact and then it gets uploaded using the artifact{} block?
And finally, Once ive done a nomad run micro.hcl in the CLI and it goes through successfully, how can I go and check that the actual file is present in the container (for visual purposes). Would I just type in docker container list to find out if the container has deployed successfully?
I stand to be corrected by those more experienced, but from what I have seen so far, the way to do this is not via an artifact stanza, but a template stanza. This can be used to create a file from a local template, write it to a destination in the job’s workspace, and then mount that path into a volume that is also mounted on the container.
The answer to this question:
is probably found with a nomad alloc fs. You would need to get the job allocation first, and then with an alloc ls, you can alloc cat <filename> to see the final tempalted file.
Hi Bruce, thanks for replying.
Do you think the best practice would be to use the COPY command in the dockerfile to copy the config.yml from the local directory and then create an image which would be easier to implement rather than the template stanza?
I’m also kinda confused on what the purpose of a artifact is, I get that its downloading, but why is that useful? And how does that differ from template stanza as they both have source and destination as parameters, and thus do similar things?
Thank you!
I guess, but then you need to have a docker-push process somewhere to deliver the updated image. Personally, I would avoid that, in order to separate configuration and data from code.
In my mind, the purpose is to provide your deploy with dependencies. These can be packages or other components that are not part of your application but need to be provisioned at runtime, or can simply be data that the application needs to function.
A common pattern is that an application needs a script, configuration file, etc to run, and typically people would combine this configuration with the build at runtime
An artifact stanza would be useful here, but for safety reasons, Nomad has disabled the ability to load artifacts from the filesystem
One of the key differences is that the template stanza provisions files, not arbitrary blobs of data (unless, of course you pass a blob of data into a template!). But templates should generally be used to take advantage of the job variables, instead of just giving the job static files.
I think that if you read nomad #1897 carefully, you will find the solution to your needs.
If anyone from the nomad devs are reading, it would be great to have a tutorial on this.