post-processor/docker-*: fix compilation errors

This commit is contained in:
Mitchell Hashimoto 2015-05-27 14:27:11 -07:00
parent c3b75f4b86
commit cbe6e83b60
4 changed files with 46 additions and 136 deletions

View File

@ -2,9 +2,12 @@ package dockerimport
import (
"fmt"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
const BuilderId = "packer.post-processor.docker-import"
@ -15,7 +18,7 @@ type Config struct {
Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"`
tpl *packer.ConfigTemplate
ctx interpolate.Context
}
type PostProcessor struct {
@ -23,42 +26,16 @@ type PostProcessor struct {
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...)
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
p.config.tpl, err = packer.NewConfigTemplate()
if err != nil {
return err
}
p.config.tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := new(packer.MultiError)
templates := map[string]*string{
"repository": &p.config.Repository,
"tag": &p.config.Tag,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = p.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
@ -76,7 +53,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
importRepo += ":" + p.config.Tag
}
driver := &docker.DockerDriver{Tpl: p.config.tpl, Ui: ui}
driver := &docker.DockerDriver{Ctx: &p.config.ctx, Ui: ui}
ui.Message("Importing image: " + artifact.Id())
ui.Message("Repository: " + importRepo)

View File

@ -2,12 +2,15 @@ package dockerpush
import (
"fmt"
"strings"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import"
"github.com/mitchellh/packer/post-processor/docker-tag"
"strings"
"github.com/mitchellh/packer/template/interpolate"
)
type Config struct {
@ -19,7 +22,7 @@ type Config struct {
LoginPassword string `mapstructure:"login_password"`
LoginServer string `mapstructure:"login_server"`
tpl *packer.ConfigTemplate
ctx interpolate.Context
}
type PostProcessor struct {
@ -29,41 +32,16 @@ type PostProcessor struct {
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...)
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
p.config.tpl, err = packer.NewConfigTemplate()
if err != nil {
return err
}
p.config.tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := new(packer.MultiError)
// Process templates
templates := map[string]*string{
"login_email": &p.config.LoginEmail,
"login_username": &p.config.LoginUsername,
"login_password": &p.config.LoginPassword,
"login_server": &p.config.LoginServer,
}
for n, ptr := range templates {
var err error
*ptr, err = p.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
@ -79,7 +57,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
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}
driver = &docker.DockerDriver{Ctx: &p.config.ctx, Ui: ui}
}
if p.config.Login {

View File

@ -2,11 +2,14 @@ package dockersave
import (
"fmt"
"os"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import"
"os"
"github.com/mitchellh/packer/template/interpolate"
)
const BuilderId = "packer.post-processor.docker-save"
@ -16,7 +19,7 @@ type Config struct {
Path string `mapstructure:"path"`
tpl *packer.ConfigTemplate
ctx interpolate.Context
}
type PostProcessor struct {
@ -26,41 +29,16 @@ type PostProcessor struct {
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...)
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
p.config.tpl, err = packer.NewConfigTemplate()
if err != nil {
return err
}
p.config.tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := new(packer.MultiError)
templates := map[string]*string{
"path": &p.config.Path,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = p.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
@ -85,7 +63,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
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}
driver = &docker.DockerDriver{Ctx: &p.config.ctx, Ui: ui}
}
ui.Message("Saving image: " + artifact.Id())

View File

@ -2,10 +2,13 @@ package dockertag
import (
"fmt"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import"
"github.com/mitchellh/packer/template/interpolate"
)
const BuilderId = "packer.post-processor.docker-tag"
@ -16,7 +19,7 @@ type Config struct {
Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"`
tpl *packer.ConfigTemplate
ctx interpolate.Context
}
type PostProcessor struct {
@ -26,42 +29,16 @@ type PostProcessor struct {
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...)
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
p.config.tpl, err = packer.NewConfigTemplate()
if err != nil {
return err
}
p.config.tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := new(packer.MultiError)
templates := map[string]*string{
"repository": &p.config.Repository,
"tag": &p.config.Tag,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = p.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
@ -77,7 +54,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
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}
driver = &docker.DockerDriver{Ctx: &p.config.ctx, Ui: ui}
}
importRepo := p.config.Repository