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
8bffbb6f
Commit
8bffbb6f
authored
Jul 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: step to snapshot the root image
parent
e418727a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
0 deletions
+88
-0
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+1
-0
builder/amazon/chroot/step_snapshot.go
builder/amazon/chroot/step_snapshot.go
+87
-0
No files found.
builder/amazon/chroot/builder.go
View file @
8bffbb6f
...
...
@@ -143,6 +143,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepCopyFiles
{},
&
StepChrootProvision
{},
&
StepEarlyCleanup
{},
&
StepSnapshot
{},
}
// Run!
...
...
builder/amazon/chroot/step_snapshot.go
0 → 100644
View file @
8bffbb6f
package
chroot
import
(
"errors"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
)
// StepSnapshot creates a snapshot of the created volume.
//
// Produces:
// snapshot_id string - ID of the created snapshot
type
StepSnapshot
struct
{
snapshotId
string
}
func
(
s
*
StepSnapshot
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
volumeId
:=
state
[
"volume_id"
]
.
(
string
)
ui
.
Say
(
"Creating snapshot..."
)
createSnapResp
,
err
:=
ec2conn
.
CreateSnapshot
(
volumeId
,
""
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating snapshot: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Set the snapshot ID so we can delete it later
s
.
snapshotId
=
createSnapResp
.
Id
ui
.
Message
(
fmt
.
Sprintf
(
"Snapshot ID: %s"
,
s
.
snapshotId
))
// Wait for the snapshot to be ready
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"pending"
},
StepState
:
state
,
Target
:
"completed"
,
Refresh
:
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
ec2conn
.
Snapshots
([]
string
{
s
.
snapshotId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
return
nil
,
""
,
err
}
if
len
(
resp
.
Snapshots
)
==
0
{
return
nil
,
""
,
errors
.
New
(
"No snapshots found."
)
}
return
nil
,
resp
.
Snapshots
[
0
]
.
Status
,
nil
},
}
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"snapshot_id"
]
=
s
.
snapshotId
return
multistep
.
ActionContinue
}
func
(
s
*
StepSnapshot
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
s
.
snapshotId
==
""
{
return
}
_
,
cancelled
:=
state
[
multistep
.
StateCancelled
]
_
,
halted
:=
state
[
multistep
.
StateHalted
]
if
cancelled
||
halted
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Removing snapshot since we cancelled or halted..."
)
_
,
err
:=
ec2conn
.
DeleteSnapshots
([]
string
{
s
.
snapshotId
})
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error: %s"
,
err
))
}
}
}
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