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
27608a7b
Commit
27608a7b
authored
Sep 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/*: use WaitForState for AMIs
parent
a6139af9
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
35 deletions
+69
-35
CHANGELOG.md
CHANGELOG.md
+5
-0
builder/amazon/chroot/step_register_ami.go
builder/amazon/chroot/step_register_ami.go
+9
-1
builder/amazon/common/ami.go
builder/amazon/common/ami.go
+0
-30
builder/amazon/common/instance.go
builder/amazon/common/instance.go
+26
-0
builder/amazon/common/step_ami_region_copy.go
builder/amazon/common/step_ami_region_copy.go
+11
-2
builder/amazon/ebs/step_create_ami.go
builder/amazon/ebs/step_create_ami.go
+9
-1
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+9
-1
No files found.
CHANGELOG.md
View file @
27608a7b
## 0.3.8 (unreleased)
IMPROVEMENTS:
*
builder/amazon/
*
: Interrupts work while waiting for AMI to be ready.
BUG FIXES:
*
builder/amazon/
*
: While waiting for AMI, will detect "failed" state.
*
provisioner/puppet-masterless: Fix failure case when both facter vars
are used and prevent_sudo. [GH-415]
...
...
builder/amazon/chroot/step_register_ami.go
View file @
27608a7b
...
...
@@ -52,8 +52,16 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
state
.
Put
(
"amis"
,
amis
)
// Wait for the image to become ready
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"pending"
},
Target
:
"available"
,
Refresh
:
awscommon
.
AMIStateRefreshFunc
(
ec2conn
,
registerResp
.
ImageId
),
StepState
:
state
,
}
ui
.
Say
(
"Waiting for AMI to become ready..."
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
registerResp
.
ImageId
);
err
!=
nil
{
if
_
,
err
:=
awscommon
.
WaitForState
(
&
stateChange
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
builder/amazon/common/ami.go
deleted
100644 → 0
View file @
a6139af9
package
common
import
(
"github.com/mitchellh/goamz/ec2"
"log"
"time"
)
// WaitForAMI waits for the given AMI ID to become ready.
func
WaitForAMI
(
c
*
ec2
.
EC2
,
imageId
string
)
error
{
for
{
imageResp
,
err
:=
c
.
Images
([]
string
{
imageId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
ec2err
,
ok
:=
err
.
(
*
ec2
.
Error
);
ok
&&
ec2err
.
Code
==
"InvalidAMIID.NotFound"
{
log
.
Println
(
"AMI not found, probably state issues on AWS side. Trying again."
)
continue
}
return
err
}
if
imageResp
.
Images
[
0
]
.
State
==
"available"
{
return
nil
}
log
.
Printf
(
"Image in state %s, sleeping 2s before checking again"
,
imageResp
.
Images
[
0
]
.
State
)
time
.
Sleep
(
2
*
time
.
Second
)
}
}
builder/amazon/common/instance.go
View file @
27608a7b
...
...
@@ -30,6 +30,32 @@ type StateChangeConf struct {
Target
string
}
// AMIStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an AMI for state changes.
func
AMIStateRefreshFunc
(
conn
*
ec2
.
EC2
,
imageId
string
)
StateRefreshFunc
{
return
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
conn
.
Images
([]
string
{
imageId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
ec2err
,
ok
:=
err
.
(
*
ec2
.
Error
);
ok
&&
ec2err
.
Code
==
"InvalidAMIID.NotFound"
{
// Set this to nil as if we didn't find anything.
resp
=
nil
}
else
{
log
.
Printf
(
"Error on AMIStateRefresh: %s"
,
err
)
return
nil
,
""
,
err
}
}
if
resp
==
nil
||
len
(
resp
.
Images
)
==
0
{
// Sometimes AWS has consistency issues and doesn't see the
// AMI. Return an empty state.
return
nil
,
""
,
nil
}
i
:=
resp
.
Images
[
0
]
return
i
,
i
.
State
,
nil
}
}
// InstanceStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an EC2 instance.
func
InstanceStateRefreshFunc
(
conn
*
ec2
.
EC2
,
i
*
ec2
.
Instance
)
StateRefreshFunc
{
...
...
builder/amazon/common/step_ami_region_copy.go
View file @
27608a7b
...
...
@@ -40,8 +40,17 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
}
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
{
stateChange
:=
StateChangeConf
{
Conn
:
regionconn
,
Pending
:
[]
string
{
"pending"
},
Target
:
"available"
,
Refresh
:
AMIStateRefreshFunc
(
regionconn
,
resp
.
ImageId
),
StepState
:
state
,
}
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for AMI (%s) in region (%s) to become ready..."
,
resp
.
ImageId
,
region
))
if
_
,
err
:=
WaitForState
(
&
stateChange
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI (%s) in region (%s): %s"
,
resp
.
ImageId
,
region
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
builder/amazon/ebs/step_create_ami.go
View file @
27608a7b
...
...
@@ -39,8 +39,16 @@ func (s *stepCreateAMI) Run(state multistep.StateBag) multistep.StepAction {
state
.
Put
(
"amis"
,
amis
)
// Wait for the image to become ready
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"pending"
},
Target
:
"available"
,
Refresh
:
awscommon
.
AMIStateRefreshFunc
(
ec2conn
,
createResp
.
ImageId
),
StepState
:
state
,
}
ui
.
Say
(
"Waiting for AMI to become ready..."
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
createResp
.
ImageId
);
err
!=
nil
{
if
_
,
err
:=
awscommon
.
WaitForState
(
&
stateChange
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
builder/amazon/instance/step_register_ami.go
View file @
27608a7b
...
...
@@ -37,8 +37,16 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
state
.
Put
(
"amis"
,
amis
)
// Wait for the image to become ready
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"pending"
},
Target
:
"available"
,
Refresh
:
awscommon
.
AMIStateRefreshFunc
(
ec2conn
,
registerResp
.
ImageId
),
StepState
:
state
,
}
ui
.
Say
(
"Waiting for AMI to become ready..."
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
registerResp
.
ImageId
);
err
!=
nil
{
if
_
,
err
:=
awscommon
.
WaitForState
(
&
stateChange
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
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