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
d46741e4
Commit
d46741e4
authored
Jul 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/*: wait for AMI to be ready in common, use it instance
parent
b5fdab40
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
18 deletions
+41
-18
builder/amazon/common/ami.go
builder/amazon/common/ami.go
+25
-0
builder/amazon/ebs/step_create_ami.go
builder/amazon/ebs/step_create_ami.go
+6
-18
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+10
-0
No files found.
builder/amazon/common/ami.go
0 → 100644
View file @
d46741e4
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
{
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/ebs/step_create_ami.go
View file @
d46741e4
...
...
@@ -5,8 +5,8 @@ import (
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
"log"
"strconv"
"text/template"
"time"
...
...
@@ -57,23 +57,11 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
// Wait for the image to become ready
ui
.
Say
(
"Waiting for AMI to become ready..."
)
for
{
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
createResp
.
ImageId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error querying images: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
imageResp
.
Images
[
0
]
.
State
==
"available"
{
break
}
log
.
Printf
(
"Image in state %s, sleeping 2s before checking again"
,
imageResp
.
Images
[
0
]
.
State
)
time
.
Sleep
(
2
*
time
.
Second
)
if
err
:=
awscommon
.
WaitForAMI
(
ec2conn
,
createResp
.
ImageId
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for AMI: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
...
...
builder/amazon/instance/step_register_ami.go
View file @
d46741e4
...
...
@@ -5,6 +5,7 @@ import (
"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"
...
...
@@ -52,6 +53,15 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
amis
[
config
.
Region
]
=
registerResp
.
ImageId
state
[
"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
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
...
...
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