2013-11-08 19:55:02 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-11-09 14:47:32 -05:00
|
|
|
"fmt"
|
2013-11-08 19:55:02 -05:00
|
|
|
"github.com/mitchellh/packer/common"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
|
2014-09-04 21:03:15 -04:00
|
|
|
Commit bool
|
2013-11-09 12:48:36 -05:00
|
|
|
ExportPath string `mapstructure:"export_path"`
|
|
|
|
Image string
|
2013-11-09 20:21:24 -05:00
|
|
|
Pull bool
|
2013-12-27 12:17:45 -05:00
|
|
|
RunCommand []string `mapstructure:"run_command"`
|
2013-11-09 01:00:57 -05:00
|
|
|
|
2014-09-05 18:24:12 -04:00
|
|
|
Login bool
|
|
|
|
LoginEmail string `mapstructure:"login_email"`
|
|
|
|
LoginUsername string `mapstructure:"login_username"`
|
|
|
|
LoginPassword string `mapstructure:"login_password"`
|
|
|
|
LoginServer string `mapstructure:"login_server"`
|
|
|
|
|
2013-11-08 19:55:02 -05:00
|
|
|
tpl *packer.ConfigTemplate
|
|
|
|
}
|
2013-11-09 14:47:32 -05:00
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
c := new(Config)
|
|
|
|
md, err := common.DecodeConfig(c, raws...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.tpl, err = packer.NewConfigTemplate()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2014-01-02 17:49:30 -05:00
|
|
|
c.tpl.UserVars = c.PackerUserVars
|
|
|
|
|
2013-12-27 12:17:45 -05:00
|
|
|
// Defaults
|
|
|
|
if len(c.RunCommand) == 0 {
|
|
|
|
c.RunCommand = []string{
|
|
|
|
"run",
|
|
|
|
"-d", "-i", "-t",
|
|
|
|
"-v", "{{.Volumes}}",
|
|
|
|
"{{.Image}}",
|
|
|
|
"/bin/bash",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-09 20:21:24 -05:00
|
|
|
// Default Pull if it wasn't set
|
|
|
|
hasPull := false
|
|
|
|
for _, k := range md.Keys {
|
|
|
|
if k == "Pull" {
|
|
|
|
hasPull = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !hasPull {
|
|
|
|
c.Pull = true
|
|
|
|
}
|
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
errs := common.CheckUnusedConfig(md)
|
2013-11-09 14:47:32 -05:00
|
|
|
|
|
|
|
templates := map[string]*string{
|
2014-09-05 18:24:12 -04:00
|
|
|
"export_path": &c.ExportPath,
|
|
|
|
"image": &c.Image,
|
|
|
|
"login_email": &c.LoginEmail,
|
|
|
|
"login_username": &c.LoginUsername,
|
|
|
|
"login_password": &c.LoginPassword,
|
|
|
|
"login_server": &c.LoginServer,
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for n, ptr := range templates {
|
|
|
|
var err error
|
|
|
|
*ptr, err = c.tpl.Process(*ptr, nil)
|
|
|
|
if err != nil {
|
2013-11-09 20:07:14 -05:00
|
|
|
errs = packer.MultiErrorAppend(
|
2013-11-09 14:47:32 -05:00
|
|
|
errs, fmt.Errorf("Error processing %s: %s", n, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Image == "" {
|
2013-11-09 20:07:14 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("image must be specified"))
|
|
|
|
}
|
|
|
|
|
2014-09-04 21:03:15 -04:00
|
|
|
if c.ExportPath != "" && c.Commit {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("both commit and export_path cannot be set"))
|
|
|
|
}
|
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
|
|
|
return nil, nil, errs
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
return c, nil, nil
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|