builder/amazon: more efficient use of templates

This commit is contained in:
Mitchell Hashimoto 2013-08-08 17:04:39 -07:00
parent c6e36108b3
commit 9520c6e6ed
3 changed files with 3 additions and 19 deletions

View File

@ -61,7 +61,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if b.config.BundlePrefix == "" {
b.config.BundlePrefix = "image-{{.CreateTime}}"
b.config.BundlePrefix = "image-{{timestamp}}"
}
if b.config.BundleUploadCommand == "" {
@ -97,7 +97,6 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
validates := map[string]*string{
"bundle_prefix": &b.config.BundlePrefix,
"bundle_upload_command": &b.config.BundleUploadCommand,
"bundle_vol_command": &b.config.BundleVolCommand,
}
@ -113,6 +112,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
"account_id": &b.config.AccountId,
"ami_name": &b.config.AMIName,
"bundle_destination": &b.config.BundleDestination,
"bundle_prefix": &b.config.BundlePrefix,
"s3_bucket": &b.config.S3Bucket,
"x509_cert_path": &b.config.X509CertPath,
"x509_key_path": &b.config.X509KeyPath,

View File

@ -115,7 +115,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) {
t.Fatalf("err: %s", err)
}
if b.config.BundlePrefix != "image-{{.CreateTime}}" {
if b.config.BundlePrefix == "" {
t.Fatalf("bad: %s", b.config.BundlePrefix)
}
}

View File

@ -5,8 +5,6 @@ import (
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strconv"
"time"
)
type bundleCmdData struct {
@ -19,10 +17,6 @@ type bundleCmdData struct {
PrivatePath string
}
type bundlePrefixData struct {
CreateTime string
}
type StepBundleVolume struct{}
func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction {
@ -54,16 +48,6 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
// Bundle the volume
var err error
config.BundlePrefix, err = config.tpl.Process(config.BundlePrefix, bundlePrefixData{
CreateTime: strconv.FormatInt(time.Now().UTC().Unix(), 10),
})
if err != nil {
err := fmt.Errorf("Error processing bundle prefix: %s", err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt
}
config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{
AccountId: config.AccountId,
Architecture: instance.Architecture,