2016-10-28 00:36:26 +00:00
|
|
|
---
|
2020-02-06 23:45:31 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: artifact Stanza - Job Specification
|
|
|
|
sidebar_title: artifact
|
2016-10-28 00:36:26 +00:00
|
|
|
description: |-
|
|
|
|
The "artifact" stanza instructs Nomad to fetch and unpack a remote resource,
|
|
|
|
such as a file, tarball, or binary, and permits downloading artifacts from a
|
|
|
|
variety of locations using a URL as the input source.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `artifact` Stanza
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
<Placement groups={['job', 'group', 'task', 'artifact']} />
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
The `artifact` stanza instructs Nomad to fetch and unpack a remote resource,
|
|
|
|
such as a file, tarball, or binary. Nomad downloads artifacts using the popular
|
|
|
|
[`go-getter`][go-getter] library, which permits downloading artifacts from a
|
|
|
|
variety of locations using a URL as the input source.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
group "example" {
|
|
|
|
task "server" {
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.tar.gz"
|
2019-02-28 21:48:01 +00:00
|
|
|
destination = "local/some-directory"
|
2016-10-28 00:36:26 +00:00
|
|
|
options {
|
|
|
|
checksum = "md5:df6a4178aec9fbdc1d6d7e3634d1bc33"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-03-01 21:02:38 +00:00
|
|
|
Nomad supports downloading `http`, `https`, `git`, `hg` and `S3` artifacts. If
|
2017-07-31 22:53:05 +00:00
|
|
|
these artifacts are archived (`zip`, `tgz`, `bz2`, `xz`), they are
|
|
|
|
automatically unarchived before the starting the task.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
## `artifact` Parameters
|
|
|
|
|
2020-10-15 13:53:25 +00:00
|
|
|
- `destination` `(string: "local/")` - Specifies the directory path to
|
|
|
|
download the artifact, relative to the root of the [task's working
|
|
|
|
directory]. If omitted, the default value is to place the artifact in
|
|
|
|
`local/`. The destination is treated as a directory unless `mode` is set to
|
2020-11-04 14:59:19 +00:00
|
|
|
`file`. Source files will be downloaded into that directory path. For more
|
|
|
|
details on how the `destination` interacts with task drivers, see the
|
|
|
|
[Filesystem internals] documentation.
|
2017-07-06 03:57:11 +00:00
|
|
|
|
|
|
|
- `mode` `(string: "any")` - One of `any`, `file`, or `dir`. If set to `file`
|
|
|
|
the `destination` must be a file, not a directory. By default the
|
|
|
|
`destination` will be `local/<filename>`.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
- `options` `(map<string|string>: nil)` - Specifies configuration parameters to
|
|
|
|
fetch the artifact. The key-value pairs map directly to parameters appended to
|
|
|
|
the supplied `source` URL. Please see the [`go-getter`
|
2020-11-12 16:25:57 +00:00
|
|
|
documentation][go-getter] for a complete list of options and examples.
|
|
|
|
|
|
|
|
- `headers` `(map<string|string>: nil)` - Specifies HTTP headers to set when
|
|
|
|
fetching the artifact using `http` or `https` protocol. Please see the
|
|
|
|
[`go-getter` headers documentation][go-getter-headers] for more information.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2017-01-26 05:16:18 +00:00
|
|
|
- `source` `(string: <required>)` - Specifies the URL of the artifact to download.
|
2017-03-24 22:37:17 +00:00
|
|
|
See [`go-getter`][go-getter] for details.
|
2017-01-26 05:16:18 +00:00
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
## `artifact` Examples
|
|
|
|
|
|
|
|
The following examples only show the `artifact` stanzas. Remember that the
|
2016-10-31 00:41:03 +00:00
|
|
|
`artifact` stanza is only valid in the placements listed above.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
### Download File
|
|
|
|
|
|
|
|
This example downloads the artifact from the provided URL and places it in
|
2020-10-15 13:53:25 +00:00
|
|
|
`local/file.txt`. The `local/` path is relative to the [task's working
|
|
|
|
directory].
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.txt"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-11-12 16:25:57 +00:00
|
|
|
To set HTTP headers in the request for the source the optional `headers` field
|
|
|
|
can be configured.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.txt"
|
|
|
|
|
|
|
|
headers {
|
|
|
|
User-Agent = "nomad-[${NOMAD_JOB_ID}]-[${NOMAD_GROUP_NAME}]-[${NOMAD_TASK_NAME}]"
|
|
|
|
X-Nomad-Alloc = "${NOMAD_ALLOC_ID}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-03-22 20:50:45 +00:00
|
|
|
### Download using git
|
|
|
|
|
2017-07-17 18:41:50 +00:00
|
|
|
This example downloads the artifact from the provided GitHub URL and places it at
|
2017-03-22 20:50:45 +00:00
|
|
|
`local/repo`, as specified by the optional `destination` parameter.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "git::https://github.com/example/nomad-examples"
|
|
|
|
destination = "local/repo"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-05-08 16:54:44 +00:00
|
|
|
To download from private repo, sshkey needs to be set. The key must be
|
2017-03-22 20:50:45 +00:00
|
|
|
base64-encoded string. Run `base64 -w0 <file>`
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "git@github.com:example/nomad-examples"
|
|
|
|
destination = "local/repo"
|
|
|
|
options {
|
2017-05-16 15:01:10 +00:00
|
|
|
sshkey = "<string>"
|
2017-03-22 20:50:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
### Download and Unarchive
|
|
|
|
|
|
|
|
This example downloads and unarchives the result in `local/file`. Because the
|
|
|
|
source URL is an archive extension, Nomad will automatically decompress it:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.tar.gz"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
To disable automatic unarchiving, set the `archive` option to false:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.tar.gz"
|
|
|
|
options {
|
|
|
|
archive = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Download and Verify Checksums
|
|
|
|
|
|
|
|
This example downloads an artifact and verifies the resulting artifact's
|
|
|
|
checksum before proceeding. If the checksum is invalid, an error will be
|
|
|
|
returned.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://example.com/file.zip"
|
|
|
|
|
|
|
|
options {
|
|
|
|
checksum = "md5:df6a4178aec9fbdc1d6d7e3634d1bc33"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-07-06 03:57:11 +00:00
|
|
|
### Download from an S3-compatible Bucket
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
These examples download artifacts from Amazon S3. There are several different
|
|
|
|
types of [S3 bucket addressing][s3-bucket-addr] and [S3 region-specific
|
2017-07-06 03:57:11 +00:00
|
|
|
endpoints][s3-region-endpoints]. As of Nomad 0.6 non-Amazon S3-compatible
|
|
|
|
endpoints like [Minio] are supported, but you must explicitly set the "s3::"
|
|
|
|
prefix.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
This example uses path-based notation on a publicly-accessible bucket:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
2019-05-06 14:39:51 +00:00
|
|
|
source = "https://my-bucket-example.s3-us-west-2.amazonaws.com/my_app.tar.gz"
|
2016-10-28 00:36:26 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-03-11 11:55:37 +00:00
|
|
|
If a bucket requires authentication, you can avoid the use of credentials by
|
|
|
|
using [EC2 IAM instance profiles][iam-instance-profiles]. If this is not possible,
|
|
|
|
credentials may be supplied via the `options` parameter:
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
options {
|
|
|
|
aws_access_key_id = "<id>"
|
|
|
|
aws_access_key_secret = "<secret>"
|
|
|
|
aws_access_token = "<token>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
To force the S3-specific syntax, use the `s3::` prefix:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
2019-05-06 14:39:51 +00:00
|
|
|
source = "s3::https://my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz"
|
2016-10-28 00:36:26 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively you can use virtual hosted style:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
artifact {
|
|
|
|
source = "https://my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
[go-getter]: https://github.com/hashicorp/go-getter 'HashiCorp go-getter Library'
|
2020-11-12 16:25:57 +00:00
|
|
|
[go-getter-headers]: https://github.com/hashicorp/go-getter#headers 'HashiCorp go-getter Headers'
|
2020-02-06 23:45:31 +00:00
|
|
|
[minio]: https://www.minio.io/
|
|
|
|
[s3-bucket-addr]: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro 'Amazon S3 Bucket Addressing'
|
|
|
|
[s3-region-endpoints]: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region 'Amazon S3 Region Endpoints'
|
2020-03-11 11:55:37 +00:00
|
|
|
[iam-instance-profiles]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html 'EC2 IAM instance profiles'
|
2020-10-15 14:20:56 +00:00
|
|
|
[task's working directory]: /docs/runtime/environment#task-directories 'Task Directories'
|
2020-11-04 14:59:19 +00:00
|
|
|
[Filesystem internals]: /docs/internals/filesystem#templates-artifacts-and-dispatch-payloads
|