forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do some forward porting of the old work of
mitchellh/packer's docker branch. hashicorp#774
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/mitchellh/packer/packer/plugin" | ||
"github.com/mitchellh/packer/post-processor/docker" | ||
) | ||
|
||
func main() { | ||
server, err := plugin.Server() | ||
if err != nil { | ||
panic(err) | ||
} | ||
server.RegisterPostProcessor(new(docker.PostProcessor)) | ||
server.Serve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package docker | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/mitchellh/packer/packer" | ||
"os/exec" | ||
) | ||
|
||
type Config struct { | ||
Registry string | ||
Username string | ||
Password string | ||
Email string | ||
} | ||
|
||
type PostProcessor struct { | ||
config Config | ||
} | ||
|
||
func (p *PostProcessor) Configure(raw ...interface{}) error { | ||
if err := mapstructure.Decode(raw, &p.config); err != nil { | ||
return err | ||
} | ||
|
||
if p.config.Registry == "" { | ||
p.config.Registry = "registry.docker.io" | ||
} | ||
|
||
if p.config.Username == "" { | ||
return errors.New("Username is required to push docker image") | ||
} | ||
|
||
if p.config.Password == "" { | ||
return errors.New("Password is required to push docker image") | ||
} | ||
|
||
return nil | ||
} | ||
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) { | ||
id := artifact.Id() | ||
ui.Say("Pushing imgage: " + id) | ||
|
||
// TODO: docker login | ||
|
||
stdout := new(bytes.Buffer) | ||
cmd := exec.Command("docker", "push", id) | ||
cmd.Stdout = stdout | ||
if err := cmd.Run(); err != nil { | ||
ui.Say("Failed to push image: " + id) | ||
return nil, true, err | ||
} | ||
|
||
return nil, true, nil | ||
} |