|
| 1 | +# Grapl Artifacts Buildkite Plugin |
| 2 | + |
| 3 | +Encapsulates logic used in Grapl's release pipelines for |
| 4 | +record-keeping around the versions of any artifacts that are |
| 5 | +generated. |
| 6 | + |
| 7 | +This is highly specific to how we run our CI/CD pipelines at Grapl; it |
| 8 | +is not intended to be broadly generalizable. |
| 9 | + |
| 10 | +## Example |
| 11 | + |
| 12 | +```yml |
| 13 | +steps: |
| 14 | + - label: ":gear::packer: Convert Packer Manifests" |
| 15 | + plugins: |
| 16 | + - grapl-security/grapl-artifacts#v0.1.0: |
| 17 | + action: convert_packer_manifests |
| 18 | +``` |
| 19 | +
|
| 20 | +```yml |
| 21 | +steps: |
| 22 | + - label: ":knot: Merge Artifact Files" |
| 23 | + plugins: |
| 24 | + - grapl-security/grapl-artifacts#v0.1.0: |
| 25 | + action: merge_artifact_files |
| 26 | +``` |
| 27 | +
|
| 28 | +## Configuration |
| 29 | +
|
| 30 | +### action (required, string) |
| 31 | +
|
| 32 | +The name of the plugin action to run; currently supports the following: |
| 33 | +- `convert_packer_manifests` |
| 34 | +- `merge_artifact_files` |
| 35 | + |
| 36 | +#### `convert_packer_manifests` |
| 37 | + |
| 38 | +Extracts the AMI IDs from one or more Packer [manifest |
| 39 | +files](https://www.packer.io/docs/post-processors/manifest) into a |
| 40 | +simplified JSON form that we can consume more easily in downstream pipeline |
| 41 | +jobs. |
| 42 | + |
| 43 | +In particular, it will take a manifest file like this (call it |
| 44 | +`my-ami.packer-manifest.json`): |
| 45 | + |
| 46 | +```json |
| 47 | +{ |
| 48 | + "builds": [ |
| 49 | + { |
| 50 | + "name": "amazon-linux-2-amd64-ami", |
| 51 | + "builder_type": "amazon-ebs", |
| 52 | + "build_time": 1626818948, |
| 53 | + "files": null, |
| 54 | + "artifact_id": "us-east-1:ami-aaaaaaaaaaaaaaaaa,us-east-2:ami-bbbbbbbbbbbbbbbbb,us-west-1:ami-ccccccccccccccccc,us-west-2:ami-ddddddddddddddddd", |
| 55 | + "packer_run_uuid": "f101f1dd-5fdb-bc9e-b0f0-ee49267bf567", |
| 56 | + "custom_data": null |
| 57 | + } |
| 58 | + ], |
| 59 | + "last_run_uuid": "f101f1dd-5fdb-bc9e-b0f0-ee49267bf567" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +and turn it into `my-ami-${BUILDKITE_JOB_ID}.grapl-artifacts.json`: |
| 64 | + |
| 65 | +```json |
| 66 | +{ |
| 67 | + "my-ami.us-east-1": "ami-aaaaaaaaaaaaaaaaa", |
| 68 | + "my-ami.us-east-2": "ami-bbbbbbbbbbbbbbbbb", |
| 69 | + "my-ami.us-west-1": "ami-ccccccccccccccccc", |
| 70 | + "my-ami.us-west-2": "ami-ddddddddddddddddd", |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +The manifest file _must_ have the extension `.packer-manifest.json`; |
| 75 | +the resulting file will be named according to whatever the basename of |
| 76 | +the manifest file is. |
| 77 | + |
| 78 | +To generate manifests compatible with this plugin, use HCL like this |
| 79 | +in your Packer template: |
| 80 | + |
| 81 | +```hcl |
| 82 | +build { |
| 83 | + # all your sources and provisioners go here... |
| 84 | +
|
| 85 | + post-processor "manifest" { |
| 86 | + output = "my-ami.packer-manifest.json" |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +All files previously uploaded using `buildkite-agent artifact upload` |
| 92 | +in the current pipeline and ending in `.packer-manifest.json` will be |
| 93 | +processed in this way; one `.grapl-artifacts.json` file per Packer |
| 94 | +manifest will be generated and uploaded for access in downstream jobs. |
| 95 | + |
| 96 | +#### `merge_artifact_files` |
| 97 | + |
| 98 | +Takes all `*.grapl-artifacts.json` files that have been previously |
| 99 | +uploaded in the current pipeline and merges them all into a single |
| 100 | +file for subsequent processing. |
| 101 | + |
| 102 | +Each file is assumed to contain a single, flat JSON object, with |
| 103 | +mutually disjoint keys. |
| 104 | + |
| 105 | +The final merged file is called `all_artifacts.json` and is uploaded |
| 106 | +for access in downstream jobs. |
| 107 | + |
| 108 | +## Building |
| 109 | + |
| 110 | +Requires `make`, `docker`, and `docker-compose`. |
| 111 | + |
| 112 | +`make all` will run all formatting, linting, and testing, though |
| 113 | +finer-grained targets are available. |
0 commit comments