Added discard option for docker builder, also reorganized some error messages
This commit is contained in:
parent
32978a5109
commit
750a9c61de
|
@ -9,8 +9,10 @@ import (
|
|||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
const BuilderId = "packer.docker"
|
||||
const BuilderIdImport = "packer.post-processor.docker-import"
|
||||
const (
|
||||
BuilderId = "packer.docker"
|
||||
BuilderIdImport = "packer.post-processor.docker-import"
|
||||
)
|
||||
|
||||
type Builder struct {
|
||||
config *Config
|
||||
|
@ -54,10 +56,16 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
&common.StepProvision{},
|
||||
}
|
||||
|
||||
if b.config.Commit {
|
||||
if b.config.Discard {
|
||||
log.Print("[DEBUG] Container will be discarded")
|
||||
} else if b.config.Commit {
|
||||
log.Print("[DEBUG] Container will be committed")
|
||||
steps = append(steps, new(StepCommit))
|
||||
} else {
|
||||
} else if b.config.ExportPath != "" {
|
||||
log.Printf("[DEBUG] Container will be exported to %s", b.config.ExportPath)
|
||||
steps = append(steps, new(StepExport))
|
||||
} else {
|
||||
return nil, ErrArtifactNotUsed
|
||||
}
|
||||
|
||||
// Setup the state bag and initial state for the steps
|
||||
|
|
|
@ -12,23 +12,33 @@ import (
|
|||
"github.com/mitchellh/packer/template/interpolate"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrArtifactNotUsed = fmt.Errorf("No instructions given for handling the artifact; expected commit, discard, or export_path")
|
||||
ErrArtifactUseConflict = fmt.Errorf("Cannot specify more than one of commit, discard, and export_path")
|
||||
ErrExportPathNotFile = fmt.Errorf("export_path must be a file, not a directory")
|
||||
ErrImageNotSpecified = fmt.Errorf("Image must be specified")
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
common.PackerConfig `mapstructure:",squash"`
|
||||
Comm communicator.Config `mapstructure:",squash"`
|
||||
|
||||
Commit bool
|
||||
Discard bool
|
||||
ExportPath string `mapstructure:"export_path"`
|
||||
Image string
|
||||
Pty bool
|
||||
Pull bool
|
||||
RunCommand []string `mapstructure:"run_command"`
|
||||
Volumes map[string]string
|
||||
|
||||
// This is used to login to dockerhub to pull a private base container
|
||||
// For pushing to dockerhub, see the docker post-processors
|
||||
Login bool
|
||||
LoginEmail string `mapstructure:"login_email"`
|
||||
LoginUsername string `mapstructure:"login_username"`
|
||||
LoginPassword string `mapstructure:"login_password"`
|
||||
LoginServer string `mapstructure:"login_server"`
|
||||
Pty bool
|
||||
LoginUsername string `mapstructure:"login_username"`
|
||||
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
@ -84,18 +94,20 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
}
|
||||
if c.Image == "" {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
fmt.Errorf("image must be specified"))
|
||||
ErrImageNotSpecified)
|
||||
}
|
||||
|
||||
if c.ExportPath != "" && c.Commit {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
fmt.Errorf("both commit and export_path cannot be set"))
|
||||
if (c.ExportPath != "" && c.Commit) || (c.ExportPath != "" && c.Discard) || (c.Commit && c.Discard) {
|
||||
errs = packer.MultiErrorAppend(errs, ErrArtifactUseConflict)
|
||||
}
|
||||
|
||||
if c.ExportPath == "" && !c.Commit && !c.Discard {
|
||||
errs = packer.MultiErrorAppend(errs, ErrArtifactNotUsed)
|
||||
}
|
||||
|
||||
if c.ExportPath != "" {
|
||||
if fi, err := os.Stat(c.ExportPath); err == nil && fi.IsDir() {
|
||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf(
|
||||
"export_path must be a file, not a directory"))
|
||||
errs = packer.MultiErrorAppend(errs, ErrExportPathNotFile)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue