builder/amazon/instance: prefix has CreateTime support
This commit is contained in:
parent
c504beacc6
commit
03a2cc8b22
|
@ -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,8 +29,7 @@ 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),
|
||||
ManifestPath: manifestPath,
|
||||
SecretKey: config.SecretKey,
|
||||
}
|
||||
t := template.Must(template.New("uploadCmd").Parse(config.BundleUploadCommand))
|
||||
|
|
Loading…
Reference in New Issue