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
0231d798
Commit
0231d798
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/instance: new multistep API
parent
b04cff5a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
63 deletions
+63
-63
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+8
-8
builder/amazon/instance/step_bundle_volume.go
builder/amazon/instance/step_bundle_volume.go
+18
-18
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+10
-10
builder/amazon/instance/step_upload_bundle.go
builder/amazon/instance/step_upload_bundle.go
+16
-16
builder/amazon/instance/step_upload_x509_cert.go
builder/amazon/instance/step_upload_x509_cert.go
+11
-11
No files found.
builder/amazon/instance/builder.go
View file @
0231d798
...
...
@@ -176,11 +176,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn
:=
ec2
.
New
(
auth
,
region
)
// Setup the state bag and initial state for the steps
state
:=
make
(
map
[
string
]
interface
{}
)
state
[
"config"
]
=
&
b
.
config
state
[
"ec2"
]
=
ec2conn
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"ec2"
,
ec2conn
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Build the steps
steps
:=
[]
multistep
.
Step
{
...
...
@@ -242,18 +242,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
]
;
ok
{
if
rawErr
,
ok
:=
state
.
GetOk
(
"error"
)
;
ok
{
return
nil
,
rawErr
.
(
error
)
}
// If there are no AMIs, then just return
if
_
,
ok
:=
state
[
"amis"
]
;
!
ok
{
if
_
,
ok
:=
state
.
GetOk
(
"amis"
)
;
!
ok
{
return
nil
,
nil
}
// Build the artifact and return it
artifact
:=
&
awscommon
.
Artifact
{
Amis
:
state
[
"amis"
]
.
(
map
[
string
]
string
),
Amis
:
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
),
BuilderIdValue
:
BuilderId
,
Conn
:
ec2conn
,
}
...
...
builder/amazon/instance/step_bundle_volume.go
View file @
0231d798
...
...
@@ -19,13 +19,13 @@ type bundleCmdData struct {
type
StepBundleVolume
struct
{}
func
(
s
*
StepBundleVolume
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
x509RemoteCertPath
:=
state
[
"x509RemoteCertPath"
]
.
(
string
)
x509RemoteKeyPath
:=
state
[
"x509RemoteKeyPath"
]
.
(
string
)
func
(
s
*
StepBundleVolume
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
instance
:=
state
.
Get
(
"instance"
)
.
(
*
ec2
.
Instance
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
x509RemoteCertPath
:=
state
.
Get
(
"x509RemoteCertPath"
)
.
(
string
)
x509RemoteKeyPath
:=
state
.
Get
(
"x509RemoteKeyPath"
)
.
(
string
)
// Bundle the volume
var
err
error
...
...
@@ -40,7 +40,7 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error processing bundle volume command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -49,26 +49,26 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
cmd
:=
new
(
packer
.
RemoteCmd
)
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
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error bundling volume: %s"
,
err
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
if
cmd
.
ExitStatus
!=
0
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Volume bundling failed. Please see the output above for more
\n
"
+
"details on what went wrong."
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Volume bundling failed. Please see the output above for more
\n
"
+
"details on what went wrong."
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
// Store the manifest path
manifestName
:=
config
.
BundlePrefix
+
".manifest.xml"
state
[
"manifest_name"
]
=
manifestName
state
[
"manifest_path"
]
=
fmt
.
Sprintf
(
"%s/%s"
,
config
.
BundleDestination
,
manifestName
)
state
.
Put
(
"manifest_name"
,
manifestName
)
state
.
Put
(
"manifest_path"
,
fmt
.
Sprintf
(
"%s/%s"
,
config
.
BundleDestination
,
manifestName
)
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepBundleVolume
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepBundleVolume
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/amazon/instance/step_register_ami.go
View file @
0231d798
...
...
@@ -10,11 +10,11 @@ import (
type
StepRegisterAMI
struct
{}
func
(
s
*
StepRegisterAMI
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
manifestPath
:=
state
[
"remote_manifest_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
StepRegisterAMI
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
manifestPath
:=
state
.
Get
(
"remote_manifest_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Registering the AMI..."
)
registerOpts
:=
&
ec2
.
RegisterImage
{
...
...
@@ -25,8 +25,8 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error registering AMI: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error registering AMI: %s"
,
err
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -34,13 +34,13 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
ui
.
Say
(
fmt
.
Sprintf
(
"AMI: %s"
,
registerResp
.
ImageId
))
amis
:=
make
(
map
[
string
]
string
)
amis
[
ec2conn
.
Region
.
Name
]
=
registerResp
.
ImageId
state
[
"amis"
]
=
amis
state
.
Put
(
"amis"
,
amis
)
// Wait for the image to become ready
ui
.
Say
(
"Waiting for AMI to become ready..."
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
registerResp
.
ImageId
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -48,4 +48,4 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
return
multistep
.
ActionContinue
}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/amazon/instance/step_upload_bundle.go
View file @
0231d798
...
...
@@ -16,12 +16,12 @@ type uploadCmdData struct {
type
StepUploadBundle
struct
{}
func
(
s
*
StepUploadBundle
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
manifestName
:=
state
[
"manifest_name"
]
.
(
string
)
manifestPath
:=
state
[
"manifest_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
StepUploadBundle
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
manifestName
:=
state
.
Get
(
"manifest_name"
)
.
(
string
)
manifestPath
:=
state
.
Get
(
"manifest_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
var
err
error
config
.
BundleUploadCommand
,
err
=
config
.
tpl
.
Process
(
config
.
BundleUploadCommand
,
uploadCmdData
{
...
...
@@ -33,7 +33,7 @@ func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepActio
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error processing bundle upload command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -41,23 +41,23 @@ func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepActio
ui
.
Say
(
"Uploading the bundle..."
)
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
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading volume: %s"
,
err
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
if
cmd
.
ExitStatus
!=
0
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Bundle upload failed. Please see the output above for more
\n
"
+
"details on what went wrong."
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Bundle upload failed. Please see the output above for more
\n
"
+
"details on what went wrong."
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"remote_manifest_path"
]
=
fmt
.
Sprintf
(
"%s/%s"
,
config
.
S3Bucket
,
manifestName
)
state
.
Put
(
"remote_manifest_path"
,
fmt
.
Sprintf
(
"%s/%s"
,
config
.
S3Bucket
,
manifestName
)
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepUploadBundle
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepUploadBundle
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/instance/step_upload_x509_cert.go
View file @
0231d798
...
...
@@ -9,34 +9,34 @@ import (
type
StepUploadX509Cert
struct
{}
func
(
s
*
StepUploadX509Cert
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
StepUploadX509Cert
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
x509RemoteCertPath
:=
config
.
X509UploadPath
+
"/cert.pem"
x509RemoteKeyPath
:=
config
.
X509UploadPath
+
"/key.pem"
ui
.
Say
(
"Uploading X509 Certificate..."
)
if
err
:=
s
.
uploadSingle
(
comm
,
x509RemoteCertPath
,
config
.
X509CertPath
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
if
err
:=
s
.
uploadSingle
(
comm
,
x509RemoteKeyPath
,
config
.
X509KeyPath
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
)
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"x509RemoteCertPath"
]
=
x509RemoteCertPath
state
[
"x509RemoteKeyPath"
]
=
x509RemoteKeyPath
state
.
Put
(
"x509RemoteCertPath"
,
x509RemoteCertPath
)
state
.
Put
(
"x509RemoteKeyPath"
,
x509RemoteKeyPath
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepUploadX509Cert
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepUploadX509Cert
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
func
(
s
*
StepUploadX509Cert
)
uploadSingle
(
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
f
,
err
:=
os
.
Open
(
src
)
...
...
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