Commit 6fe0cb76 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/docker-push: allow repo with ports [GH-923]

parent 46abd505
......@@ -18,6 +18,7 @@ BUG FIXES:
* builder/virtualbox-iso: Retry unregister a few times to deal with
VBoxManage randomness. [GH-915]
* provisioners/chef-client: Don't chown directory with Ubuntu. [GH-939]
* post-processor/docker-push: Allow repositories with ports. [GH-923]
## 0.5.2 (02/21/2014)
......
......@@ -16,6 +16,8 @@ type Config struct {
}
type PostProcessor struct {
Driver docker.Driver
config Config
}
......@@ -38,7 +40,6 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
return nil
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
......@@ -49,13 +50,22 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return nil, false, err
}
driver := &docker.DockerDriver{Tpl: p.config.tpl, Ui: ui}
driver := p.Driver
if driver == nil {
// If no driver is set, then we use the real driver
driver = &docker.DockerDriver{Tpl: p.config.tpl, Ui: ui}
}
// Get the name. We strip off any tags from the name because the
// push doesn't use those.
name := artifact.Id()
if i := strings.Index(name, ":"); i >= 0 {
name = name[:i]
if i := strings.Index(name, "/"); i >= 0 {
// This should always be true because the / is required. But we have
// to get the index to this so we don't accidentally strip off the port
if j := strings.Index(name[i:], ":"); j >= 0 {
name = name[:i+j]
}
}
ui.Message("Pushing: " + name)
......
......@@ -2,7 +2,9 @@ package dockerpush
import (
"bytes"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import"
"testing"
)
......@@ -29,3 +31,84 @@ func testUi() *packer.BasicUi {
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
var _ packer.PostProcessor = new(PostProcessor)
}
func TestPostProcessor_PostProcess(t *testing.T) {
driver := &docker.MockDriver{}
p := &PostProcessor{Driver: driver}
artifact := &packer.MockArtifact{
BuilderIdValue: dockerimport.BuilderId,
IdValue: "foo/bar",
}
result, keep, err := p.PostProcess(testUi(), artifact)
if result != nil {
t.Fatal("should be nil")
}
if keep {
t.Fatal("should not keep")
}
if err != nil {
t.Fatalf("err: %s", err)
}
if !driver.PushCalled {
t.Fatal("should call push")
}
if driver.PushName != "foo/bar" {
t.Fatal("bad name")
}
}
func TestPostProcessor_PostProcess_portInName(t *testing.T) {
driver := &docker.MockDriver{}
p := &PostProcessor{Driver: driver}
artifact := &packer.MockArtifact{
BuilderIdValue: dockerimport.BuilderId,
IdValue: "localhost:5000/foo/bar",
}
result, keep, err := p.PostProcess(testUi(), artifact)
if result != nil {
t.Fatal("should be nil")
}
if keep {
t.Fatal("should not keep")
}
if err != nil {
t.Fatalf("err: %s", err)
}
if !driver.PushCalled {
t.Fatal("should call push")
}
if driver.PushName != "localhost:5000/foo/bar" {
t.Fatal("bad name")
}
}
func TestPostProcessor_PostProcess_tags(t *testing.T) {
driver := &docker.MockDriver{}
p := &PostProcessor{Driver: driver}
artifact := &packer.MockArtifact{
BuilderIdValue: dockerimport.BuilderId,
IdValue: "hashicorp/ubuntu:precise",
}
result, keep, err := p.PostProcess(testUi(), artifact)
if result != nil {
t.Fatal("should be nil")
}
if keep {
t.Fatal("should not keep")
}
if err != nil {
t.Fatalf("err: %s", err)
}
if !driver.PushCalled {
t.Fatal("should call push")
}
if driver.PushName != "hashicorp/ubuntu" {
t.Fatalf("bad name: %s", driver.PushName)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment