From b982d987a7b95fd60442dceb8fd71f8b1dc869ee Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 15 May 2020 13:13:43 -0700 Subject: [PATCH] Add Artifice postprocessor ID to valid artifacts for postprocessors that perform artifact type validation --- post-processor/googlecompute-export/post-processor.go | 8 ++++++-- post-processor/googlecompute-import/post-processor.go | 10 +++++++--- post-processor/vagrant-cloud/post-processor.go | 2 +- post-processor/vagrant/post-processor.go | 2 ++ post-processor/vsphere-template/post-processor.go | 2 ++ post-processor/yandex-export/post-processor.go | 8 ++++++-- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/post-processor/googlecompute-export/post-processor.go b/post-processor/googlecompute-export/post-processor.go index 2d4a2a995..7341e6cfb 100644 --- a/post-processor/googlecompute-export/post-processor.go +++ b/post-processor/googlecompute-export/post-processor.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/post-processor/artifice" "github.com/hashicorp/packer/template/interpolate" "golang.org/x/oauth2/jwt" ) @@ -92,9 +93,12 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { } func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) { - if artifact.BuilderId() != googlecompute.BuilderId { + switch artifact.BuilderId() { + case googlecompute.BuilderId, artifice.BuilderId: + break + default: err := fmt.Errorf( - "Unknown artifact type: %s\nCan only export from Google Compute Engine builder artifacts.", + "Unknown artifact type: %s\nCan only export from Google Compute Engine builder and Artifice post-processor artifacts.", artifact.BuilderId()) return nil, false, false, err } diff --git a/post-processor/googlecompute-import/post-processor.go b/post-processor/googlecompute-import/post-processor.go index 33f2501b9..2379e3e3c 100644 --- a/post-processor/googlecompute-import/post-processor.go +++ b/post-processor/googlecompute-import/post-processor.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/post-processor/artifice" "github.com/hashicorp/packer/post-processor/compress" "github.com/hashicorp/packer/template/interpolate" ) @@ -123,9 +124,12 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact return nil, false, false, err } - if artifact.BuilderId() != compress.BuilderId { - err = fmt.Errorf( - "incompatible artifact type: %s\nCan only import from Compress post-processor artifacts", + switch artifact.BuilderId() { + case compress.BuilderId, artifice.BuilderId: + break + default: + err := fmt.Errorf( + "Unknown artifact type: %s\nCan only import from Compress post-processor and Artifice post-processor artifacts.", artifact.BuilderId()) return nil, false, false, err } diff --git a/post-processor/vagrant-cloud/post-processor.go b/post-processor/vagrant-cloud/post-processor.go index 26a30cc1a..b79652a67 100644 --- a/post-processor/vagrant-cloud/post-processor.go +++ b/post-processor/vagrant-cloud/post-processor.go @@ -130,7 +130,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) { if _, ok := builtins[artifact.BuilderId()]; !ok { return nil, false, false, fmt.Errorf( - "Unknown artifact type, requires box from vagrant post-processor or vagrant builder: %s", artifact.BuilderId()) + "Unknown artifact type: this post-processor requires an input artifact from the artifice post-processor, vagrant post-processor, or vagrant builder: %s", artifact.BuilderId()) } // We assume that there is only one .box file to upload diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index 15faa0c9e..624bb7b0e 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/tmp" + "github.com/hashicorp/packer/post-processor/artifice" "github.com/hashicorp/packer/template/interpolate" "github.com/mitchellh/mapstructure" ) @@ -40,6 +41,7 @@ var builtins = map[string]string{ "packer.post-processor.docker-import": "docker", "packer.post-processor.docker-tag": "docker", "packer.post-processor.docker-push": "docker", + artifice.BuilderId: "artifice", } type Config struct { diff --git a/post-processor/vsphere-template/post-processor.go b/post-processor/vsphere-template/post-processor.go index 490453e1b..978970633 100644 --- a/post-processor/vsphere-template/post-processor.go +++ b/post-processor/vsphere-template/post-processor.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/post-processor/artifice" "github.com/hashicorp/packer/template/interpolate" "github.com/vmware/govmomi" ) @@ -27,6 +28,7 @@ var builtins = map[string]string{ vspherepost.BuilderId: "vmware", vmwcommon.BuilderIdESX: "vmware", vsphere.BuilderId: "vsphere", + artifice.BuilderId: "artifice", } type Config struct { diff --git a/post-processor/yandex-export/post-processor.go b/post-processor/yandex-export/post-processor.go index 1a37bb16b..7987e9d78 100644 --- a/post-processor/yandex-export/post-processor.go +++ b/post-processor/yandex-export/post-processor.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/post-processor/artifice" "github.com/hashicorp/packer/template/interpolate" ) @@ -106,9 +107,12 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { } func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) { - if artifact.BuilderId() != yandex.BuilderID { + switch artifact.BuilderId() { + case yandex.BuilderID, artifice.BuilderId: + break + default: err := fmt.Errorf( - "Unknown artifact type: %s\nCan only export from Yandex Cloud builder artifacts.", + "Unknown artifact type: %s\nCan only export from Yandex Cloud builder artifact or Artifice post-processor artifact.", artifact.BuilderId()) return nil, false, false, err }