github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/job-specification/artifact.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: artifact Stanza - Job Specification
     4  sidebar_title: artifact
     5  description: |-
     6    The "artifact" stanza instructs Nomad to fetch and unpack a remote resource,
     7    such as a file, tarball, or binary, and permits downloading artifacts from a
     8    variety of locations using a URL as the input source.
     9  ---
    10  
    11  # `artifact` Stanza
    12  
    13  <Placement groups={['job', 'group', 'task', 'artifact']} />
    14  
    15  The `artifact` stanza instructs Nomad to fetch and unpack a remote resource,
    16  such as a file, tarball, or binary. Nomad downloads artifacts using the popular
    17  [`go-getter`][go-getter] library, which permits downloading artifacts from a
    18  variety of locations using a URL as the input source.
    19  
    20  ```hcl
    21  job "docs" {
    22    group "example" {
    23      task "server" {
    24        artifact {
    25          source      = "https://example.com/file.tar.gz"
    26          destination = "local/some-directory"
    27          options {
    28            checksum = "md5:df6a4178aec9fbdc1d6d7e3634d1bc33"
    29          }
    30        }
    31      }
    32    }
    33  }
    34  ```
    35  
    36  Nomad supports downloading `http`, `https`, `git`, `hg` and `S3` artifacts. If
    37  these artifacts are archived (`zip`, `tgz`, `bz2`, `xz`), they are
    38  automatically unarchived before the starting the task.
    39  
    40  ## `artifact` Parameters
    41  
    42  - `destination` `(string: "local/")` - Specifies the directory path to download
    43    the artifact, relative to the root of the task's directory. If omitted, the
    44    default value is to place the artifact in `local/`. The destination is treated
    45    as a directory unless `mode` is set to `file`. Source files will be downloaded
    46    into that directory path.
    47  
    48  - `mode` `(string: "any")` - One of `any`, `file`, or `dir`. If set to `file`
    49    the `destination` must be a file, not a directory. By default the
    50    `destination` will be `local/<filename>`.
    51  
    52  - `options` `(map<string|string>: nil)` - Specifies configuration parameters to
    53    fetch the artifact. The key-value pairs map directly to parameters appended to
    54    the supplied `source` URL. Please see the [`go-getter`
    55    documentation][go-getter] for a complete list of options and examples
    56  
    57  - `source` `(string: <required>)` - Specifies the URL of the artifact to download.
    58    See [`go-getter`][go-getter] for details.
    59  
    60  ## `artifact` Examples
    61  
    62  The following examples only show the `artifact` stanzas. Remember that the
    63  `artifact` stanza is only valid in the placements listed above.
    64  
    65  ### Download File
    66  
    67  This example downloads the artifact from the provided URL and places it in
    68  `local/file.txt`. The `local/` path is relative to the task's directory.
    69  
    70  ```hcl
    71  artifact {
    72    source = "https://example.com/file.txt"
    73  }
    74  ```
    75  
    76  ### Download using git
    77  
    78  This example downloads the artifact from the provided GitHub URL and places it at
    79  `local/repo`, as specified by the optional `destination` parameter.
    80  
    81  ```hcl
    82  artifact {
    83    source      = "git::https://github.com/example/nomad-examples"
    84    destination = "local/repo"
    85  }
    86  ```
    87  
    88  To download from private repo, sshkey needs to be set. The key must be
    89  base64-encoded string. Run `base64 -w0 <file>`
    90  
    91  ```hcl
    92  artifact {
    93    source      = "git@github.com:example/nomad-examples"
    94    destination = "local/repo"
    95    options {
    96      sshkey = "<string>"
    97    }
    98  }
    99  ```
   100  
   101  ### Download and Unarchive
   102  
   103  This example downloads and unarchives the result in `local/file`. Because the
   104  source URL is an archive extension, Nomad will automatically decompress it:
   105  
   106  ```hcl
   107  artifact {
   108    source = "https://example.com/file.tar.gz"
   109  }
   110  ```
   111  
   112  To disable automatic unarchiving, set the `archive` option to false:
   113  
   114  ```hcl
   115  artifact {
   116    source = "https://example.com/file.tar.gz"
   117    options {
   118      archive = false
   119    }
   120  }
   121  ```
   122  
   123  ### Download and Verify Checksums
   124  
   125  This example downloads an artifact and verifies the resulting artifact's
   126  checksum before proceeding. If the checksum is invalid, an error will be
   127  returned.
   128  
   129  ```hcl
   130  artifact {
   131    source = "https://example.com/file.zip"
   132  
   133    options {
   134      checksum = "md5:df6a4178aec9fbdc1d6d7e3634d1bc33"
   135    }
   136  }
   137  ```
   138  
   139  ### Download from an S3-compatible Bucket
   140  
   141  These examples download artifacts from Amazon S3. There are several different
   142  types of [S3 bucket addressing][s3-bucket-addr] and [S3 region-specific
   143  endpoints][s3-region-endpoints]. As of Nomad 0.6 non-Amazon S3-compatible
   144  endpoints like [Minio] are supported, but you must explicitly set the "s3::"
   145  prefix.
   146  
   147  This example uses path-based notation on a publicly-accessible bucket:
   148  
   149  ```hcl
   150  artifact {
   151    source = "https://my-bucket-example.s3-us-west-2.amazonaws.com/my_app.tar.gz"
   152  }
   153  ```
   154  
   155  If a bucket requires authentication, you can avoid the use of credentials by
   156  using [EC2 IAM instance profiles][iam-instance-profiles]. If this is not possible,
   157  credentials may be supplied via the `options` parameter:
   158  
   159  ```hcl
   160  artifact {
   161    options {
   162      aws_access_key_id     = "<id>"
   163      aws_access_key_secret = "<secret>"
   164      aws_access_token      = "<token>"
   165    }
   166  }
   167  ```
   168  
   169  To force the S3-specific syntax, use the `s3::` prefix:
   170  
   171  ```hcl
   172  artifact {
   173    source = "s3::https://my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz"
   174  }
   175  ```
   176  
   177  Alternatively you can use virtual hosted style:
   178  
   179  ```hcl
   180  artifact {
   181    source = "https://my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz"
   182  }
   183  ```
   184  
   185  [go-getter]: https://github.com/hashicorp/go-getter 'HashiCorp go-getter Library'
   186  [minio]: https://www.minio.io/
   187  [s3-bucket-addr]: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro 'Amazon S3 Bucket Addressing'
   188  [s3-region-endpoints]: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region 'Amazon S3 Region Endpoints'
   189  [iam-instance-profiles]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html 'EC2 IAM instance profiles'