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