Fix regression in docker-tag post-processor (#8593)
GH-8392 introduced the feature that multiple tags can be specified. This (presumably inadvertently) broke the option to tag an image without the actual tag specified -- Docker handles this by assuming `latest` as the tag. In addition, use-cases exist for the `repository` field containing the tag already, which was also broken.
This commit is contained in:
parent
d6a351b173
commit
d7d00d8069
|
@ -10,6 +10,7 @@
|
|||
* builder/virtualbox-vm: use config as a non pointer to avoid a panic [GH-8576]
|
||||
* core: Fix crash when build.sources is set to an invalid name [GH-8569]
|
||||
* core: Fix loading of external plugins. GH-8543]
|
||||
* post-processor/docker-tag: Fix regression if no tags were specified. [GH-8593]
|
||||
* post-processor/vagrant: correctly handle the diskSize property as a qemu size
|
||||
string [GH-8567]
|
||||
* provisioner/ansible: Fix password sanitization to account for empty string
|
||||
|
|
|
@ -68,6 +68,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
|
|||
|
||||
importRepo := p.config.Repository
|
||||
var lastTaggedRepo = importRepo
|
||||
if len(p.config.Tag) > 0 {
|
||||
for _, tag := range p.config.Tag {
|
||||
local := importRepo + ":" + tag
|
||||
ui.Message("Tagging image: " + artifact.Id())
|
||||
|
@ -80,6 +81,14 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
|
|||
|
||||
lastTaggedRepo = local
|
||||
}
|
||||
} else {
|
||||
ui.Message("Tagging image: " + artifact.Id())
|
||||
ui.Message("Repository: " + importRepo)
|
||||
err := driver.TagImage(artifact.Id(), importRepo, p.config.Force)
|
||||
if err != nil {
|
||||
return nil, false, true, err
|
||||
}
|
||||
}
|
||||
|
||||
// Build the artifact
|
||||
artifact = &docker.ImportArtifact{
|
||||
|
|
|
@ -127,3 +127,42 @@ func TestPostProcessor_PostProcess_Force(t *testing.T) {
|
|||
t.Fatal("bad force")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostProcessor_PostProcess_NoTag(t *testing.T) {
|
||||
driver := &docker.MockDriver{}
|
||||
p := &PostProcessor{Driver: driver}
|
||||
c := testConfig()
|
||||
delete(c, "tag")
|
||||
if err := p.Configure(c); err != nil {
|
||||
t.Fatalf("err %s", err)
|
||||
}
|
||||
|
||||
artifact := &packer.MockArtifact{BuilderIdValue: dockerimport.BuilderId, IdValue: "1234567890abcdef"}
|
||||
|
||||
result, keep, forceOverride, err := p.PostProcess(context.Background(), testUi(), artifact)
|
||||
if _, ok := result.(packer.Artifact); !ok {
|
||||
t.Fatal("should be instance of Artifact")
|
||||
}
|
||||
if !keep {
|
||||
t.Fatal("should keep")
|
||||
}
|
||||
if !forceOverride {
|
||||
t.Fatal("Should force keep no matter what user sets.")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if driver.TagImageCalled != 1 {
|
||||
t.Fatal("should call TagImage")
|
||||
}
|
||||
if driver.TagImageImageId != "1234567890abcdef" {
|
||||
t.Fatal("bad image id")
|
||||
}
|
||||
if driver.TagImageRepo[0] != "foo" {
|
||||
t.Fatal("bad repo")
|
||||
}
|
||||
if driver.TagImageForce {
|
||||
t.Fatal("bad force")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue