github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/website/source/api/json-jobs.html.md (about) 1 --- 2 layout: api 3 page_title: JSON Job Specification - HTTP API 4 sidebar_current: api-json-jobs 5 description: |- 6 Jobs can also be specified via the HTTP API using a JSON format. This guide 7 discusses the job specification in JSON format. 8 --- 9 10 # JSON Job Specification 11 12 This guide covers the JSON syntax for submitting jobs to Nomad. A useful command 13 for generating valid JSON versions of HCL jobs is: 14 15 ```shell 16 $ nomad run -output my-job.nomad 17 ``` 18 19 ## Syntax 20 21 Below is the JSON representation of the job outputted by `$ nomad init`: 22 23 ```json 24 { 25 "Job": { 26 "ID": "example", 27 "Name": "example", 28 "Type": "service", 29 "Priority": 50, 30 "Datacenters": [ 31 "dc1" 32 ], 33 "TaskGroups": [{ 34 "Name": "cache", 35 "Count": 1, 36 "Tasks": [{ 37 "Name": "redis", 38 "Driver": "docker", 39 "User": "", 40 "Config": { 41 "image": "redis:3.2", 42 "port_map": [{ 43 "db": 6379 44 }] 45 }, 46 "Services": [{ 47 "Id": "", 48 "Name": "global-redis-check", 49 "Tags": [ 50 "global", 51 "cache" 52 ], 53 "PortLabel": "db", 54 "AddressMode": "", 55 "Checks": [{ 56 "Id": "", 57 "Name": "alive", 58 "Type": "tcp", 59 "Command": "", 60 "Args": null, 61 "Header": {}, 62 "Method": "", 63 "Path": "", 64 "Protocol": "", 65 "PortLabel": "", 66 "Interval": 10000000000, 67 "Timeout": 2000000000, 68 "InitialStatus": "", 69 "TLSSkipVerify": false, 70 "CheckRestart": { 71 "Limit": 3, 72 "Grace": "30s", 73 "IgnoreWarnings": false 74 } 75 }] 76 }], 77 "Resources": { 78 "CPU": 500, 79 "MemoryMB": 256, 80 "Networks": [{ 81 "Device": "", 82 "CIDR": "", 83 "IP": "", 84 "MBits": 10, 85 "DynamicPorts": [{ 86 "Label": "db", 87 "Value": 0 88 }] 89 }] 90 }, 91 "Leader": false 92 }], 93 "RestartPolicy": { 94 "Interval": 300000000000, 95 "Attempts": 10, 96 "Delay": 25000000000, 97 "Mode": "delay" 98 }, 99 "EphemeralDisk": { 100 "SizeMB": 300 101 } 102 }], 103 "Update": { 104 "MaxParallel": 1, 105 "MinHealthyTime": 10000000000, 106 "HealthyDeadline": 180000000000, 107 "AutoRevert": false, 108 "Canary": 0 109 } 110 } 111 } 112 ``` 113 114 The example JSON could be submitted as a job using the following: 115 116 ```text 117 $ curl -XPUT @d example.json http://127.0.0.1:4646/v1/job/example 118 { 119 "EvalID": "5d6ded54-0b2a-8858-6583-be5f476dec9d", 120 "EvalCreateIndex": 12, 121 "JobModifyIndex": 11, 122 "Warnings": "", 123 "Index": 12, 124 "LastContact": 0, 125 "KnownLeader": false 126 } 127 ``` 128 129 ## Syntax Reference 130 131 Following is a syntax reference for the possible keys that are supported and 132 their default values if any for each type of object. 133 134 ### Job 135 136 The `Job` object supports the following keys: 137 138 - `AllAtOnce` - Controls whether the scheduler can make partial placements if 139 optimistic scheduling resulted in an oversubscribed node. This does not 140 control whether all allocations for the job, where all would be the desired 141 count for each task group, must be placed atomically. This should only be 142 used for special circumstances. Defaults to `false`. 143 144 - `Constraints` - A list to define additional constraints where a job can be 145 run. See the constraint reference for more details. 146 147 - `Datacenters` - A list of datacenters in the region which are eligible 148 for task placement. This must be provided, and does not have a default. 149 150 - `TaskGroups` - A list to define additional task groups. See the task group 151 reference for more details. 152 153 - `Meta` - Annotates the job with opaque metadata. 154 155 - `Namespace` - The namespace to execute the job in, defaults to "default". 156 Values other than default are not allowed in non-Enterprise versions of Nomad. 157 158 - `ParameterizedJob` - Specifies the job as a parameterized job such that it can 159 be dispatched against. The `ParamaterizedJob` object supports the following 160 attributes: 161 162 - `MetaOptional` - Specifies the set of metadata keys that may be provided 163 when dispatching against the job as a string array. 164 165 - `MetaRequired` - Specifies the set of metadata keys that must be provided 166 when dispatching against the job as a string array. 167 168 - `Payload` - Specifies the requirement of providing a payload when 169 dispatching against the parameterized job. The options for this field are 170 "optional", "required" and "forbidden". The default value is "optional". 171 172 - `Payload` - The payload may not be set when submitting a job but may appear in 173 a dispatched job. The `Payload` will be a base64 encoded string containing the 174 payload that the job was dispatched with. The `payload` has a **maximum size 175 of 16 KiB**. 176 177 - `Priority` - Specifies the job priority which is used to prioritize 178 scheduling and access to resources. Must be between 1 and 100 inclusively, 179 and defaults to 50. 180 181 - `Region` - The region to run the job in, defaults to "global". 182 183 - `Type` - Specifies the job type and switches which scheduler 184 is used. Nomad provides the `service`, `system` and `batch` schedulers, 185 and defaults to `service`. To learn more about each scheduler type visit 186 [here](/docs/runtime/schedulers.html) 187 188 - `Update` - Specifies an update strategy to be applied to all task groups 189 within the job. When specified both at the job level and the task group level, 190 the update blocks are merged with the task group's taking precedence. For more 191 details on the update stanza, please see below. 192 193 - `Periodic` - `Periodic` allows the job to be scheduled at fixed times, dates 194 or intervals. The periodic expression is always evaluated in the UTC 195 timezone to ensure consistent evaluation when Nomad Servers span multiple 196 time zones. The `Periodic` object is optional and supports the following attributes: 197 198 - `Enabled` - `Enabled` determines whether the periodic job will spawn child 199 jobs. 200 201 - `TimeZone` - Specifies the time zone to evaluate the next launch interval 202 against. This is useful when wanting to account for day light savings in 203 various time zones. The time zone must be parsable by Golang's 204 [LoadLocation](https://golang.org/pkg/time/#LoadLocation). The default is 205 UTC. 206 207 - `SpecType` - `SpecType` determines how Nomad is going to interpret the 208 periodic expression. `cron` is the only supported `SpecType` currently. 209 210 - `Spec` - A cron expression configuring the interval the job is launched 211 at. Supports predefined expressions such as "@daily" and "@weekly" See 212 [here](https://github.com/gorhill/cronexpr#implementation) for full 213 documentation of supported cron specs and the predefined expressions. 214 215 - <a id="prohibit_overlap">`ProhibitOverlap`</a> - `ProhibitOverlap` can 216 be set to true to enforce that the periodic job doesn't spawn a new 217 instance of the job if any of the previous jobs are still running. It is 218 defaulted to false. 219 220 An example `periodic` block: 221 222 ```json 223 { 224 "Periodic": { 225 "Spec": "*/15 - *", 226 "TimeZone": "Europe/Berlin", 227 "SpecType": "cron", 228 "Enabled": true, 229 "ProhibitOverlap": true 230 } 231 } 232 ``` 233 234 ### Task Group 235 236 `TaskGroups` is a list of `TaskGroup` objects, each supports the following 237 attributes: 238 239 - `Constraints` - This is a list of `Constraint` objects. See the constraint 240 reference for more details. 241 242 - `Count` - Specifies the number of the task groups that should 243 be running. Must be non-negative, defaults to one. 244 245 - `Meta` - A key-value map that annotates the task group with opaque metadata. 246 247 - `Name` - The name of the task group. Must be specified. 248 249 - `RestartPolicy` - Specifies the restart policy to be applied to tasks in this group. 250 If omitted, a default policy for batch and non-batch jobs is used based on the 251 job type. See the [restart policy reference](#restart_policy) for more details. 252 253 - `EphemeralDisk` - Specifies the group's ephemeral disk requirements. See the 254 [ephemeral disk reference](#ephemeral_disk) for more details. 255 256 - `Update` - Specifies an update strategy to be applied to all task groups 257 within the job. When specified both at the job level and the task group level, 258 the update blocks are merged with the task group's taking precedence. For more 259 details on the update stanza, please see below. 260 261 - `Tasks` - A list of `Task` object that are part of the task group. 262 263 ### Task 264 265 The `Task` object supports the following keys: 266 267 - `Artifacts` - `Artifacts` is a list of `Artifact` objects which define 268 artifacts to be downloaded before the task is run. See the artifacts 269 reference for more details. 270 271 - `Config` - A map of key-value configuration passed into the driver 272 to start the task. The details of configurations are specific to 273 each driver. 274 275 - `Constraints` - This is a list of `Constraint` objects. See the constraint 276 reference for more details. 277 278 - `DispatchPayload` - Configures the task to have access to dispatch payloads. 279 The `DispatchPayload` object supports the following attributes: 280 281 - `File` - Specifies the file name to write the content of dispatch payload 282 to. The file is written relative to the task's local directory. 283 284 - `Driver` - Specifies the task driver that should be used to run the 285 task. See the [driver documentation](/docs/drivers/index.html) for what 286 is available. Examples include `docker`, `qemu`, `java`, and `exec`. 287 288 - `Env` - A map of key-value representing environment variables that 289 will be passed along to the running process. Nomad variables are 290 interpreted when set in the environment variable values. See the table of 291 interpreted variables [here](/docs/runtime/interpolation.html). 292 293 For example the below environment map will be reinterpreted: 294 295 ```json 296 { 297 "Env": { 298 "NODE_CLASS" : "${nomad.class}" 299 } 300 } 301 ``` 302 303 - `KillSignal` - Specifies a configurable kill signal for a task, where the 304 default is SIGINT. Note that this is only supported for drivers which accept 305 sending signals (currently `docker`, `exec`, `raw_exec`, and `java` drivers). 306 307 - `KillTimeout` - `KillTimeout` is a time duration in nanoseconds. It can be 308 used to configure the time between signaling a task it will be killed and 309 actually killing it. Drivers first sends a task the `SIGINT` signal and then 310 sends `SIGTERM` if the task doesn't die after the `KillTimeout` duration has 311 elapsed. The default `KillTimeout` is 5 seconds. 312 313 - `Leader` - Specifies whether the task is the leader task of the task group. If 314 set to true, when the leader task completes, all other tasks within the task 315 group will be gracefully shutdown. 316 317 - `LogConfig` - This allows configuring log rotation for the `stdout` and `stderr` 318 buffers of a Task. See the log rotation reference below for more details. 319 320 - `Meta` - Annotates the task group with opaque metadata. 321 322 - `Name` - The name of the task. This field is required. 323 324 - `Resources` - Provides the resource requirements of the task. 325 See the resources reference for more details. 326 327 - `Services` - `Services` is a list of `Service` objects. Nomad integrates with 328 Consul for service discovery. A `Service` object represents a routable and 329 discoverable service on the network. Nomad automatically registers when a task 330 is started and de-registers it when the task transitions to the dead state. 331 [Click here](/docs/service-discovery/index.html) to learn more about 332 services. Below is the fields in the `Service` object: 333 334 - `Name`: An explicit name for the Service. Nomad will replace `${JOB}`, 335 `${TASKGROUP}` and `${TASK}` by the name of the job, task group or task, 336 respectively. `${BASE}` expands to the equivalent of 337 `${JOB}-${TASKGROUP}-${TASK}`, and is the default name for a Service. 338 Each service defined for a given task must have a distinct name, so if 339 a task has multiple services only one of them can use the default name 340 and the others must be explicitly named. Names must adhere to 341 [RFC-1123 ยง2.1](https://tools.ietf.org/html/rfc1123#section-2) and are 342 limited to alphanumeric and hyphen characters (i.e. `[a-z0-9\-]`), and be 343 less than 64 characters in length. 344 345 - `Tags`: A list of string tags associated with this Service. String 346 interpolation is supported in tags. 347 348 - `PortLabel`: `PortLabel` is an optional string and is used to associate 349 a port with the service. If specified, the port label must match one 350 defined in the resources block. This could be a label of either a 351 dynamic or a static port. 352 353 - `AddressMode`: Specifies what address (host or driver-specific) this 354 service should advertise. This setting is supported in Docker since 355 Nomad 0.6 and rkt since Nomad 0.7. Valid options are: 356 357 - `auto` - Allows the driver to determine whether the host or driver 358 address should be used. Defaults to `host` and only implemented by 359 Docker. If you use a Docker network plugin such as weave, Docker will 360 automatically use its address. 361 362 - `driver` - Use the IP specified by the driver, and the port specified 363 in a port map. A numeric port may be specified since port maps aren't 364 required by all network plugins. Useful for advertising SDN and 365 overlay network addresses. Task will fail if driver network cannot be 366 determined. Only implemented for Docker and rkt. 367 368 - `host` - Use the host IP and port. 369 370 - `Checks`: `Checks` is an array of check objects. A check object defines a 371 health check associated with the service. Nomad supports the `script`, 372 `http` and `tcp` Consul Checks. Script checks are not supported for the 373 qemu driver since the Nomad client doesn't have access to the file system 374 of a task using the Qemu driver. 375 376 - `Type`: This indicates the check types supported by Nomad. Valid 377 options are currently `script`, `http` and `tcp`. 378 379 - `Name`: The name of the health check. 380 381 - `AddressMode`: Same as `AddressMode` on `Service`. Unlike services, 382 checks do not have an `auto` address mode as there's no way for 383 Nomad to know which is the best address to use for checks. Consul 384 needs access to the address for any HTTP or TCP checks. Added in 385 Nomad 0.7.1. Unlike `PortLabel`, this setting is *not* inherited 386 from the `Service`. 387 388 - `PortLabel`: Specifies the label of the port on which the check will 389 be performed. Note this is the _label_ of the port and not the port 390 number unless `AddressMode: "driver"`. The port label must match one 391 defined in the Network stanza. If a port value was declared on the 392 `Service`, this will inherit from that value if not supplied. If 393 supplied, this value takes precedence over the `Service.PortLabel` 394 value. This is useful for services which operate on multiple ports. 395 `http` and `tcp` checks require a port while `script` checks do not. 396 Checks will use the host IP and ports by default. In Nomad 0.7.1 or 397 later numeric ports may be used if `AddressMode: "driver"` is set on 398 the check. 399 400 - `Header`: Headers for HTTP checks. Should be an object where the 401 values are an array of values. Headers will be written once for each 402 value. 403 404 - `Interval`: This indicates the frequency of the health checks that 405 Consul will perform. 406 407 - `Timeout`: This indicates how long Consul will wait for a health 408 check query to succeed. 409 410 - `Method`: The HTTP method to use for HTTP checks. Defaults to GET. 411 412 - `Path`: The path of the HTTP endpoint which Consul will query to query 413 the health of a service if the type of the check is `http`. Nomad 414 will add the IP of the service and the port, users are only required 415 to add the relative URL of the health check endpoint. 416 417 - `Protocol`: This indicates the protocol for the HTTP checks. Valid 418 options are `http` and `https`. We default it to `http`. 419 420 - `Command`: This is the command that the Nomad client runs for doing 421 script based health check. 422 423 - `Args`: Additional arguments to the `command` for script based health 424 checks. 425 426 - `TLSSkipVerify`: If true, Consul will not attempt to verify the 427 certificate when performing HTTPS checks. Requires Consul >= 0.7.2. 428 429 - `CheckRestart`: `CheckRestart` is an object which enables 430 restarting of tasks based upon Consul health checks. 431 432 - `Limit`: The number of unhealthy checks allowed before the 433 service is restarted. Defaults to `0` which disables 434 health-based restarts. 435 436 - `Grace`: The duration to wait after a task starts or restarts 437 before counting unhealthy checks count against the limit. 438 Defaults to "1s". 439 440 - `IgnoreWarnings`: Treat checks that are warning as passing. 441 Defaults to false which means warnings are considered unhealthy. 442 443 - `ShutdownDelay` - Specifies the duration to wait when killing a task between 444 removing it from Consul and sending it a shutdown signal. Ideally services 445 would fail healthchecks once they receive a shutdown signal. Alternatively 446 `ShutdownDelay` may be set to give in flight requests time to complete before 447 shutting down. 448 449 - `Templates` - Specifies the set of [`Template`](#template) objects to render for the task. 450 Templates can be used to inject both static and dynamic configuration with 451 data populated from environment variables, Consul and Vault. 452 453 - `User` - Set the user that will run the task. It defaults to the same user 454 the Nomad client is being run as. This can only be set on Linux platforms. 455 456 ### Resources 457 458 The `Resources` object supports the following keys: 459 460 - `CPU` - The CPU required in MHz. 461 462 - `IOPS` - The number of IOPS required given as a weight between 10-1000. 463 464 - `MemoryMB` - The memory required in MB. 465 466 - `Networks` - A list of network objects. 467 468 The Network object supports the following keys: 469 470 - `MBits` - The number of MBits in bandwidth required. 471 472 Nomad can allocate two types of ports to a task - Dynamic and Static/Reserved 473 ports. A network object allows the user to specify a list of `DynamicPorts` and 474 `ReservedPorts`. Each object supports the following attributes: 475 476 - `Value` - The port number for static ports. If the port is dynamic, then this 477 attribute is ignored. 478 - `Label` - The label to annotate a port so that it can be referred in the 479 service discovery block or environment variables. 480 481 <a id="ephemeral_disk"></a> 482 483 ### Ephemeral Disk 484 485 The `EphemeralDisk` object supports the following keys: 486 487 - `Migrate` - Specifies that the Nomad client should make a best-effort attempt 488 to migrate the data from a remote machine if placement cannot be made on the 489 original node. During data migration, the task will block starting until the 490 data migration has completed. Value is a boolean and the default is false. 491 492 - `SizeMB` - Specifies the size of the ephemeral disk in MB. Default is 300. 493 494 - `Sticky` - Specifies that Nomad should make a best-effort attempt to place the 495 updated allocation on the same machine. This will move the `local/` and 496 `alloc/data` directories to the new allocation. Value is a boolean and the 497 default is false. 498 499 <a id="restart_policy"></a> 500 501 ### Restart Policy 502 503 The `RestartPolicy` object supports the following keys: 504 505 - `Attempts` - `Attempts` is the number of restarts allowed in an `Interval`. 506 507 - `Interval` - `Interval` is a time duration that is specified in nanoseconds. 508 The `Interval` begins when the first task starts and ensures that only 509 `Attempts` number of restarts happens within it. If more than `Attempts` 510 number of failures happen, behavior is controlled by `Mode`. 511 512 - `Delay` - A duration to wait before restarting a task. It is specified in 513 nanoseconds. A random jitter of up to 25% is added to the delay. 514 515 - `Mode` - `Mode` is given as a string and controls the behavior when the task 516 fails more than `Attempts` times in an `Interval`. Possible values are listed 517 below: 518 519 - `delay` - `delay` will delay the next restart until the next `Interval` is 520 reached. 521 522 - `fail` - `fail` will not restart the task again. 523 524 ### Update 525 526 Specifies the task group update strategy. When omitted, rolling updates are 527 disabled. The update stanza can be specified at the job or task group level. 528 When specified at the job, the update stanza is inherited by all task groups. 529 When specified in both the job and in a task group, the stanzas are merged with 530 the task group's taking precedence. The `Update` object supports the following 531 attributes: 532 533 - `MaxParallel` - `MaxParallel` is given as an integer value and specifies 534 the number of tasks that can be updated at the same time. 535 536 - `HealthCheck` - Specifies the mechanism in which allocations health is 537 determined. The potential values are: 538 539 - "checks" - Specifies that the allocation should be considered healthy when 540 all of its tasks are running and their associated [checks][] are healthy, 541 and unhealthy if any of the tasks fail or not all checks become healthy. 542 This is a superset of "task_states" mode. 543 544 - "task_states" - Specifies that the allocation should be considered healthy 545 when all its tasks are running and unhealthy if tasks fail. 546 547 - "manual" - Specifies that Nomad should not automatically determine health 548 and that the operator will specify allocation health using the [HTTP 549 API](/api/deployments.html#set-allocation-health-in-deployment). 550 551 - `MinHealthyTime` - Specifies the minimum time the allocation must be in the 552 healthy state before it is marked as healthy and unblocks further allocations 553 from being updated. This is specified using a label suffix like "30s" or 554 "15m". 555 556 - `HealthyDeadline` - Specifies the deadline in which the allocation must be 557 marked as healthy after which the allocation is automatically transitioned to 558 unhealthy. This is specified using a label suffix like "2m" or "1h". 559 560 - `AutoRevert` - Specifies if the job should auto-revert to the last stable job 561 on deployment failure. A job is marked as stable if all the allocations as 562 part of its deployment were marked healthy. 563 564 - `Canary` - Specifies that changes to the job that would result in destructive 565 updates should create the specified number of canaries without stopping any 566 previous allocations. Once the operator determines the canaries are healthy, 567 they can be promoted which unblocks a rolling update of the remaining 568 allocations at a rate of `max_parallel`. 569 570 - `Stagger` - Specifies the delay between migrating allocations off nodes marked 571 for draining. This is specified using a label suffix like "30s" or "1h". 572 573 An example `Update` block: 574 575 ```json 576 { 577 "Update": { 578 "MaxParallel": 3, 579 "HealthCheck": "checks", 580 "MinHealthyTime": 15000000000, 581 "HealthyDeadline": 180000000000, 582 "AutoRevert": false, 583 "Canary": 1 584 } 585 } 586 ``` 587 588 ### Constraint 589 590 The `Constraint` object supports the following keys: 591 592 - `LTarget` - Specifies the attribute to examine for the 593 constraint. See the table of attributes [here](/docs/runtime/interpolation.html#interpreted_node_vars). 594 595 - `RTarget` - Specifies the value to compare the attribute against. 596 This can be a literal value, another attribute or a regular expression if 597 the `Operator` is in "regexp" mode. 598 599 - `Operand` - Specifies the test to be performed on the two targets. It takes on the 600 following values: 601 602 - `regexp` - Allows the `RTarget` to be a regular expression to be matched. 603 604 - `set_contains` - Allows the `RTarget` to be a comma separated list of values 605 that should be contained in the LTarget's value. 606 607 - `distinct_hosts` - If set, the scheduler will not co-locate any task groups on the same 608 machine. This can be specified as a job constraint which applies the 609 constraint to all task groups in the job, or as a task group constraint which 610 scopes the effect to just that group. The constraint may not be 611 specified at the task level. 612 613 Placing the constraint at both the job level and at the task group level is 614 redundant since when placed at the job level, the constraint will be applied 615 to all task groups. When specified, `LTarget` and `RTarget` should be 616 omitted. 617 618 - `distinct_property` - If set, the scheduler selects nodes that have a 619 distinct value of the specified property. The `RTarget` specifies how 620 many allocations are allowed to share the value of a property. The 621 `RTarget` must be 1 or greater and if omitted, defaults to 1. This can 622 be specified as a job constraint which applies the constraint to all 623 task groups in the job, or as a task group constraint which scopes the 624 effect to just that group. The constraint may not be specified at the 625 task level. 626 627 Placing the constraint at both the job level and at the task group level is 628 redundant since when placed at the job level, the constraint will be applied 629 to all task groups. When specified, `LTarget` should be the property 630 that should be distinct and and `RTarget` should be omitted. 631 632 - Comparison Operators - `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The 633 ordering is compared lexically. 634 635 ### Log Rotation 636 637 The `LogConfig` object configures the log rotation policy for a task's `stdout` and 638 `stderr`. The `LogConfig` object supports the following attributes: 639 640 - `MaxFiles` - The maximum number of rotated files Nomad will retain for 641 `stdout` and `stderr`, each tracked individually. 642 643 - `MaxFileSizeMB` - The size of each rotated file. The size is specified in 644 `MB`. 645 646 If the amount of disk resource requested for the task is less than the total 647 amount of disk space needed to retain the rotated set of files, Nomad will return 648 a validation error when a job is submitted. 649 650 ```json 651 { 652 "LogConfig": { 653 "MaxFiles": 3, 654 "MaxFileSizeMB": 10 655 } 656 } 657 ``` 658 659 In the above example we have asked Nomad to retain 3 rotated files for both 660 `stderr` and `stdout` and size of each file is 10 MB. The minimum disk space that 661 would be required for the task would be 60 MB. 662 663 ### Artifact 664 665 Nomad downloads artifacts using 666 [`go-getter`](https://github.com/hashicorp/go-getter). The `go-getter` library 667 allows downloading of artifacts from various sources using a URL as the input 668 source. The key-value pairs given in the `options` block map directly to 669 parameters appended to the supplied `source` URL. These are then used by 670 `go-getter` to appropriately download the artifact. `go-getter` also has a CLI 671 tool to validate its URL and can be used to check if the Nomad `artifact` is 672 valid. 673 674 Nomad allows downloading `http`, `https`, and `S3` artifacts. If these artifacts 675 are archives (zip, tar.gz, bz2, etc.), these will be unarchived before the task 676 is started. 677 678 The `Artifact` object supports the following keys: 679 680 - `GetterSource` - The path to the artifact to download. 681 682 - `RelativeDest` - An optional path to download the artifact into relative to the 683 root of the task's directory. If omitted, it will default to `local/`. 684 685 - `GetterOptions` - A `map[string]string` block of options for `go-getter`. 686 Full documentation of supported options are available 687 [here](https://github.com/hashicorp/go-getter/tree/ef5edd3d8f6f482b775199be2f3734fd20e04d4a#protocol-specific-options-1). 688 An example is given below: 689 690 ```json 691 { 692 "GetterOptions": { 693 "checksum": "md5:c4aa853ad2215426eb7d70a21922e794", 694 695 "aws_access_key_id": "<id>", 696 "aws_access_key_secret": "<secret>", 697 "aws_access_token": "<token>" 698 } 699 } 700 ``` 701 702 An example of downloading and unzipping an archive is as simple as: 703 704 ```json 705 { 706 "Artifacts": [ 707 { 708 "GetterSource": "https://example.com/my.zip", 709 "GetterOptions": { 710 "checksum": "md5:7f4b3e3b4dd5150d4e5aaaa5efada4c3" 711 } 712 } 713 ] 714 } 715 ``` 716 717 #### S3 examples 718 719 S3 has several different types of addressing and more detail can be found 720 [here](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro) 721 722 S3 region specific endpoints can be found 723 [here](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) 724 725 Path based style: 726 727 ```json 728 { 729 "Artifacts": [ 730 { 731 "GetterSource": "https://s3-us-west-2.amazonaws.com/my-bucket-example/my_app.tar.gz", 732 } 733 ] 734 } 735 ``` 736 737 or to override automatic detection in the URL, use the S3-specific syntax 738 739 ```json 740 { 741 "Artifacts": [ 742 { 743 "GetterSource": "s3::https://s3-eu-west-1.amazonaws.com/my-bucket-example/my_app.tar.gz", 744 } 745 ] 746 } 747 ``` 748 749 Virtual hosted based style 750 751 ```json 752 { 753 "Artifacts": [ 754 { 755 "GetterSource": "my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz", 756 } 757 ] 758 } 759 ``` 760 761 ### Template 762 763 The `Template` block instantiates an instance of a template renderer. This 764 creates a convenient way to ship configuration files that are populated from 765 environment variables, Consul data, Vault secrets, or just general 766 configurations within a Nomad task. 767 768 Nomad utilizes a tool called [Consul Template][ct]. Since Nomad v0.5.3, the 769 template can reference [Nomad's runtime environment variables][env]. For a full 770 list of the API template functions, please refer to the [Consul Template 771 README][ct]. 772 773 774 `Template` object supports following attributes: 775 776 - `ChangeMode` - Specifies the behavior Nomad should take if the rendered 777 template changes. The default value is `"restart"`. The possible values are: 778 779 - `"noop"` - take no action (continue running the task) 780 - `"restart"` - restart the task 781 - `"signal"` - send a configurable signal to the task 782 783 - `ChangeSignal` - Specifies the signal to send to the task as a string like 784 "SIGUSR1" or "SIGINT". This option is required if the `ChangeMode` is 785 `signal`. 786 787 - `DestPath` - Specifies the location where the resulting template should be 788 rendered, relative to the task directory. 789 790 - `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath` 791 or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller 792 templates, but we recommend using `SourcePath` for larger templates. 793 794 - `Envvars` - Specifies the template should be read back as environment 795 variables for the task. 796 797 - `LeftDelim` - Specifies the left delimiter to use in the template. The default 798 is "{{" for some templates, it may be easier to use a different delimiter that 799 does not conflict with the output file itself. 800 801 - `Perms` - Specifies the rendered template's permissions. File permissions are 802 given as octal of the Unix file permissions rwxrwxrwx. 803 804 - `RightDelim` - Specifies the right delimiter to use in the template. The default 805 is "}}" for some templates, it may be easier to use a different delimiter that 806 does not conflict with the output file itself. 807 808 - `SourcePath` - Specifies the path to the template to be rendered. `SourcePath` 809 is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched 810 using an [`Artifact`](#artifact) resource. The template must exist on the 811 machine prior to starting the task; it is not possible to reference a template 812 inside of a Docker container, for example. 813 814 - `Splay` - Specifies a random amount of time to wait between 0 ms and the given 815 splay value before invoking the change mode. Should be specified in 816 nanoseconds. 817 818 - `VaultGrace` - Specifies the grace period between lease renewal and secret 819 re-acquisition. When renewing a secret, if the remaining lease is less than or 820 equal to the configured grace, the template will request a new credential. 821 This prevents Vault from revoking the secret at its expiration and the task 822 having a stale secret. If the grace is set to a value that is higher than your 823 default TTL or max TTL, the template will always read a new secret. If the 824 task defines several templates, the `vault_grace` will be set to the lowest 825 value across all the templates. 826 827 ```json 828 { 829 "Templates": [ 830 { 831 "SourcePath": "local/config.conf.tpl", 832 "DestPath": "local/config.conf", 833 "EmbeddedTmpl": "", 834 "ChangeMode": "signal", 835 "ChangeSignal": "SIGUSR1", 836 "Splay": 5000000000 837 } 838 ] 839 } 840 ``` 841 842 [ct]: https://github.com/hashicorp/consul-template "Consul Template by HashiCorp" 843 [env]: /docs/runtime/environment.html "Nomad Runtime Environment"