Commit 03a2cc8b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/instance: prefix has CreateTime support

parent c504beac
......@@ -53,7 +53,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if b.config.BundlePrefix == "" {
b.config.BundlePrefix = "image"
b.config.BundlePrefix = "image-{{.CreateTime}}"
}
if b.config.BundleUploadCommand == "" {
......
......@@ -86,7 +86,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) {
t.Fatalf("err: %s", err)
}
if b.config.BundlePrefix != "image" {
if b.config.BundlePrefix != "image-{{.CreateTime}}" {
t.Fatalf("bad: %s", b.config.BundlePrefix)
}
}
......
......@@ -6,7 +6,9 @@ import (
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strconv"
"text/template"
"time"
)
type bundleCmdData struct {
......@@ -19,6 +21,10 @@ type bundleCmdData struct {
PrivatePath string
}
type bundlePrefixData struct {
CreateTime string
}
type StepBundleVolume struct{}
func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction {
......@@ -49,6 +55,13 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
}
// Bundle the volume
var bundlePrefix bytes.Buffer
prefixTData := bundlePrefixData{
CreateTime: strconv.FormatInt(time.Now().UTC().Unix(), 10),
}
t := template.Must(template.New("bundlePrefix").Parse(config.BundlePrefix))
t.Execute(&bundlePrefix, prefixTData)
var bundleCmd bytes.Buffer
tData := bundleCmdData{
AccountId: config.AccountId,
......@@ -56,10 +69,10 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
CertPath: x509RemoteCertPath,
Destination: config.BundleDestination,
KeyPath: x509RemoteKeyPath,
Prefix: config.BundlePrefix,
Prefix: bundlePrefix.String(),
PrivatePath: config.X509UploadPath,
}
t := template.Must(template.New("bundleCmd").Parse(config.BundleVolCommand))
t = template.Must(template.New("bundleCmd").Parse(config.BundleVolCommand))
t.Execute(&bundleCmd, tData)
ui.Say("Bundling the volume...")
......@@ -79,6 +92,10 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
return multistep.ActionHalt
}
// Store the manifest path
state["manifest_path"] = fmt.Sprintf(
"%s/%s.manifest.xml", config.BundleDestination, bundlePrefix.String())
return multistep.ActionContinue
}
......
......@@ -21,6 +21,7 @@ type StepUploadBundle struct{}
func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepAction {
comm := state["communicator"].(packer.Communicator)
config := state["config"].(*Config)
manifestPath := state["manifest_path"].(string)
ui := state["ui"].(packer.Ui)
var uploadCmd bytes.Buffer
......@@ -28,9 +29,8 @@ func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepActio
AccessKey: config.AccessKey,
BucketName: config.S3Bucket,
BundleDirectory: config.BundleDestination,
ManifestPath: fmt.Sprintf(
"%s/%s.manifest.xml", config.BundleDestination, config.BundlePrefix),
SecretKey: config.SecretKey,
ManifestPath: manifestPath,
SecretKey: config.SecretKey,
}
t := template.Must(template.New("uploadCmd").Parse(config.BundleUploadCommand))
t.Execute(&uploadCmd, tData)
......
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