Skip to content

Commit 6b504bd

Browse files
committed
Update detailed usage doc
1 parent 6340149 commit 6b504bd

File tree

1 file changed

+150
-75
lines changed

1 file changed

+150
-75
lines changed

docs/detailed-usage.md

Lines changed: 150 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,149 @@
11
# Detailed Nomad Pack Usage
22

3-
This guide will go into detail on Nomad Pack usage and commands.
3+
This guide goes more deeply into detail on Nomad Pack usage and commands.
44

55
For an overview on basic use, see the repository [README](../README.md).
66

77
For more information on writing custom packs and registries, see the [Writing Packs Guide](./writing-packs.md)
8-
in the repository or in the [HashiCorp Learn Guides](https://learn.hashicorp.com/nomad).
9-
10-
<!-- TODO: Get the link to the writing own packs guide once it is up -->
8+
in the repository or the [Writing Custom Packs tutorial][writing-packs-tut] at developer.hashicorp.com.
119

1210
## Initialization
1311

14-
When first using Nomad Pack, a directory at `./.nomad/packs` will be created to store information about available packs and packs in use.
12+
The first time you run registry list, Nomad Pack will add a `nomad/packs`
13+
directory to your desktop user's cache directory—`$XDG_CACHE_DIR` on Linux,
14+
`~/Library/Caches` on macOS, `%AppData%` on Windows, etc. This folder stores
15+
information about cloned registries and their available packs.
1516

16-
During initializing, Nomad Pack downloads a default registry of packs from [https://github.com/hashicorp/nomad-pack-community- registry](https://github.com/hashicorp/nomad-pack-community-registry).
17+
During initializing, Nomad Pack downloads a default registry of packs from the
18+
[Nomad Pack community registry][].
1719

1820
The directory structure is as follows:
19-
20-
```
21-
.nomad
21+
<!-- TODO: this will need to be trued up based on PR -->
22+
```plaintext
23+
nomad
2224
└── packs
2325
├── <REGISTRY>
2426
├── <PACK-NAME>
2527
├── <PACK-REF>
2628
├── ...files containing pack contents...
2729
```
2830

29-
The contents of the `.nomad/pack` directory are needed for Nomad Pack to work properly,
30-
but users must not manually manage or change these files. Instead, use the `registry`
31-
commands.
31+
The `nomad/packs` directory's contents are managed by Nomad Pack. Users should
32+
not manually manage or change these files. Instead, use the `registry` commands.
3233

3334
## List
3435

3536
The `list` command lists the packs available to deploy.
3637

37-
```
38-
nomad-pack list
38+
```shell
39+
nomad-pack registry list
3940
```
4041

41-
This command reads from the `.nomad/packs` directory explained above.
42+
This command reads from the `nomad/packs` directory explained earlier.
4243

43-
## Adding new Registries and Packs
44+
## Add new registries and packs
4445

4546
The `registry` command includes several sub-commands for interacting with registries.
4647

4748
Custom registries can be added using the `registry add` command. Any `git` based
48-
registry supported by [`go-getter`](https://github.com/hashicorp/go-getter) should
49-
work.
49+
registry supported by [`go-getter`][] should work.
5050

51-
For instance, if you wanted to add the entire [Nomad Pack Community Registry](https://github.com/hashicorp/nomad-pack-community-registry),
51+
For instance, if you wanted to add the entire [Nomad Pack community registry][],
5252
you would run the following command to download the registry.
5353

54-
```
54+
```shell
5555
nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry
5656
```
5757

5858
To add a single pack from the registry, use the `--target` flag.
5959

60-
```
60+
```shell
6161
nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry --target=nginx
6262
```
6363

6464
To download single pack or an entire registry at a specific version/SHA, use the `--ref` flag.
6565

66-
```
66+
```shell
6767
nomad-pack registry add community github.com/hashicorp/nomad-pack-community-registry --ref=v0.0.1
6868
```
6969

7070
To remove a registry or pack from your local cache. Use the `registry delete` command.
7171
This command also supports the `--target` and `--ref` flags.
7272

73-
```
73+
```shell
7474
nomad-pack registry delete community
7575
```
7676

77-
## Render
77+
## Render a pack
7878

79-
At times, you may wish to use Nomad Pack to render jobspecs, but you will not want to immediately deploy these to Nomad.
79+
At times, you may wish to use Nomad Pack to render job specifications, but don't
80+
want to immediately deploy these to Nomad.
8081

81-
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.
82+
This can be useful when writing a pack, debugging deployments, integrating Nomad
83+
Pack into a CI/CD environment, or if you have another mechanism for handling
84+
deployments to Nomad.
8285

83-
The `render` command takes the `--var` and `--var-file` flags that `run` takes.
86+
Like the `run` command, the `render` command takes the `--var` and `--var-file`
87+
flags to provide variable values and overrides.
8488

85-
The `--to-dir` flag determines the directory where the rendered templates will be written.
89+
The `--to-dir` flag determines the directory where the rendered templates will
90+
be written.
8691

87-
The `--render-output-template` can be passed to additionally render the output template. Some output templates rely on a deployment for information. In these cases, the output template may not be rendered with all necessary information.
92+
Packs can create multiple output files. When running the `render` command
93+
without the `--to-dir` flag the `render` command outputs all the rendered pack
94+
templates to the terminal underneath their file names. When rendering a pack's
95+
output to disk, you should use the `--to-dir` flag.
8896

89-
```
97+
The `--render-output-template` can be passed to additionally render the output
98+
template. Some output templates rely on a deployment for information. In these
99+
cases, the output template may not be rendered with all necessary information.
100+
101+
```shell
90102
nomad-pack render hello-world --to-dir ./tmp --var greeting=hola --render-output-template
91103
```
92104

93-
## Run
105+
## Run a pack
94106

95107
To deploy the resources in a pack to Nomad, use the `run` command.
96108

97-
```
109+
```shell
98110
nomad-pack run hello-world
99111
```
100112

113+
<!-- TODO: awkward -->
101114
By passing a `--name` value into `run`, Nomad Pack deploys each resource in the
102115
pack with a metadata value for "pack name". If no name is given, the pack name
103116
is used by default.
104117

105118
This allows Nomad Pack to manage multiple deployments of the same pack.
106119

107-
```
120+
```shell
108121
nomad-pack run hello-world --name hola-mundo
109122
```
110123

111-
It is also possible to run a local pack directly from the pack directory by passing in the directory instead of the pack name.
124+
It's also possible to run a local pack directly from the pack directory by passing in the directory instead of the pack name.
112125

113-
```
126+
```shell
114127
nomad pack run .
115128
```
116129

117-
### Variables
130+
### Provide values for pack variables
118131

119132
Each pack defines a set of variables that can be provided by the user. Values for variables can be passed into the `run` command using the `--var` flag.
120133

121-
```
134+
```shell
122135
nomad-pack run hello-world --var greeting=hola
123136
```
124137

125138
Values can also be provided by passing in a variables file.
126139

127-
```
140+
```shell
128141
nomad-pack run hello-world -f ./my-variables.hcl
129142
```
130143

131144
These files can define overrides to the variables defined in the pack.
132145

133-
```
146+
```hcl
134147
docker_image = "hashicorp/hello-world"
135148
136149
app_count = 3
@@ -148,110 +161,172 @@ app_resources = {
148161

149162
To see the type and description of each variable, run the `info` command.
150163

151-
```
164+
```shell
152165
nomad-pack info hello-world
153166
```
154167

155-
## Plan
168+
## Plan a pack
156169

157170
If you do not want to immediately deploy the pack, but instead want details on how it will be deployed, run the `plan` command.
158171

159-
This invokes Nomad in a dry-run mode using the [Nomad Plan](https://www.nomadproject.io/api-docs/jobs#create-job-plan) API endpoint.
172+
This invokes Nomad in a dry-run mode using the Nomad's [Create Job Plan][nomad-plan] API endpoint.
160173

161-
```
174+
```shell
162175
nomad-pack plan hello-world
163176
```
164177

165178
By passing a `--name` value into plan, Nomad Pack will look for packs deployed with that name. If no name is provided, Nomad Pack uses the pack name by default.
166179

167-
```
180+
```shell
168181
nomad-pack plan hello-world --name hola-mundo
169182
```
170183

171184
The `plan` command takes the `--var` and `-f` flags like the `run` command.
172185

173-
```
186+
```shell
174187
nomad-pack plan hello-world --var greeting=hallo
175188
```
176189

177-
```
190+
```shell
178191
nomad-pack plan hello-world -f ./my-variables.hcl
179192
```
180193

181-
## Status
194+
## Get the status of running packs
195+
182196
If you want to see a list of the packs currently deployed (this may include packs that are stopped but not yet removed), run the `status` command.
183197

184-
```
198+
```shell
185199
nomad-pack status
186200
```
187201

188202
To see the status of jobs running in a specific pack, use the `status` command with the pack name.
189203

190-
```
204+
```shell
191205
nomad-pack status hello-world
192206
```
193207

194-
## Destroy
208+
## Stop a running pack
195209

196-
If you want to remove the resources deployed by a pack, run the `destroy` command with the pack name.
210+
To stop the jobs without completely removing them from Nomad completely, use the `stop` command:
197211

212+
```shell
213+
nomad-pack stop hola-mundo
198214
```
215+
216+
If you deployed the pack with a `--name` value, you must also provide the name
217+
you gave the pack. For instance, to stop a `hello-world` pack having the name
218+
`hola-mundo`, you would run the following command.
219+
220+
```shell
221+
nomad-pack stop hello-world --name hola-mundo
222+
```
223+
224+
When you have deployed a pack with variable overrides that override the job name,
225+
you must pass in those same overrides when stopping the pack. The `hello-world`
226+
pack allows you to override the Nomad job name and can be used to demonstrate
227+
this. If you deploy it with the following command.
228+
229+
```shell
230+
nomad-pack run hello-world --name hola-mundo --var job_name=spanish
231+
```
232+
233+
Running the following command stops the job instance named `spanish`.
234+
235+
```shell
236+
nomad-pack stop hello-world --name hola-mundo --var job_name=spanish
237+
```
238+
239+
It's also possible to deploy multiple instances of a pack using the same
240+
`--name` value but with different job names using variable overrides.
241+
For example, you can run the following commands, which will create two different
242+
jobs, one named "spanish" and one named "hola".
243+
244+
```shell
245+
nomad-pack run hello-world --name hola-mundo --var job_name=spanish
246+
nomad-pack run hello-world --name hola-mundo --var job_name=hola
247+
```
248+
249+
If you run the destroy command without including the variable overrides, Nomad
250+
Pack destroys both jobs, since by default it targets all jobs belonging to the
251+
specified pack and deployment name.
252+
253+
```shell
254+
# This stops both jobs: "spanish" and "hola"
255+
nomad-pack stop hello-world --name hola-mundo
256+
```
257+
258+
In this case, you must also include the variable overrides so that Nomad Pack
259+
targets the correct instance.
260+
261+
```shell
262+
# This stops the job named "spanish"
263+
nomad-pack stop hello-world --name hola-mundo --var job_name=spanish
264+
```
265+
266+
## Destroy a running pack
267+
268+
If you want to purge the resources deployed by a pack, run the `destroy` command with the pack name.
269+
270+
```shell
199271
nomad-pack destroy hello-world
200272
```
201273

202274
If you deployed the pack with a `--name` value, pass in the name you gave the pack. For instance, if you deployed with the command:
203275

204-
```
276+
```shell
205277
nomad-pack run hello-world --name hola-mundo
206278
```
207279

208280
You would destroy the contents of that pack with the command;
209281

210-
```
282+
```shell
211283
nomad-pack destroy hello-world --name hola-mundo
212284
```
213285

214-
If you deployed the pack with variable overrides that override the job name in a pack, pass in those same overrides. For example,
215-
if you deployed with the command:
286+
When you deploy a pack with variable overrides that override the job name, pass
287+
in those same overrides. The `hello-world` job is one such job. If you deploy
288+
it with the following command.
216289

217-
```
290+
```shell
218291
nomad-pack run hello-world --name hola-mundo --var job_name=spanish
219292
```
220293

221-
You would destroy the contents of that pack with the command:
294+
You would destroy a running instance of that pack with the following command.
222295

223-
```
296+
```shell
224297
nomad-pack destroy hello-world --name hola-mundo --var job_name=spanish
225298
```
226299

227-
It's possible to deploy multiple instances of a pack using the same `--name` value but with different job names using variable
228-
overrides. For example, you can run the following commands, which will create two jobs,
229-
one named "spanish" and one named "hola":
300+
It's also possible to deploy multiple instances of a pack using the same
301+
`--name` value but with different job names using variable overrides.
302+
For example, you can run the following commands, which will create two different
303+
jobs, one named "spanish" and one named "hola".
230304

231-
```
305+
```shell
232306
nomad-pack run hello-world --name hola-mundo --var job_name=spanish
233307
nomad-pack run hello-world --name hola-mundo --var job_name=hola
234308
```
235309

236-
If you run the destroy command without including the variable overrides, the command will destroy both jobs, since by default
237-
nomad pack will target all jobs belonging to the specified pack and deployment name.
238-
```
310+
If you run the destroy command without including the variable overrides, Nomad
311+
Pack destroys both jobs, since by default it targets all jobs belonging to the
312+
specified pack and deployment name.
313+
314+
```shell
239315
# This destroys both jobs: "spanish" and "hola"
240316
nomad-pack destroy hello-world --name hola-mundo
241317
```
242318

243-
If you only want to destroy one of the jobs, you need to include the variable overrides so nomad pack knows which job to target:
244-
```
319+
In this case, you must also include the variable overrides so that Nomad Pack
320+
targets the correct instance.
321+
322+
```shell
245323
# This destroys the job named "spanish"
246324
nomad-pack destroy hello-world --name hola-mundo --var job_name=spanish
247325
```
248326

249-
## Stop
250-
251-
To stop the jobs without completely removing them from Nomad completely, use the `stop` command:
252-
253-
```
254-
nomad-pack stop hola-mundo
255-
```
256-
257327
N.B. The `destroy` command is an alias for `stop --purge`.
328+
329+
[Nomad Pack community registry]: https://github.com/hashicorp/nomad-pack-community-registry
330+
[`go-getter`]: https://github.com/hashicorp/go-getter
331+
[nomad-plan]: https://www.nomadproject.io/api-docs/jobs#create-job-plan
332+
[writing-packs-tut]: https://developer.hashicorp.com/nomad/tutorials/job-specifications/nomad-pack-writing-packs

0 commit comments

Comments
 (0)