From 4d10d668eec24d0f1f68e67abc5444b1665ceaad Mon Sep 17 00:00:00 2001 From: Olivier Ceyral Date: Tue, 29 Jan 2019 12:07:24 +0100 Subject: [PATCH] Add "custom_data" key to packer manifest --- post-processor/manifest/artifact.go | 13 +++++++------ post-processor/manifest/post-processor.go | 6 ++++-- .../docs/post-processors/manifest.html.md | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/post-processor/manifest/artifact.go b/post-processor/manifest/artifact.go index 50ecc15a0..59d6110eb 100644 --- a/post-processor/manifest/artifact.go +++ b/post-processor/manifest/artifact.go @@ -10,12 +10,13 @@ type ArtifactFile struct { } type Artifact struct { - BuildName string `json:"name"` - BuilderType string `json:"builder_type"` - BuildTime int64 `json:"build_time"` - ArtifactFiles []ArtifactFile `json:"files"` - ArtifactId string `json:"artifact_id"` - PackerRunUUID string `json:"packer_run_uuid"` + BuildName string `json:"name"` + BuilderType string `json:"builder_type"` + BuildTime int64 `json:"build_time"` + ArtifactFiles []ArtifactFile `json:"files"` + ArtifactId string `json:"artifact_id"` + PackerRunUUID string `json:"packer_run_uuid"` + CustomData map[string]string `json:"custom_data"` } func (a *Artifact) BuilderId() string { diff --git a/post-processor/manifest/post-processor.go b/post-processor/manifest/post-processor.go index f5807dbb2..8833f2abe 100644 --- a/post-processor/manifest/post-processor.go +++ b/post-processor/manifest/post-processor.go @@ -18,8 +18,9 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - OutputPath string `mapstructure:"output"` - StripPath bool `mapstructure:"strip_path"` + OutputPath string `mapstructure:"output"` + StripPath bool `mapstructure:"strip_path"` + CustomData map[string]string `mapstructure:"custom_data"` ctx interpolate.Context } @@ -75,6 +76,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, source packer.Artifact) (packe artifact.ArtifactFiles = append(artifact.ArtifactFiles, af) } artifact.ArtifactId = source.Id() + artifact.CustomData = p.config.CustomData artifact.BuilderType = p.config.PackerBuilderType artifact.BuildName = p.config.PackerBuildName artifact.BuildTime = time.Now().Unix() diff --git a/website/source/docs/post-processors/manifest.html.md b/website/source/docs/post-processors/manifest.html.md index 56127c54d..3bb9bef3b 100644 --- a/website/source/docs/post-processors/manifest.html.md +++ b/website/source/docs/post-processors/manifest.html.md @@ -38,11 +38,12 @@ post-processors such as Docker and Artifice. to `packer-manifest.json`. - `strip_path` (boolean) Write only filename without the path to the manifest file. This defaults to false. +- `custom_data` (map of strings) Arbitrary data to add to the manifest. ### Example Configuration You can simply add `{"type":"manifest"}` to your post-processor section. Below -is a more verbose example: +is a more complete example: ``` json { @@ -50,7 +51,10 @@ is a more verbose example: { "type": "manifest", "output": "manifest.json", - "strip_path": true + "strip_path": true, + "custom_data": { + "my_custom_data": "example" + } } ] } @@ -72,7 +76,10 @@ An example manifest file looks like: } ], "artifact_id": "Container", - "packer_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f" + "packer_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f", + "custom_data": { + "my_custom_data": "example" + } } ], "last_run_uuid": "6d5d3185-fa95-44e1-8775-9e64fe2e2d8f" @@ -114,7 +121,10 @@ The above manifest was generated with this packer.json: { "type": "manifest", "output": "manifest.json", - "strip_path": true + "strip_path": true, + "custom_data": { + "my_custom_data": "example" + } } ] }