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
0df18df4
Commit
0df18df4
authored
Jun 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: extract multistep, use that
parent
2dd5a982
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
62 deletions
+31
-62
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+4
-2
builder/amazonebs/step.go
builder/amazonebs/step.go
+0
-39
builder/amazonebs/step_connect_ssh.go
builder/amazonebs/step_connect_ssh.go
+5
-4
builder/amazonebs/step_create_ami.go
builder/amazonebs/step_create_ami.go
+5
-4
builder/amazonebs/step_keypair.go
builder/amazonebs/step_keypair.go
+4
-3
builder/amazonebs/step_provision.go
builder/amazonebs/step_provision.go
+3
-2
builder/amazonebs/step_run_source_instance.go
builder/amazonebs/step_run_source_instance.go
+5
-4
builder/amazonebs/step_stop_instance.go
builder/amazonebs/step_stop_instance.go
+5
-4
No files found.
builder/amazonebs/builder.go
View file @
0df18df4
...
...
@@ -9,6 +9,7 @@ import (
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
...
...
@@ -87,7 +88,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
state
[
"ui"
]
=
ui
// Build the steps
steps
:=
[]
Step
{
steps
:=
[]
multistep
.
Step
{
&
stepKeyPair
{},
&
stepRunSourceInstance
{},
&
stepConnectSSH
{},
...
...
@@ -97,7 +98,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
}
// Run!
RunSteps
(
state
,
steps
)
runner
:=
&
multistep
.
BasicRunner
{
Steps
:
steps
}
runner
.
Run
(
state
)
// Build the artifact and return it
return
&
artifact
{
state
[
"amis"
]
.
(
map
[
string
]
string
)}
...
...
builder/amazonebs/step.go
deleted
100644 → 0
View file @
2dd5a982
package
amazonebs
// A StepAction determines the next step to take regarding multi-step actions.
type
StepAction
uint
const
(
StepContinue
StepAction
=
iota
StepHalt
)
// Step is a single step that is part of a potentially large sequence
// of other steps, responsible for performing some specific action.
type
Step
interface
{
// Run is called to perform the action. The parameter is a "state bag"
// of untyped things. Please be very careful about type-checking the
// items in this bag.
//
// The return value determines whether multi-step sequences continue
// or should halt.
Run
(
map
[
string
]
interface
{})
StepAction
// Cleanup is called in reverse order of the steps that have run
// and allow steps to clean up after themselves.
//
// The parameter is the same "state bag" as Run.
Cleanup
(
map
[
string
]
interface
{})
}
// RunSteps runs a sequence of steps.
func
RunSteps
(
state
map
[
string
]
interface
{},
steps
[]
Step
)
{
for
_
,
step
:=
range
steps
{
action
:=
step
.
Run
(
state
)
defer
step
.
Cleanup
(
state
)
if
action
==
StepHalt
{
break
}
}
}
builder/amazonebs/step_connect_ssh.go
View file @
0df18df4
...
...
@@ -4,6 +4,7 @@ import (
gossh
"code.google.com/p/go.crypto/ssh"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/packer"
"log"
...
...
@@ -15,7 +16,7 @@ type stepConnectSSH struct {
conn
net
.
Conn
}
func
(
s
*
stepConnectSSH
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
s
*
stepConnectSSH
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
config
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
privateKey
:=
state
[
"privateKey"
]
.
(
string
)
...
...
@@ -27,7 +28,7 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) StepAction {
err
:=
keyring
.
AddPEMKey
(
privateKey
)
if
err
!=
nil
{
ui
.
Say
(
fmt
.
Sprintf
(
"Error setting up SSH config: %s"
,
err
))
return
Step
Halt
return
multistep
.
Action
Halt
}
// Build the actual SSH client configuration
...
...
@@ -59,13 +60,13 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) StepAction {
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error connecting to SSH: %s"
,
err
))
return
Step
Halt
return
multistep
.
Action
Halt
}
// Set the communicator on the state bag so it can be used later
state
[
"communicator"
]
=
comm
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
s
*
stepConnectSSH
)
Cleanup
(
map
[
string
]
interface
{})
{
...
...
builder/amazonebs/step_create_ami.go
View file @
0df18df4
...
...
@@ -3,12 +3,13 @@ package amazonebs
import
(
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type
stepCreateAMI
struct
{}
func
(
s
*
stepCreateAMI
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
s
*
stepCreateAMI
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
...
...
@@ -24,7 +25,7 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) StepAction {
createResp
,
err
:=
ec2conn
.
CreateImage
(
createOpts
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
// Set the AMI ID in the state
...
...
@@ -39,7 +40,7 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) StepAction {
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
createResp
.
ImageId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
if
imageResp
.
Images
[
0
]
.
State
==
"available"
{
...
...
@@ -47,7 +48,7 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) StepAction {
}
}
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
s
*
stepCreateAMI
)
Cleanup
(
map
[
string
]
interface
{})
{
...
...
builder/amazonebs/step_keypair.go
View file @
0df18df4
...
...
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
...
...
@@ -13,7 +14,7 @@ type stepKeyPair struct {
keyName
string
}
func
(
s
*
stepKeyPair
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
s
*
stepKeyPair
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
...
...
@@ -23,7 +24,7 @@ func (s *stepKeyPair) Run(state map[string]interface{}) StepAction {
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
// Set the keyname so we know to delete it later
...
...
@@ -33,7 +34,7 @@ func (s *stepKeyPair) Run(state map[string]interface{}) StepAction {
state
[
"keyPair"
]
=
keyName
state
[
"privateKey"
]
=
keyResp
.
KeyMaterial
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
s
*
stepKeyPair
)
Cleanup
(
state
map
[
string
]
interface
{})
{
...
...
builder/amazonebs/step_provision.go
View file @
0df18df4
package
amazonebs
import
(
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type
stepProvision
struct
{}
func
(
*
stepProvision
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
*
stepProvision
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
hook
:=
state
[
"hook"
]
.
(
packer
.
Hook
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
...
...
@@ -15,7 +16,7 @@ func (*stepProvision) Run(state map[string]interface{}) StepAction {
log
.
Println
(
"Running the provision hook"
)
hook
.
Run
(
packer
.
HookProvision
,
ui
,
comm
,
nil
)
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
*
stepProvision
)
Cleanup
(
map
[
string
]
interface
{})
{}
builder/amazonebs/step_run_source_instance.go
View file @
0df18df4
...
...
@@ -2,6 +2,7 @@ package amazonebs
import
(
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
...
...
@@ -10,7 +11,7 @@ type stepRunSourceInstance struct {
instance
*
ec2
.
Instance
}
func
(
s
*
stepRunSourceInstance
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
s
*
stepRunSourceInstance
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
keyName
:=
state
[
"keyPair"
]
.
(
string
)
...
...
@@ -28,7 +29,7 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) StepAction {
runResp
,
err
:=
ec2conn
.
RunInstances
(
runOpts
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
s
.
instance
=
&
runResp
.
Instances
[
0
]
...
...
@@ -38,12 +39,12 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) StepAction {
s
.
instance
,
err
=
waitForState
(
ec2conn
,
s
.
instance
,
"running"
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
state
[
"instance"
]
=
s
.
instance
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
s
*
stepRunSourceInstance
)
Cleanup
(
state
map
[
string
]
interface
{})
{
...
...
builder/amazonebs/step_stop_instance.go
View file @
0df18df4
...
...
@@ -2,12 +2,13 @@ package amazonebs
import
(
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type
stepStopInstance
struct
{}
func
(
s
*
stepStopInstance
)
Run
(
state
map
[
string
]
interface
{})
StepAction
{
func
(
s
*
stepStopInstance
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
...
...
@@ -17,7 +18,7 @@ func (s *stepStopInstance) Run(state map[string]interface{}) StepAction {
_
,
err
:=
ec2conn
.
StopInstances
(
instance
.
InstanceId
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
// Wait for the instance to actual stop
...
...
@@ -27,10 +28,10 @@ func (s *stepStopInstance) Run(state map[string]interface{}) StepAction {
instance
,
err
=
waitForState
(
ec2conn
,
instance
,
"stopped"
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
Step
Halt
return
multistep
.
Action
Halt
}
return
Step
Continue
return
multistep
.
Action
Continue
}
func
(
s
*
stepStopInstance
)
Cleanup
(
map
[
string
]
interface
{})
{
...
...
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