Commit cbe6e83b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/docker-*: fix compilation errors

parent c3b75f4b
...@@ -2,9 +2,12 @@ package dockerimport ...@@ -2,9 +2,12 @@ package dockerimport
import ( import (
"fmt" "fmt"
"github.com/mitchellh/packer/builder/docker" "github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
const BuilderId = "packer.post-processor.docker-import" const BuilderId = "packer.post-processor.docker-import"
...@@ -15,7 +18,7 @@ type Config struct { ...@@ -15,7 +18,7 @@ type Config struct {
Repository string `mapstructure:"repository"` Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"` Tag string `mapstructure:"tag"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
type PostProcessor struct { type PostProcessor struct {
...@@ -23,41 +26,15 @@ type PostProcessor struct { ...@@ -23,41 +26,15 @@ type PostProcessor struct {
} }
func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...) err := config.Decode(&p.config, &config.DecodeOpts{
if err != nil { Interpolate: true,
return err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{},
},
p.config.tpl, err = packer.NewConfigTemplate() }, raws...)
if err != nil { if err != nil {
return err 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 return nil
...@@ -76,7 +53,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -76,7 +53,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
importRepo += ":" + p.config.Tag 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("Importing image: " + artifact.Id())
ui.Message("Repository: " + importRepo) ui.Message("Repository: " + importRepo)
......
...@@ -2,12 +2,15 @@ package dockerpush ...@@ -2,12 +2,15 @@ package dockerpush
import ( import (
"fmt" "fmt"
"strings"
"github.com/mitchellh/packer/builder/docker" "github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import" "github.com/mitchellh/packer/post-processor/docker-import"
"github.com/mitchellh/packer/post-processor/docker-tag" "github.com/mitchellh/packer/post-processor/docker-tag"
"strings" "github.com/mitchellh/packer/template/interpolate"
) )
type Config struct { type Config struct {
...@@ -19,7 +22,7 @@ type Config struct { ...@@ -19,7 +22,7 @@ type Config struct {
LoginPassword string `mapstructure:"login_password"` LoginPassword string `mapstructure:"login_password"`
LoginServer string `mapstructure:"login_server"` LoginServer string `mapstructure:"login_server"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
type PostProcessor struct { type PostProcessor struct {
...@@ -29,40 +32,15 @@ type PostProcessor struct { ...@@ -29,40 +32,15 @@ type PostProcessor struct {
} }
func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...) err := config.Decode(&p.config, &config.DecodeOpts{
if err != nil { Interpolate: true,
return err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{},
},
p.config.tpl, err = packer.NewConfigTemplate() }, raws...)
if err != nil { if err != nil {
return err 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 return nil
} }
...@@ -79,7 +57,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -79,7 +57,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
driver := p.Driver driver := p.Driver
if driver == nil { if driver == nil {
// If no driver is set, then we use the real driver // 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 { if p.config.Login {
......
...@@ -2,11 +2,14 @@ package dockersave ...@@ -2,11 +2,14 @@ package dockersave
import ( import (
"fmt" "fmt"
"os"
"github.com/mitchellh/packer/builder/docker" "github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import" "github.com/mitchellh/packer/post-processor/docker-import"
"os" "github.com/mitchellh/packer/template/interpolate"
) )
const BuilderId = "packer.post-processor.docker-save" const BuilderId = "packer.post-processor.docker-save"
...@@ -16,7 +19,7 @@ type Config struct { ...@@ -16,7 +19,7 @@ type Config struct {
Path string `mapstructure:"path"` Path string `mapstructure:"path"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
type PostProcessor struct { type PostProcessor struct {
...@@ -26,40 +29,15 @@ type PostProcessor struct { ...@@ -26,40 +29,15 @@ type PostProcessor struct {
} }
func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...) err := config.Decode(&p.config, &config.DecodeOpts{
if err != nil { Interpolate: true,
return err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{},
},
p.config.tpl, err = packer.NewConfigTemplate() }, raws...)
if err != nil { if err != nil {
return err 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 return nil
...@@ -85,7 +63,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -85,7 +63,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
driver := p.Driver driver := p.Driver
if driver == nil { if driver == nil {
// If no driver is set, then we use the real driver // 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()) ui.Message("Saving image: " + artifact.Id())
......
...@@ -2,10 +2,13 @@ package dockertag ...@@ -2,10 +2,13 @@ package dockertag
import ( import (
"fmt" "fmt"
"github.com/mitchellh/packer/builder/docker" "github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/post-processor/docker-import" "github.com/mitchellh/packer/post-processor/docker-import"
"github.com/mitchellh/packer/template/interpolate"
) )
const BuilderId = "packer.post-processor.docker-tag" const BuilderId = "packer.post-processor.docker-tag"
...@@ -16,7 +19,7 @@ type Config struct { ...@@ -16,7 +19,7 @@ type Config struct {
Repository string `mapstructure:"repository"` Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"` Tag string `mapstructure:"tag"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
type PostProcessor struct { type PostProcessor struct {
...@@ -26,41 +29,15 @@ type PostProcessor struct { ...@@ -26,41 +29,15 @@ type PostProcessor struct {
} }
func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) Configure(raws ...interface{}) error {
_, err := common.DecodeConfig(&p.config, raws...) err := config.Decode(&p.config, &config.DecodeOpts{
if err != nil { Interpolate: true,
return err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{},
},
p.config.tpl, err = packer.NewConfigTemplate() }, raws...)
if err != nil { if err != nil {
return err 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 return nil
...@@ -77,7 +54,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -77,7 +54,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
driver := p.Driver driver := p.Driver
if driver == nil { if driver == nil {
// If no driver is set, then we use the real driver // 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 importRepo := p.config.Repository
......
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