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
80ed7edd
Commit
80ed7edd
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: new multistep API
parent
f74ff911
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
205 additions
and
201 deletions
+205
-201
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+8
-8
builder/amazon/chroot/cleanup.go
builder/amazon/chroot/cleanup.go
+5
-1
builder/amazon/chroot/step_attach_volume.go
builder/amazon/chroot/step_attach_volume.go
+14
-14
builder/amazon/chroot/step_chroot_provision.go
builder/amazon/chroot/step_chroot_provision.go
+6
-6
builder/amazon/chroot/step_copy_files.go
builder/amazon/chroot/step_copy_files.go
+9
-9
builder/amazon/chroot/step_create_volume.go
builder/amazon/chroot/step_create_volume.go
+12
-12
builder/amazon/chroot/step_early_cleanup.go
builder/amazon/chroot/step_early_cleanup.go
+5
-5
builder/amazon/chroot/step_early_unflock.go
builder/amazon/chroot/step_early_unflock.go
+5
-5
builder/amazon/chroot/step_flock.go
builder/amazon/chroot/step_flock.go
+8
-8
builder/amazon/chroot/step_instance_info.go
builder/amazon/chroot/step_instance_info.go
+8
-8
builder/amazon/chroot/step_mount_device.go
builder/amazon/chroot/step_mount_device.go
+15
-15
builder/amazon/chroot/step_mount_extra.go
builder/amazon/chroot/step_mount_extra.go
+11
-11
builder/amazon/chroot/step_prepare_device.go
builder/amazon/chroot/step_prepare_device.go
+7
-7
builder/amazon/chroot/step_register_ami.go
builder/amazon/chroot/step_register_ami.go
+11
-11
builder/amazon/chroot/step_snapshot.go
builder/amazon/chroot/step_snapshot.go
+12
-12
builder/amazon/chroot/step_source_ami_info.go
builder/amazon/chroot/step_source_ami_info.go
+9
-9
builder/amazon/common/instance.go
builder/amazon/common/instance.go
+2
-2
builder/amazon/common/step_ami_region_copy.go
builder/amazon/common/step_ami_region_copy.go
+9
-9
builder/amazon/common/step_create_tags.go
builder/amazon/common/step_create_tags.go
+6
-6
builder/amazon/common/step_key_pair.go
builder/amazon/common/step_key_pair.go
+12
-12
builder/amazon/common/step_modify_ami_attributes.go
builder/amazon/common/step_modify_ami_attributes.go
+6
-6
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+16
-16
builder/amazon/common/step_security_group.go
builder/amazon/common/step_security_group.go
+9
-9
No files found.
builder/amazon/chroot/builder.go
View file @
80ed7edd
...
@@ -167,11 +167,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -167,11 +167,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn
:=
ec2
.
New
(
auth
,
region
)
ec2conn
:=
ec2
.
New
(
auth
,
region
)
// Setup the state bag and initial state for the steps
// Setup the state bag and initial state for the steps
state
:=
make
(
map
[
string
]
interface
{}
)
state
:=
new
(
multistep
.
BasicStateBag
)
state
[
"config"
]
=
&
b
.
config
state
.
Put
(
"config"
,
&
b
.
config
)
state
[
"ec2"
]
=
ec2conn
state
.
Put
(
"ec2"
,
ec2conn
)
state
[
"hook"
]
=
hook
state
.
Put
(
"hook"
,
hook
)
state
[
"ui"
]
=
ui
state
.
Put
(
"ui"
,
ui
)
// Build the steps
// Build the steps
steps
:=
[]
multistep
.
Step
{
steps
:=
[]
multistep
.
Step
{
...
@@ -216,18 +216,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -216,18 +216,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b
.
runner
.
Run
(
state
)
b
.
runner
.
Run
(
state
)
// If there was an error, return that
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
]
;
ok
{
if
rawErr
,
ok
:=
state
.
GetOk
(
"error"
)
;
ok
{
return
nil
,
rawErr
.
(
error
)
return
nil
,
rawErr
.
(
error
)
}
}
// If there are no AMIs, then just return
// If there are no AMIs, then just return
if
_
,
ok
:=
state
[
"amis"
]
;
!
ok
{
if
_
,
ok
:=
state
.
GetOk
(
"amis"
)
;
!
ok
{
return
nil
,
nil
return
nil
,
nil
}
}
// Build the artifact and return it
// Build the artifact and return it
artifact
:=
&
awscommon
.
Artifact
{
artifact
:=
&
awscommon
.
Artifact
{
Amis
:
state
[
"amis"
]
.
(
map
[
string
]
string
),
Amis
:
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
),
BuilderIdValue
:
BuilderId
,
BuilderIdValue
:
BuilderId
,
Conn
:
ec2conn
,
Conn
:
ec2conn
,
}
}
...
...
builder/amazon/chroot/cleanup.go
View file @
80ed7edd
package
chroot
package
chroot
import
(
"github.com/mitchellh/multistep"
)
// Cleanup is an interface that some steps implement for early cleanup.
// Cleanup is an interface that some steps implement for early cleanup.
type
Cleanup
interface
{
type
Cleanup
interface
{
CleanupFunc
(
m
ap
[
string
]
interface
{}
)
error
CleanupFunc
(
m
ultistep
.
StateBag
)
error
}
}
builder/amazon/chroot/step_attach_volume.go
View file @
80ed7edd
...
@@ -21,12 +21,12 @@ type StepAttachVolume struct {
...
@@ -21,12 +21,12 @@ type StepAttachVolume struct {
volumeId
string
volumeId
string
}
}
func
(
s
*
StepAttachVolume
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepAttachVolume
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
device
:=
state
[
"device"
]
.
(
string
)
device
:=
state
.
Get
(
"device"
)
.
(
string
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
instance
:=
state
.
Get
(
"instance"
)
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
volumeId
:=
state
[
"volume_id"
]
.
(
string
)
volumeId
:=
state
.
Get
(
"volume_id"
)
.
(
string
)
// For the API call, it expects "sd" prefixed devices.
// For the API call, it expects "sd" prefixed devices.
attachVolume
:=
strings
.
Replace
(
device
,
"/xvd"
,
"/sd"
,
1
)
attachVolume
:=
strings
.
Replace
(
device
,
"/xvd"
,
"/sd"
,
1
)
...
@@ -35,7 +35,7 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
...
@@ -35,7 +35,7 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
_
,
err
:=
ec2conn
.
AttachVolume
(
volumeId
,
instance
.
InstanceId
,
attachVolume
)
_
,
err
:=
ec2conn
.
AttachVolume
(
volumeId
,
instance
.
InstanceId
,
attachVolume
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error attaching volume: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error attaching volume: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -67,29 +67,29 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
...
@@ -67,29 +67,29 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for volume: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for volume: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
state
[
"attach_cleanup"
]
=
s
state
.
Put
(
"attach_cleanup"
,
s
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepAttachVolume
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepAttachVolume
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
}
}
}
}
func
(
s
*
StepAttachVolume
)
CleanupFunc
(
state
m
ap
[
string
]
interface
{}
)
error
{
func
(
s
*
StepAttachVolume
)
CleanupFunc
(
state
m
ultistep
.
StateBag
)
error
{
if
!
s
.
attached
{
if
!
s
.
attached
{
return
nil
return
nil
}
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Detaching EBS volume..."
)
ui
.
Say
(
"Detaching EBS volume..."
)
_
,
err
:=
ec2conn
.
DetachVolume
(
s
.
volumeId
)
_
,
err
:=
ec2conn
.
DetachVolume
(
s
.
volumeId
)
...
...
builder/amazon/chroot/step_chroot_provision.go
View file @
80ed7edd
...
@@ -11,10 +11,10 @@ type StepChrootProvision struct {
...
@@ -11,10 +11,10 @@ type StepChrootProvision struct {
mounts
[]
string
mounts
[]
string
}
}
func
(
s
*
StepChrootProvision
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepChrootProvision
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
hook
:=
state
[
"hook"
]
.
(
packer
.
Hook
)
hook
:=
state
.
Get
(
"hook"
)
.
(
packer
.
Hook
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// Create our communicator
// Create our communicator
comm
:=
&
Communicator
{
comm
:=
&
Communicator
{
...
@@ -24,11 +24,11 @@ func (s *StepChrootProvision) Run(state map[string]interface{}) multistep.StepAc
...
@@ -24,11 +24,11 @@ func (s *StepChrootProvision) Run(state map[string]interface{}) multistep.StepAc
// Provision
// Provision
log
.
Println
(
"Running the provision hook"
)
log
.
Println
(
"Running the provision hook"
)
if
err
:=
hook
.
Run
(
packer
.
HookProvision
,
ui
,
comm
,
nil
);
err
!=
nil
{
if
err
:=
hook
.
Run
(
packer
.
HookProvision
,
ui
,
comm
,
nil
);
err
!=
nil
{
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepChrootProvision
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepChrootProvision
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_copy_files.go
View file @
80ed7edd
...
@@ -19,10 +19,10 @@ type StepCopyFiles struct {
...
@@ -19,10 +19,10 @@ type StepCopyFiles struct {
files
[]
string
files
[]
string
}
}
func
(
s
*
StepCopyFiles
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepCopyFiles
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
s
.
files
=
make
([]
string
,
0
,
len
(
config
.
CopyFiles
))
s
.
files
=
make
([]
string
,
0
,
len
(
config
.
CopyFiles
))
if
len
(
config
.
CopyFiles
)
>
0
{
if
len
(
config
.
CopyFiles
)
>
0
{
...
@@ -34,7 +34,7 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -34,7 +34,7 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
if
err
:=
s
.
copySingle
(
chrootPath
,
path
);
err
!=
nil
{
if
err
:=
s
.
copySingle
(
chrootPath
,
path
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error copying file: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error copying file: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -43,18 +43,18 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -43,18 +43,18 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
}
}
}
}
state
[
"copy_files_cleanup"
]
=
s
state
.
Put
(
"copy_files_cleanup"
,
s
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepCopyFiles
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepCopyFiles
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
}
}
}
}
func
(
s
*
StepCopyFiles
)
CleanupFunc
(
m
ap
[
string
]
interface
{}
)
error
{
func
(
s
*
StepCopyFiles
)
CleanupFunc
(
m
ultistep
.
StateBag
)
error
{
if
s
.
files
!=
nil
{
if
s
.
files
!=
nil
{
for
_
,
file
:=
range
s
.
files
{
for
_
,
file
:=
range
s
.
files
{
log
.
Printf
(
"Removing: %s"
,
file
)
log
.
Printf
(
"Removing: %s"
,
file
)
...
...
builder/amazon/chroot/step_create_volume.go
View file @
80ed7edd
...
@@ -18,11 +18,11 @@ type StepCreateVolume struct {
...
@@ -18,11 +18,11 @@ type StepCreateVolume struct {
volumeId
string
volumeId
string
}
}
func
(
s
*
StepCreateVolume
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepCreateVolume
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
image
:=
state
[
"source_image"
]
.
(
*
ec2
.
Image
)
image
:=
state
.
Get
(
"source_image"
)
.
(
*
ec2
.
Image
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
instance
:=
state
.
Get
(
"instance"
)
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// Determine the root device snapshot
// Determine the root device snapshot
log
.
Printf
(
"Searching for root device of the image (%s)"
,
image
.
RootDeviceName
)
log
.
Printf
(
"Searching for root device of the image (%s)"
,
image
.
RootDeviceName
)
...
@@ -36,7 +36,7 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
...
@@ -36,7 +36,7 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
if
rootDevice
==
nil
{
if
rootDevice
==
nil
{
err
:=
fmt
.
Errorf
(
"Couldn't find root device!"
)
err
:=
fmt
.
Errorf
(
"Couldn't find root device!"
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -54,7 +54,7 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
...
@@ -54,7 +54,7 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
createVolumeResp
,
err
:=
ec2conn
.
CreateVolume
(
createVolume
)
createVolumeResp
,
err
:=
ec2conn
.
CreateVolume
(
createVolume
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating root volume: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating root volume: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -82,22 +82,22 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
...
@@ -82,22 +82,22 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for volume: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for volume: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
state
[
"volume_id"
]
=
s
.
volumeId
state
.
Put
(
"volume_id"
,
s
.
volumeId
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepCreateVolume
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepCreateVolume
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
volumeId
==
""
{
if
s
.
volumeId
==
""
{
return
return
}
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting the created EBS volume..."
)
ui
.
Say
(
"Deleting the created EBS volume..."
)
_
,
err
:=
ec2conn
.
DeleteVolume
(
s
.
volumeId
)
_
,
err
:=
ec2conn
.
DeleteVolume
(
s
.
volumeId
)
...
...
builder/amazon/chroot/step_early_cleanup.go
View file @
80ed7edd
...
@@ -11,8 +11,8 @@ import (
...
@@ -11,8 +11,8 @@ import (
// prepare for snapshotting and creating an AMI.
// prepare for snapshotting and creating an AMI.
type
StepEarlyCleanup
struct
{}
type
StepEarlyCleanup
struct
{}
func
(
s
*
StepEarlyCleanup
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepEarlyCleanup
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
cleanupKeys
:=
[]
string
{
cleanupKeys
:=
[]
string
{
"copy_files_cleanup"
,
"copy_files_cleanup"
,
"mount_extra_cleanup"
,
"mount_extra_cleanup"
,
...
@@ -21,11 +21,11 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
...
@@ -21,11 +21,11 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
}
}
for
_
,
key
:=
range
cleanupKeys
{
for
_
,
key
:=
range
cleanupKeys
{
c
:=
state
[
key
]
.
(
Cleanup
)
c
:=
state
.
Get
(
key
)
.
(
Cleanup
)
log
.
Printf
(
"Running cleanup func: %s"
,
key
)
log
.
Printf
(
"Running cleanup func: %s"
,
key
)
if
err
:=
c
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
c
.
CleanupFunc
(
state
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error cleaning up: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error cleaning up: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -34,4 +34,4 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
...
@@ -34,4 +34,4 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepEarlyCleanup
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepEarlyCleanup
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_early_unflock.go
View file @
80ed7edd
...
@@ -10,14 +10,14 @@ import (
...
@@ -10,14 +10,14 @@ import (
// StepEarlyUnflock unlocks the flock.
// StepEarlyUnflock unlocks the flock.
type
StepEarlyUnflock
struct
{}
type
StepEarlyUnflock
struct
{}
func
(
s
*
StepEarlyUnflock
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepEarlyUnflock
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
cleanup
:=
state
[
"flock_cleanup"
]
.
(
Cleanup
)
cleanup
:=
state
.
Get
(
"flock_cleanup"
)
.
(
Cleanup
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
log
.
Println
(
"Unlocking file lock..."
)
log
.
Println
(
"Unlocking file lock..."
)
if
err
:=
cleanup
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
cleanup
.
CleanupFunc
(
state
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error unlocking file lock: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error unlocking file lock: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -25,4 +25,4 @@ func (s *StepEarlyUnflock) Run(state map[string]interface{}) multistep.StepActio
...
@@ -25,4 +25,4 @@ func (s *StepEarlyUnflock) Run(state map[string]interface{}) multistep.StepActio
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepEarlyUnflock
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepEarlyUnflock
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_flock.go
View file @
80ed7edd
...
@@ -17,13 +17,13 @@ type StepFlock struct {
...
@@ -17,13 +17,13 @@ type StepFlock struct {
fh
*
os
.
File
fh
*
os
.
File
}
}
func
(
s
*
StepFlock
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepFlock
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
lockfile
:=
"/var/lock/packer-chroot/lock"
lockfile
:=
"/var/lock/packer-chroot/lock"
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
lockfile
),
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
lockfile
),
0755
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -32,7 +32,7 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -32,7 +32,7 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
f
,
err
:=
os
.
Create
(
lockfile
)
f
,
err
:=
os
.
Create
(
lockfile
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -40,7 +40,7 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -40,7 +40,7 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
// LOCK!
// LOCK!
if
err
:=
lockFile
(
f
);
err
!=
nil
{
if
err
:=
lockFile
(
f
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating lock: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -49,15 +49,15 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -49,15 +49,15 @@ func (s *StepFlock) Run(state map[string]interface{}) multistep.StepAction {
// the lock.
// the lock.
s
.
fh
=
f
s
.
fh
=
f
state
[
"flock_cleanup"
]
=
s
state
.
Put
(
"flock_cleanup"
,
s
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepFlock
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepFlock
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
s
.
CleanupFunc
(
state
)
s
.
CleanupFunc
(
state
)
}
}
func
(
s
*
StepFlock
)
CleanupFunc
(
state
m
ap
[
string
]
interface
{}
)
error
{
func
(
s
*
StepFlock
)
CleanupFunc
(
state
m
ultistep
.
StateBag
)
error
{
if
s
.
fh
==
nil
{
if
s
.
fh
==
nil
{
return
nil
return
nil
}
}
...
...
builder/amazon/chroot/step_instance_info.go
View file @
80ed7edd
...
@@ -12,9 +12,9 @@ import (
...
@@ -12,9 +12,9 @@ import (
// StepInstanceInfo verifies that this builder is running on an EC2 instance.
// StepInstanceInfo verifies that this builder is running on an EC2 instance.
type
StepInstanceInfo
struct
{}
type
StepInstanceInfo
struct
{}
func
(
s
*
StepInstanceInfo
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepInstanceInfo
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// Get our own instance ID
// Get our own instance ID
ui
.
Say
(
"Gathering information about this EC2 instance..."
)
ui
.
Say
(
"Gathering information about this EC2 instance..."
)
...
@@ -24,7 +24,7 @@ func (s *StepInstanceInfo) Run(state map[string]interface{}) multistep.StepActio
...
@@ -24,7 +24,7 @@ func (s *StepInstanceInfo) Run(state map[string]interface{}) multistep.StepActio
err
:=
fmt
.
Errorf
(
err
:=
fmt
.
Errorf
(
"Error retrieving the ID of the instance Packer is running on.
\n
"
+
"Error retrieving the ID of the instance Packer is running on.
\n
"
+
"Please verify Packer is running on a proper AWS EC2 instance."
)
"Please verify Packer is running on a proper AWS EC2 instance."
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -36,22 +36,22 @@ func (s *StepInstanceInfo) Run(state map[string]interface{}) multistep.StepActio
...
@@ -36,22 +36,22 @@ func (s *StepInstanceInfo) Run(state map[string]interface{}) multistep.StepActio
instancesResp
,
err
:=
ec2conn
.
Instances
([]
string
{
instanceId
},
ec2
.
NewFilter
())
instancesResp
,
err
:=
ec2conn
.
Instances
([]
string
{
instanceId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error getting instance data: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error getting instance data: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
if
len
(
instancesResp
.
Reservations
)
==
0
{
if
len
(
instancesResp
.
Reservations
)
==
0
{
err
:=
fmt
.
Errorf
(
"Error getting instance data: no instance found."
)
err
:=
fmt
.
Errorf
(
"Error getting instance data: no instance found."
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
instance
:=
&
instancesResp
.
Reservations
[
0
]
.
Instances
[
0
]
instance
:=
&
instancesResp
.
Reservations
[
0
]
.
Instances
[
0
]
state
[
"instance"
]
=
instance
state
.
Put
(
"instance"
,
instance
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepInstanceInfo
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepInstanceInfo
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_mount_device.go
View file @
80ed7edd
...
@@ -24,10 +24,10 @@ type StepMountDevice struct {
...
@@ -24,10 +24,10 @@ type StepMountDevice struct {
mountPath
string
mountPath
string
}
}
func
(
s
*
StepMountDevice
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepMountDevice
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
device
:=
state
[
"device"
]
.
(
string
)
device
:=
state
.
Get
(
"device"
)
.
(
string
)
mountPath
,
err
:=
config
.
tpl
.
Process
(
config
.
MountPath
,
&
mountPathData
{
mountPath
,
err
:=
config
.
tpl
.
Process
(
config
.
MountPath
,
&
mountPathData
{
Device
:
filepath
.
Base
(
device
),
Device
:
filepath
.
Base
(
device
),
...
@@ -35,7 +35,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
...
@@ -35,7 +35,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing mount directory: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error preparing mount directory: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -43,7 +43,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
...
@@ -43,7 +43,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
mountPath
,
err
=
filepath
.
Abs
(
mountPath
)
mountPath
,
err
=
filepath
.
Abs
(
mountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing mount directory: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error preparing mount directory: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -52,7 +52,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
...
@@ -52,7 +52,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
if
err
:=
os
.
MkdirAll
(
mountPath
,
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
mountPath
,
0755
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating mount directory: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating mount directory: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -65,33 +65,33 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
...
@@ -65,33 +65,33 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
err
:=
cmd
.
Run
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
err
:=
fmt
.
Errorf
(
"Error mounting root volume: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
"Error mounting root volume: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
// Set the mount path so we remember to unmount it later
// Set the mount path so we remember to unmount it later
s
.
mountPath
=
mountPath
s
.
mountPath
=
mountPath
state
[
"mount_path"
]
=
s
.
mountPath
state
.
Put
(
"mount_path"
,
s
.
mountPath
)
state
[
"mount_device_cleanup"
]
=
s
state
.
Put
(
"mount_device_cleanup"
,
s
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepMountDevice
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepMountDevice
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
}
}
}
}
func
(
s
*
StepMountDevice
)
CleanupFunc
(
state
m
ap
[
string
]
interface
{}
)
error
{
func
(
s
*
StepMountDevice
)
CleanupFunc
(
state
m
ultistep
.
StateBag
)
error
{
if
s
.
mountPath
==
""
{
if
s
.
mountPath
==
""
{
return
nil
return
nil
}
}
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Unmounting the root device..."
)
ui
.
Say
(
"Unmounting the root device..."
)
unmountCommand
:=
fmt
.
Sprintf
(
"%s %s"
,
config
.
UnmountCommand
,
s
.
mountPath
)
unmountCommand
:=
fmt
.
Sprintf
(
"%s %s"
,
config
.
UnmountCommand
,
s
.
mountPath
)
...
...
builder/amazon/chroot/step_mount_extra.go
View file @
80ed7edd
...
@@ -17,10 +17,10 @@ type StepMountExtra struct {
...
@@ -17,10 +17,10 @@ type StepMountExtra struct {
mounts
[]
string
mounts
[]
string
}
}
func
(
s
*
StepMountExtra
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepMountExtra
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
s
.
mounts
=
make
([]
string
,
0
,
len
(
config
.
ChrootMounts
))
s
.
mounts
=
make
([]
string
,
0
,
len
(
config
.
ChrootMounts
))
...
@@ -30,7 +30,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
...
@@ -30,7 +30,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
if
err
:=
os
.
MkdirAll
(
innerPath
,
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
innerPath
,
0755
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating mount directory: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating mount directory: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -53,7 +53,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
...
@@ -53,7 +53,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
err
:=
cmd
.
Run
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
err
:=
fmt
.
Errorf
(
"Error mounting: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
"Error mounting: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -61,12 +61,12 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
...
@@ -61,12 +61,12 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
s
.
mounts
=
append
(
s
.
mounts
,
innerPath
)
s
.
mounts
=
append
(
s
.
mounts
,
innerPath
)
}
}
state
[
"mount_extra_cleanup"
]
=
s
state
.
Put
(
"mount_extra_cleanup"
,
s
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepMountExtra
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepMountExtra
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
if
err
:=
s
.
CleanupFunc
(
state
);
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
...
@@ -74,12 +74,12 @@ func (s *StepMountExtra) Cleanup(state map[string]interface{}) {
...
@@ -74,12 +74,12 @@ func (s *StepMountExtra) Cleanup(state map[string]interface{}) {
}
}
}
}
func
(
s
*
StepMountExtra
)
CleanupFunc
(
state
m
ap
[
string
]
interface
{}
)
error
{
func
(
s
*
StepMountExtra
)
CleanupFunc
(
state
m
ultistep
.
StateBag
)
error
{
if
s
.
mounts
==
nil
{
if
s
.
mounts
==
nil
{
return
nil
return
nil
}
}
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
for
len
(
s
.
mounts
)
>
0
{
for
len
(
s
.
mounts
)
>
0
{
var
path
string
var
path
string
lastIndex
:=
len
(
s
.
mounts
)
-
1
lastIndex
:=
len
(
s
.
mounts
)
-
1
...
...
builder/amazon/chroot/step_prepare_device.go
View file @
80ed7edd
...
@@ -13,9 +13,9 @@ type StepPrepareDevice struct {
...
@@ -13,9 +13,9 @@ type StepPrepareDevice struct {
mounts
[]
string
mounts
[]
string
}
}
func
(
s
*
StepPrepareDevice
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepPrepareDevice
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
device
:=
config
.
DevicePath
device
:=
config
.
DevicePath
if
device
==
""
{
if
device
==
""
{
...
@@ -24,7 +24,7 @@ func (s *StepPrepareDevice) Run(state map[string]interface{}) multistep.StepActi
...
@@ -24,7 +24,7 @@ func (s *StepPrepareDevice) Run(state map[string]interface{}) multistep.StepActi
device
,
err
=
AvailableDevice
()
device
,
err
=
AvailableDevice
()
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error finding available device: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error finding available device: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -32,14 +32,14 @@ func (s *StepPrepareDevice) Run(state map[string]interface{}) multistep.StepActi
...
@@ -32,14 +32,14 @@ func (s *StepPrepareDevice) Run(state map[string]interface{}) multistep.StepActi
if
_
,
err
:=
os
.
Stat
(
device
);
err
==
nil
{
if
_
,
err
:=
os
.
Stat
(
device
);
err
==
nil
{
err
:=
fmt
.
Errorf
(
"Device is in use: %s"
,
device
)
err
:=
fmt
.
Errorf
(
"Device is in use: %s"
,
device
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
log
.
Printf
(
"Device: %s"
,
device
)
log
.
Printf
(
"Device: %s"
,
device
)
state
[
"device"
]
=
device
state
.
Put
(
"device"
,
device
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepPrepareDevice
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepPrepareDevice
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_register_ami.go
View file @
80ed7edd
...
@@ -11,12 +11,12 @@ import (
...
@@ -11,12 +11,12 @@ import (
// StepRegisterAMI creates the AMI.
// StepRegisterAMI creates the AMI.
type
StepRegisterAMI
struct
{}
type
StepRegisterAMI
struct
{}
func
(
s
*
StepRegisterAMI
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepRegisterAMI
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
image
:=
state
[
"source_image"
]
.
(
*
ec2
.
Image
)
image
:=
state
.
Get
(
"source_image"
)
.
(
*
ec2
.
Image
)
snapshotId
:=
state
[
"snapshot_id"
]
.
(
string
)
snapshotId
:=
state
.
Get
(
"snapshot_id"
)
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Registering the AMI..."
)
ui
.
Say
(
"Registering the AMI..."
)
blockDevices
:=
make
([]
ec2
.
BlockDeviceMapping
,
len
(
image
.
BlockDevices
))
blockDevices
:=
make
([]
ec2
.
BlockDeviceMapping
,
len
(
image
.
BlockDevices
))
...
@@ -40,8 +40,8 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
...
@@ -40,8 +40,8 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error registering AMI: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error registering AMI: %s"
,
err
)
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
ui
.
Error
(
state
.
Get
(
"error"
)
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -49,13 +49,13 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
...
@@ -49,13 +49,13 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
ui
.
Say
(
fmt
.
Sprintf
(
"AMI: %s"
,
registerResp
.
ImageId
))
ui
.
Say
(
fmt
.
Sprintf
(
"AMI: %s"
,
registerResp
.
ImageId
))
amis
:=
make
(
map
[
string
]
string
)
amis
:=
make
(
map
[
string
]
string
)
amis
[
ec2conn
.
Region
.
Name
]
=
registerResp
.
ImageId
amis
[
ec2conn
.
Region
.
Name
]
=
registerResp
.
ImageId
state
[
"amis"
]
=
amis
state
.
Put
(
"amis"
,
amis
)
// Wait for the image to become ready
// Wait for the image to become ready
ui
.
Say
(
"Waiting for AMI to become ready..."
)
ui
.
Say
(
"Waiting for AMI to become ready..."
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
registerResp
.
ImageId
);
err
!=
nil
{
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
registerResp
.
ImageId
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -63,4 +63,4 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
...
@@ -63,4 +63,4 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/amazon/chroot/step_snapshot.go
View file @
80ed7edd
...
@@ -17,16 +17,16 @@ type StepSnapshot struct {
...
@@ -17,16 +17,16 @@ type StepSnapshot struct {
snapshotId
string
snapshotId
string
}
}
func
(
s
*
StepSnapshot
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepSnapshot
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
volumeId
:=
state
[
"volume_id"
]
.
(
string
)
volumeId
:=
state
.
Get
(
"volume_id"
)
.
(
string
)
ui
.
Say
(
"Creating snapshot..."
)
ui
.
Say
(
"Creating snapshot..."
)
createSnapResp
,
err
:=
ec2conn
.
CreateSnapshot
(
volumeId
,
""
)
createSnapResp
,
err
:=
ec2conn
.
CreateSnapshot
(
volumeId
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating snapshot: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating snapshot: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -58,26 +58,26 @@ func (s *StepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -58,26 +58,26 @@ func (s *StepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
state
[
"snapshot_id"
]
=
s
.
snapshotId
state
.
Put
(
"snapshot_id"
,
s
.
snapshotId
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepSnapshot
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepSnapshot
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
snapshotId
==
""
{
if
s
.
snapshotId
==
""
{
return
return
}
}
_
,
cancelled
:=
state
[
multistep
.
StateCancelled
]
_
,
cancelled
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
_
,
halted
:=
state
[
multistep
.
StateHalted
]
_
,
halted
:=
state
.
GetOk
(
multistep
.
StateHalted
)
if
cancelled
||
halted
{
if
cancelled
||
halted
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Removing snapshot since we cancelled or halted..."
)
ui
.
Say
(
"Removing snapshot since we cancelled or halted..."
)
_
,
err
:=
ec2conn
.
DeleteSnapshots
([]
string
{
s
.
snapshotId
})
_
,
err
:=
ec2conn
.
DeleteSnapshots
([]
string
{
s
.
snapshotId
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
builder/amazon/chroot/step_source_ami_info.go
View file @
80ed7edd
...
@@ -14,23 +14,23 @@ import (
...
@@ -14,23 +14,23 @@ import (
// source_image *ec2.Image - the source AMI info
// source_image *ec2.Image - the source AMI info
type
StepSourceAMIInfo
struct
{}
type
StepSourceAMIInfo
struct
{}
func
(
s
*
StepSourceAMIInfo
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepSourceAMIInfo
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Inspecting the source AMI..."
)
ui
.
Say
(
"Inspecting the source AMI..."
)
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
config
.
SourceAmi
},
ec2
.
NewFilter
())
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
config
.
SourceAmi
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error querying AMI: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error querying AMI: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
if
len
(
imageResp
.
Images
)
==
0
{
if
len
(
imageResp
.
Images
)
==
0
{
err
:=
fmt
.
Errorf
(
"Source AMI '%s' was not found!"
,
config
.
SourceAmi
)
err
:=
fmt
.
Errorf
(
"Source AMI '%s' was not found!"
,
config
.
SourceAmi
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -40,13 +40,13 @@ func (s *StepSourceAMIInfo) Run(state map[string]interface{}) multistep.StepActi
...
@@ -40,13 +40,13 @@ func (s *StepSourceAMIInfo) Run(state map[string]interface{}) multistep.StepActi
// It must be EBS-backed otherwise the build won't work
// It must be EBS-backed otherwise the build won't work
if
image
.
RootDeviceType
!=
"ebs"
{
if
image
.
RootDeviceType
!=
"ebs"
{
err
:=
fmt
.
Errorf
(
"The root device of the source AMI must be EBS-backed."
)
err
:=
fmt
.
Errorf
(
"The root device of the source AMI must be EBS-backed."
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
state
[
"source_image"
]
=
image
state
.
Put
(
"source_image"
,
image
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepSourceAMIInfo
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepSourceAMIInfo
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/amazon/common/instance.go
View file @
80ed7edd
...
@@ -26,7 +26,7 @@ type StateChangeConf struct {
...
@@ -26,7 +26,7 @@ type StateChangeConf struct {
Conn
*
ec2
.
EC2
Conn
*
ec2
.
EC2
Pending
[]
string
Pending
[]
string
Refresh
StateRefreshFunc
Refresh
StateRefreshFunc
StepState
m
ap
[
string
]
interface
{}
StepState
m
ultistep
.
StateBag
Target
string
Target
string
}
}
...
@@ -62,7 +62,7 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
...
@@ -62,7 +62,7 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
}
}
if
conf
.
StepState
!=
nil
{
if
conf
.
StepState
!=
nil
{
if
_
,
ok
:=
conf
.
StepState
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
conf
.
StepState
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
nil
,
errors
.
New
(
"interrupted"
)
return
nil
,
errors
.
New
(
"interrupted"
)
}
}
}
}
...
...
builder/amazon/common/step_ami_region_copy.go
View file @
80ed7edd
...
@@ -13,10 +13,10 @@ type StepAMIRegionCopy struct {
...
@@ -13,10 +13,10 @@ type StepAMIRegionCopy struct {
Tags
map
[
string
]
string
Tags
map
[
string
]
string
}
}
func
(
s
*
StepAMIRegionCopy
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepAMIRegionCopy
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
amis
:=
state
[
"amis"
]
.
(
map
[
string
]
string
)
amis
:=
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
if
len
(
s
.
Regions
)
==
0
{
if
len
(
s
.
Regions
)
==
0
{
...
@@ -36,7 +36,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
...
@@ -36,7 +36,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error Copying AMI (%s) to region (%s): %s"
,
ami
,
region
,
err
)
err
:=
fmt
.
Errorf
(
"Error Copying AMI (%s) to region (%s): %s"
,
ami
,
region
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -44,7 +44,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
...
@@ -44,7 +44,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for AMI (%s) in region (%s) to become ready..."
,
resp
.
ImageId
,
region
))
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for AMI (%s) in region (%s) to become ready..."
,
resp
.
ImageId
,
region
))
if
err
:=
WaitForAMI
(
regionconn
,
resp
.
ImageId
);
err
!=
nil
{
if
err
:=
WaitForAMI
(
regionconn
,
resp
.
ImageId
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI (%s) in region (%s): %s"
,
resp
.
ImageId
,
region
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for AMI (%s) in region (%s): %s"
,
resp
.
ImageId
,
region
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -62,7 +62,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
...
@@ -62,7 +62,7 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
_
,
err
:=
regionconn
.
CreateTags
([]
string
{
resp
.
ImageId
},
ec2Tags
)
_
,
err
:=
regionconn
.
CreateTags
([]
string
{
resp
.
ImageId
},
ec2Tags
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
resp
.
ImageId
,
err
)
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
resp
.
ImageId
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -71,10 +71,10 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
...
@@ -71,10 +71,10 @@ func (s *StepAMIRegionCopy) Run(state map[string]interface{}) multistep.StepActi
amis
[
region
]
=
resp
.
ImageId
amis
[
region
]
=
resp
.
ImageId
}
}
state
[
"amis"
]
=
amis
state
.
Put
(
"amis"
,
amis
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepAMIRegionCopy
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepAMIRegionCopy
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
// No cleanup...
// No cleanup...
}
}
builder/amazon/common/step_create_tags.go
View file @
80ed7edd
...
@@ -11,10 +11,10 @@ type StepCreateTags struct {
...
@@ -11,10 +11,10 @@ type StepCreateTags struct {
Tags
map
[
string
]
string
Tags
map
[
string
]
string
}
}
func
(
s
*
StepCreateTags
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepCreateTags
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
amis
:=
state
[
"amis"
]
.
(
map
[
string
]
string
)
amis
:=
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
if
len
(
s
.
Tags
)
>
0
{
if
len
(
s
.
Tags
)
>
0
{
...
@@ -29,7 +29,7 @@ func (s *StepCreateTags) Run(state map[string]interface{}) multistep.StepAction
...
@@ -29,7 +29,7 @@ func (s *StepCreateTags) Run(state map[string]interface{}) multistep.StepAction
_
,
err
:=
ec2conn
.
CreateTags
([]
string
{
ami
},
ec2Tags
)
_
,
err
:=
ec2conn
.
CreateTags
([]
string
{
ami
},
ec2Tags
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
ami
,
err
)
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
ami
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -38,6 +38,6 @@ func (s *StepCreateTags) Run(state map[string]interface{}) multistep.StepAction
...
@@ -38,6 +38,6 @@ func (s *StepCreateTags) Run(state map[string]interface{}) multistep.StepAction
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepCreateTags
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepCreateTags
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
// No cleanup...
// No cleanup...
}
}
builder/amazon/common/step_key_pair.go
View file @
80ed7edd
...
@@ -19,16 +19,16 @@ type StepKeyPair struct {
...
@@ -19,16 +19,16 @@ type StepKeyPair struct {
keyName
string
keyName
string
}
}
func
(
s
*
StepKeyPair
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepKeyPair
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Creating temporary keypair for this instance..."
)
ui
.
Say
(
"Creating temporary keypair for this instance..."
)
keyName
:=
fmt
.
Sprintf
(
"packer %s"
,
hex
.
EncodeToString
(
identifier
.
NewUUID
()
.
Raw
()))
keyName
:=
fmt
.
Sprintf
(
"packer %s"
,
hex
.
EncodeToString
(
identifier
.
NewUUID
()
.
Raw
()))
log
.
Printf
(
"temporary keypair name: %s"
,
keyName
)
log
.
Printf
(
"temporary keypair name: %s"
,
keyName
)
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
if
err
!=
nil
{
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating temporary keypair: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating temporary keypair: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -36,8 +36,8 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -36,8 +36,8 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
s
.
keyName
=
keyName
s
.
keyName
=
keyName
// Set some state data for use in future steps
// Set some state data for use in future steps
state
[
"keyPair"
]
=
keyName
state
.
Put
(
"keyPair"
,
keyName
)
state
[
"privateKey"
]
=
keyResp
.
KeyMaterial
state
.
Put
(
"privateKey"
,
keyResp
.
KeyMaterial
)
// If we're in debug mode, output the private key to the working
// If we're in debug mode, output the private key to the working
// directory.
// directory.
...
@@ -45,21 +45,21 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -45,21 +45,21 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Message
(
fmt
.
Sprintf
(
"Saving key for debug purposes: %s"
,
s
.
DebugKeyPath
))
ui
.
Message
(
fmt
.
Sprintf
(
"Saving key for debug purposes: %s"
,
s
.
DebugKeyPath
))
f
,
err
:=
os
.
Create
(
s
.
DebugKeyPath
)
f
,
err
:=
os
.
Create
(
s
.
DebugKeyPath
)
if
err
!=
nil
{
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error saving debug key: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error saving debug key: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
defer
f
.
Close
()
defer
f
.
Close
()
// Write the key out
// Write the key out
if
_
,
err
:=
f
.
Write
([]
byte
(
keyResp
.
KeyMaterial
));
err
!=
nil
{
if
_
,
err
:=
f
.
Write
([]
byte
(
keyResp
.
KeyMaterial
));
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error saving debug key: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error saving debug key: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
// Chmod it so that it is SSH ready
// Chmod it so that it is SSH ready
if
runtime
.
GOOS
!=
"windows"
{
if
runtime
.
GOOS
!=
"windows"
{
if
err
:=
f
.
Chmod
(
0600
);
err
!=
nil
{
if
err
:=
f
.
Chmod
(
0600
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error setting permissions of debug key: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error setting permissions of debug key: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
}
}
...
@@ -68,14 +68,14 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -68,14 +68,14 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepKeyPair
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepKeyPair
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
// If no key name is set, then we never created it, so just return
// If no key name is set, then we never created it, so just return
if
s
.
keyName
==
""
{
if
s
.
keyName
==
""
{
return
return
}
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting temporary keypair..."
)
ui
.
Say
(
"Deleting temporary keypair..."
)
_
,
err
:=
ec2conn
.
DeleteKeyPair
(
s
.
keyName
)
_
,
err
:=
ec2conn
.
DeleteKeyPair
(
s
.
keyName
)
...
...
builder/amazon/common/step_modify_ami_attributes.go
View file @
80ed7edd
...
@@ -14,10 +14,10 @@ type StepModifyAMIAttributes struct {
...
@@ -14,10 +14,10 @@ type StepModifyAMIAttributes struct {
Description
string
Description
string
}
}
func
(
s
*
StepModifyAMIAttributes
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepModifyAMIAttributes
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
amis
:=
state
[
"amis"
]
.
(
map
[
string
]
string
)
amis
:=
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
// Determine if there is any work to do.
// Determine if there is any work to do.
...
@@ -65,7 +65,7 @@ func (s *StepModifyAMIAttributes) Run(state map[string]interface{}) multistep.St
...
@@ -65,7 +65,7 @@ func (s *StepModifyAMIAttributes) Run(state map[string]interface{}) multistep.St
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
opts
)
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error modify AMI attributes: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error modify AMI attributes: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -74,6 +74,6 @@ func (s *StepModifyAMIAttributes) Run(state map[string]interface{}) multistep.St
...
@@ -74,6 +74,6 @@ func (s *StepModifyAMIAttributes) Run(state map[string]interface{}) multistep.St
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepModifyAMIAttributes
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepModifyAMIAttributes
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
// No cleanup...
// No cleanup...
}
}
builder/amazon/common/step_run_source_instance.go
View file @
80ed7edd
...
@@ -23,17 +23,17 @@ type StepRunSourceInstance struct {
...
@@ -23,17 +23,17 @@ type StepRunSourceInstance struct {
instance
*
ec2
.
Instance
instance
*
ec2
.
Instance
}
}
func
(
s
*
StepRunSourceInstance
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepRunSourceInstance
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
keyName
:=
state
[
"keyPair"
]
.
(
string
)
keyName
:=
state
.
Get
(
"keyPair"
)
.
(
string
)
securityGroupId
:=
state
[
"securityGroupId"
]
.
(
string
)
securityGroupId
:=
state
.
Get
(
"securityGroupId"
)
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
userData
:=
s
.
UserData
userData
:=
s
.
UserData
if
s
.
UserDataFile
!=
""
{
if
s
.
UserDataFile
!=
""
{
contents
,
err
:=
ioutil
.
ReadFile
(
s
.
UserDataFile
)
contents
,
err
:=
ioutil
.
ReadFile
(
s
.
UserDataFile
)
if
err
!=
nil
{
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Problem reading user data file: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Problem reading user data file: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -56,27 +56,27 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
...
@@ -56,27 +56,27 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
ui
.
Say
(
"Launching a source AWS instance..."
)
ui
.
Say
(
"Launching a source AWS instance..."
)
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
s
.
SourceAMI
},
ec2
.
NewFilter
())
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
s
.
SourceAMI
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"There was a problem with the source AMI: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"There was a problem with the source AMI: %s"
,
err
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
if
len
(
imageResp
.
Images
)
!=
1
{
if
len
(
imageResp
.
Images
)
!=
1
{
state
[
"error"
]
=
fmt
.
Errorf
(
"The source AMI '%s' could not be found."
,
s
.
SourceAMI
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"The source AMI '%s' could not be found."
,
s
.
SourceAMI
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
if
s
.
ExpectedRootDevice
!=
""
&&
imageResp
.
Images
[
0
]
.
RootDeviceType
!=
s
.
ExpectedRootDevice
{
if
s
.
ExpectedRootDevice
!=
""
&&
imageResp
.
Images
[
0
]
.
RootDeviceType
!=
s
.
ExpectedRootDevice
{
state
[
"error"
]
=
fmt
.
Errorf
(
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"The provided source AMI has an invalid root device type.
\n
"
+
"The provided source AMI has an invalid root device type.
\n
"
+
"Expected '%s', got '%s'."
,
"Expected '%s', got '%s'."
,
s
.
ExpectedRootDevice
,
imageResp
.
Images
[
0
]
.
RootDeviceType
)
s
.
ExpectedRootDevice
,
imageResp
.
Images
[
0
]
.
RootDeviceType
)
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
runResp
,
err
:=
ec2conn
.
RunInstances
(
runOpts
)
runResp
,
err
:=
ec2conn
.
RunInstances
(
runOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error launching source instance: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error launching source instance: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -95,7 +95,7 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
...
@@ -95,7 +95,7 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
latestInstance
,
err
:=
WaitForState
(
&
stateChange
)
latestInstance
,
err
:=
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance (%s) to become ready: %s"
,
s
.
instance
.
InstanceId
,
err
)
err
:=
fmt
.
Errorf
(
"Error waiting for instance (%s) to become ready: %s"
,
s
.
instance
.
InstanceId
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -112,18 +112,18 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
...
@@ -112,18 +112,18 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
}
}
}
}
state
[
"instance"
]
=
s
.
instance
state
.
Put
(
"instance"
,
s
.
instance
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepRunSourceInstance
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepRunSourceInstance
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
instance
==
nil
{
if
s
.
instance
==
nil
{
return
return
}
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Terminating the source AWS instance..."
)
ui
.
Say
(
"Terminating the source AWS instance..."
)
if
_
,
err
:=
ec2conn
.
TerminateInstances
([]
string
{
s
.
instance
.
InstanceId
});
err
!=
nil
{
if
_
,
err
:=
ec2conn
.
TerminateInstances
([]
string
{
s
.
instance
.
InstanceId
});
err
!=
nil
{
...
...
builder/amazon/common/step_security_group.go
View file @
80ed7edd
...
@@ -19,13 +19,13 @@ type StepSecurityGroup struct {
...
@@ -19,13 +19,13 @@ type StepSecurityGroup struct {
createdGroupId
string
createdGroupId
string
}
}
func
(
s
*
StepSecurityGroup
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepSecurityGroup
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
s
.
SecurityGroupId
!=
""
{
if
s
.
SecurityGroupId
!=
""
{
log
.
Printf
(
"Using specified security group: %s"
,
s
.
SecurityGroupId
)
log
.
Printf
(
"Using specified security group: %s"
,
s
.
SecurityGroupId
)
state
[
"securityGroupId"
]
=
s
.
SecurityGroupId
state
.
Put
(
"securityGroupId"
,
s
.
SecurityGroupId
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
...
@@ -64,24 +64,24 @@ func (s *StepSecurityGroup) Run(state map[string]interface{}) multistep.StepActi
...
@@ -64,24 +64,24 @@ func (s *StepSecurityGroup) Run(state map[string]interface{}) multistep.StepActi
ui
.
Say
(
"Authorizing SSH access on the temporary security group..."
)
ui
.
Say
(
"Authorizing SSH access on the temporary security group..."
)
if
_
,
err
:=
ec2conn
.
AuthorizeSecurityGroup
(
groupResp
.
SecurityGroup
,
perms
);
err
!=
nil
{
if
_
,
err
:=
ec2conn
.
AuthorizeSecurityGroup
(
groupResp
.
SecurityGroup
,
perms
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating temporary security group: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating temporary security group: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
// Set some state data for use in future steps
// Set some state data for use in future steps
state
[
"securityGroupId"
]
=
s
.
createdGroupId
state
.
Put
(
"securityGroupId"
,
s
.
createdGroupId
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
StepSecurityGroup
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepSecurityGroup
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
createdGroupId
==
""
{
if
s
.
createdGroupId
==
""
{
return
return
}
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting temporary security group..."
)
ui
.
Say
(
"Deleting temporary security group..."
)
...
...
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