From 4f9a91012f7586b74a18cf4042b0b0045e74f217 Mon Sep 17 00:00:00 2001 From: Patrick Double Date: Fri, 20 Jul 2018 15:27:29 -0500 Subject: [PATCH] Change docker-push to return docker-import artifact --- Makefile | 1 + post-processor/docker-push/post-processor.go | 10 +++++- .../docker-push/post-processor_test.go | 33 ++++++++++++------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b22d61e93..5203d31a2 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ package: @sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)" deps: + @go get golang.org/x/tools/cmd/goimports @go get golang.org/x/tools/cmd/stringer @go get -u github.com/mna/pigeon @go get github.com/kardianos/govendor diff --git a/post-processor/docker-push/post-processor.go b/post-processor/docker-push/post-processor.go index f0fee00ca..2ffc3e5a5 100644 --- a/post-processor/docker-push/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -12,6 +12,8 @@ import ( "github.com/hashicorp/packer/template/interpolate" ) +const BuilderIdImport = "packer.post-processor.docker-import" + type Config struct { common.PackerConfig `mapstructure:",squash"` @@ -103,5 +105,11 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, false, err } - return nil, false, nil + artifact = &docker.ImportArtifact{ + BuilderIdValue: BuilderIdImport, + Driver: driver, + IdValue: name, + } + + return artifact, true, nil } diff --git a/post-processor/docker-push/post-processor_test.go b/post-processor/docker-push/post-processor_test.go index d132595e5..1eee102cb 100644 --- a/post-processor/docker-push/post-processor_test.go +++ b/post-processor/docker-push/post-processor_test.go @@ -42,11 +42,11 @@ func TestPostProcessor_PostProcess(t *testing.T) { } result, keep, err := p.PostProcess(testUi(), artifact) - if result != nil { - t.Fatal("should be nil") + if _, ok := result.(packer.Artifact); !ok { + t.Fatal("should be instance of Artifact") } - if keep { - t.Fatal("should not keep") + if !keep { + t.Fatal("should keep") } if err != nil { t.Fatalf("err: %s", err) @@ -58,6 +58,9 @@ func TestPostProcessor_PostProcess(t *testing.T) { if driver.PushName != "foo/bar" { t.Fatal("bad name") } + if result.Id() != "foo/bar" { + t.Fatal("bad image id") + } } func TestPostProcessor_PostProcess_portInName(t *testing.T) { @@ -69,11 +72,11 @@ func TestPostProcessor_PostProcess_portInName(t *testing.T) { } result, keep, err := p.PostProcess(testUi(), artifact) - if result != nil { - t.Fatal("should be nil") + if _, ok := result.(packer.Artifact); !ok { + t.Fatal("should be instance of Artifact") } - if keep { - t.Fatal("should not keep") + if !keep { + t.Fatal("should keep") } if err != nil { t.Fatalf("err: %s", err) @@ -85,6 +88,9 @@ func TestPostProcessor_PostProcess_portInName(t *testing.T) { if driver.PushName != "localhost:5000/foo/bar" { t.Fatal("bad name") } + if result.Id() != "localhost:5000/foo/bar" { + t.Fatal("bad image id") + } } func TestPostProcessor_PostProcess_tags(t *testing.T) { @@ -96,11 +102,11 @@ func TestPostProcessor_PostProcess_tags(t *testing.T) { } result, keep, err := p.PostProcess(testUi(), artifact) - if result != nil { - t.Fatal("should be nil") + if _, ok := result.(packer.Artifact); !ok { + t.Fatal("should be instance of Artifact") } - if keep { - t.Fatal("should not keep") + if !keep { + t.Fatal("should keep") } if err != nil { t.Fatalf("err: %s", err) @@ -112,4 +118,7 @@ func TestPostProcessor_PostProcess_tags(t *testing.T) { if driver.PushName != "hashicorp/ubuntu:precise" { t.Fatalf("bad name: %s", driver.PushName) } + if result.Id() != "hashicorp/ubuntu:precise" { + t.Fatal("bad image id") + } }