|
|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
@ -53,11 +63,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
|
if len(c.RunCommand) == 0 {
|
|
|
|
|
c.RunCommand = []string{
|
|
|
|
|
"-d", "-i", "-t",
|
|
|
|
|
"{{.Image}}",
|
|
|
|
|
"/bin/bash",
|
|
|
|
|
}
|
|
|
|
|
c.RunCommand = []string{"-d", "-i", "-t", "{{.Image}}", "/bin/bash"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Default Pull if it wasn't set
|
|
|
|
|
@ -83,19 +89,20 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, es...)
|
|
|
|
|
}
|
|
|
|
|
if c.Image == "" {
|
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
|
fmt.Errorf("image must be specified"))
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, errImageNotSpecified)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c.ExportPath != "" && c.Commit) || (c.ExportPath != "" && c.Discard) || (c.Commit && c.Discard) {
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, errArtifactUseConflict)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|