In the Introduction to Nomad Pack tutorial you learned about Nomad Pack, how to deploy applications with it, and how to discover community packs.
In this tutorial, you will learn about more advanced usage including:
- Generating a variable file
- Rendering a Pack
- Planning with
- Registry management
You can pass in variables to a pack with a variables file.
$ nomad-pack run hello_world -f ./my-variables.hcl
generate var-file command can generate variable files from a pack.
$ nomad-pack generate var-file hello_world -o ./my-variables.hcl
You can also use the path to a pack instead of a pack name.
$ nomad-pack generate var-file ./my-local-pack -o ./my-variables.hcl
At times, you may wish to use Nomad Pack to render jobspecs, but you will not want to immediately deploy these to Nomad.
This can be useful when writing a pack, debugging deployments, integrating Nomad Pack into a CI/CD environment, or if you have another mechanism for handling Nomad deploys.
render command takes the same
--var-file flags that
--to-dir flag determines the directory where the rendered templates will be written.
You can pass the
--render-output-template flag to additionally render the output template. Some output templates rely on a deployment for information. In these cases, the output template may not render with all the necessary information.
$ nomad-pack render hello_world --to-dir ./tmp --var greeting=hola --render-output-template
To deploy the resources in a pack to Nomad, use the
$ nomad-pack run hello_world
By passing a
--name value into
run, Nomad Pack deploys each resource in the
pack with a metadata value for pack name. If no name is given, the pack name
is used by default.
This allows Nomad Pack to manage multiple deployments of the same pack.
$ nomad-pack run hello_world --name hola-mundo
It is also possible to run a local pack directly from the pack directory by passing in the directory instead of the pack name. This can be helpful while developing a pack.
nomad pack run .
If you want see details on how Nomad Pack will deploy a pack but are not ready to immediately deploy the pack, run the
This invokes Nomad in a dry-run mode using the Nomad Plan API endpoint.
nomad-pack plan hello_world
plan takes the
--name flag to look for packs deployments with that name. Nomad Pack uses the pack name by default.
nomad-pack plan hello_world --name hola-mundo
plan command also takes the
-f flags like the
nomad-pack plan hello_world -f ./my-variables.hcl --var greeting=hallo
The Introduction to Nomad Pack tutorial explains the basics of adding to and listing packs in the registry. The following section provides additional details on registry management.
The first time you run
list, Nomad Pack will add a
directory to your desktop user's cache directory—
$XDG_CACHE_DIR on Linux,
~/Library/Caches on macOS,
%AppData% on Windows, etc. This folder stores
information about cloned registries and their available packs.
During initialization, Nomad Pack downloads a default registry of packs from the Nomad Pack community registry.
The directory structure is as follows:
parent-directories (see above) └── nomad └── packs ├── <REGISTRY> ├── <REGISTRY-TAG> ├── <PACK-NAME@REF> ├── ...files containing pack contents...
Nomad Pack requires the contents of the pack cache directory to work properly, but you should not manually manage or change these files. Instead, you can use the
registry command includes several sub-commands for interacting with registries.
Add custom registries with the
registry add command. Any
registry supported by
For example, to add the entire Nomad Pack Community Registry, use the
registry add command to download the registry.
$ nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry
To add a single pack from the registry, use the
$ nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry --target=nginx
To download a single pack or an entire registry at a specific version/SHA, use the
$ nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry --ref=v0.0.1
To remove a registry or pack from your local cache, use the
registry delete command.
This command also supports the
$ nomad-pack registry delete community
To update a registry, use the
add command and Nomad Pack will re-download the registry and replace the contents.
$ nomad-pack registry add default github.com/hashicorp/nomad-pack-community-registry
In this tutorial you learned how to interact with Nomad Pack in an advanced way. You learned how to generate a variable file, render a pack, use additional
run options, use the
plan command, and interact with Nomad Pack registries.
The official and community packs available to Nomad Pack are valuable because it allows you to quickly deploy apps using the best practices and leverage the knowledge of the Nomad community.
To learn how to write your own Nomad Packs or convert your existing Nomad job specifications into reusable packs, continue on to the Writing Custom Packs tutorial.