Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
75ff149a
Commit
75ff149a
authored
Aug 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/instance: switch to new template stuff
parent
c8a98683
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
41 deletions
+69
-41
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+41
-2
builder/amazon/instance/step_bundle_volume.go
builder/amazon/instance/step_bundle_volume.go
+18
-13
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+1
-19
builder/amazon/instance/step_upload_bundle.go
builder/amazon/instance/step_upload_bundle.go
+9
-7
No files found.
builder/amazon/instance/builder.go
View file @
75ff149a
...
...
@@ -37,6 +37,8 @@ type Config struct {
X509CertPath
string
`mapstructure:"x509_cert_path"`
X509KeyPath
string
`mapstructure:"x509_key_path"`
X509UploadPath
string
`mapstructure:"x509_upload_path"`
tpl
*
common
.
Template
}
type
Builder
struct
{
...
...
@@ -50,6 +52,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return
err
}
b
.
config
.
tpl
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
err
}
if
b
.
config
.
BundleDestination
==
""
{
b
.
config
.
BundleDestination
=
"/tmp"
}
...
...
@@ -87,8 +94,40 @@ func (b *Builder) Prepare(raws ...interface{}) error {
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
()
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
()
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
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
,
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
b
.
config
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
}
}
templates
:=
map
[
string
]
*
string
{
"account_id"
:
&
b
.
config
.
AccountId
,
"ami_name"
:
&
b
.
config
.
AMIName
,
"bundle_destination"
:
&
b
.
config
.
BundleDestination
,
"s3_bucket"
:
&
b
.
config
.
S3Bucket
,
"x509_cert_path"
:
&
b
.
config
.
X509CertPath
,
"x509_key_path"
:
&
b
.
config
.
X509KeyPath
,
"x509_upload_path"
:
&
b
.
config
.
X509UploadPath
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
b
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
b
.
config
.
AccountId
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"account_id is required"
))
...
...
builder/amazon/instance/step_bundle_volume.go
View file @
75ff149a
package
instance
import
(
"bytes"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strconv"
"text/template"
"time"
)
...
...
@@ -55,29 +53,36 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
}
// Bundle the volume
var
bundlePrefix
bytes
.
Buffe
r
prefixTData
:=
bundlePrefixData
{
var
err
erro
r
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
}
t
:=
template
.
Must
(
template
.
New
(
"bundlePrefix"
)
.
Parse
(
config
.
BundlePrefix
))
t
.
Execute
(
&
bundlePrefix
,
prefixTData
)
var
bundleCmd
bytes
.
Buffer
tData
:=
bundleCmdData
{
config
.
BundleVolCommand
,
err
=
config
.
tpl
.
Process
(
config
.
BundleVolCommand
,
bundleCmdData
{
AccountId
:
config
.
AccountId
,
Architecture
:
instance
.
Architecture
,
CertPath
:
x509RemoteCertPath
,
Destination
:
config
.
BundleDestination
,
KeyPath
:
x509RemoteKeyPath
,
Prefix
:
bundlePrefix
.
String
()
,
Prefix
:
config
.
BundlePrefix
,
PrivatePath
:
config
.
X509UploadPath
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error processing bundle volume command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
t
=
template
.
Must
(
template
.
New
(
"bundleCmd"
)
.
Parse
(
config
.
BundleVolCommand
))
t
.
Execute
(
&
bundleCmd
,
tData
)
ui
.
Say
(
"Bundling the volume..."
)
cmd
=
new
(
packer
.
RemoteCmd
)
cmd
.
Command
=
bundleCmd
.
String
()
cmd
.
Command
=
config
.
BundleVolCommand
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error bundling volume: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
...
...
@@ -93,7 +98,7 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
}
// Store the manifest path
manifestName
:=
bundlePrefix
.
String
()
+
".manifest.xml"
manifestName
:=
config
.
BundlePrefix
+
".manifest.xml"
state
[
"manifest_name"
]
=
manifestName
state
[
"manifest_path"
]
=
fmt
.
Sprintf
(
"%s/%s"
,
config
.
BundleDestination
,
manifestName
)
...
...
builder/amazon/instance/step_register_ami.go
View file @
75ff149a
package
instance
import
(
"bytes"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
"strconv"
"text/template"
"time"
)
type
amiNameData
struct
{
CreateTime
string
}
type
StepRegisterAMI
struct
{}
func
(
s
*
StepRegisterAMI
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
...
...
@@ -24,20 +16,10 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
manifestPath
:=
state
[
"remote_manifest_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
// Parse the name of the AMI
amiNameBuf
:=
new
(
bytes
.
Buffer
)
tData
:=
amiNameData
{
strconv
.
FormatInt
(
time
.
Now
()
.
UTC
()
.
Unix
(),
10
),
}
t
:=
template
.
Must
(
template
.
New
(
"ami"
)
.
Parse
(
config
.
AMIName
))
t
.
Execute
(
amiNameBuf
,
tData
)
amiName
:=
amiNameBuf
.
String
()
ui
.
Say
(
"Registering the AMI..."
)
registerOpts
:=
&
ec2
.
RegisterImage
{
ImageLocation
:
manifestPath
,
Name
:
ami
Name
,
Name
:
config
.
AMI
Name
,
}
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
...
...
builder/amazon/instance/step_upload_bundle.go
View file @
75ff149a
package
instance
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"text/template"
)
type
uploadCmdData
struct
{
...
...
@@ -25,19 +23,23 @@ func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepActio
manifestPath
:=
state
[
"manifest_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
var
uploadCmd
bytes
.
Buffe
r
tData
:=
uploadCmdData
{
var
err
erro
r
config
.
BundleUploadCommand
,
err
=
config
.
tpl
.
Process
(
config
.
BundleUploadCommand
,
uploadCmdData
{
AccessKey
:
config
.
AccessKey
,
BucketName
:
config
.
S3Bucket
,
BundleDirectory
:
config
.
BundleDestination
,
ManifestPath
:
manifestPath
,
SecretKey
:
config
.
SecretKey
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error processing bundle upload command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
t
:=
template
.
Must
(
template
.
New
(
"uploadCmd"
)
.
Parse
(
config
.
BundleUploadCommand
))
t
.
Execute
(
&
uploadCmd
,
tData
)
ui
.
Say
(
"Uploading the bundle..."
)
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
uploadCmd
.
String
()
}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
config
.
BundleUploadCommand
}
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading volume: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment