feature: add remaining steps and and create artifact in chroot builder

This commit is contained in:
Marin Salinas 2019-03-05 11:58:59 -06:00 committed by Megan Marsh
parent 70d2ff3d8a
commit 9d6c4a8e5b
4 changed files with 39 additions and 9 deletions

View File

@ -274,6 +274,16 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepCreateOMI{
RootVolumeSize: b.config.RootVolumeSize,
},
&osccommon.StepUpdateOMIAttributes{
AccountIds: b.config.OMIAccountIDs,
SnapshotAccountIds: b.config.SnapshotAccountIDs,
Ctx: b.config.ctx,
},
&osccommon.StepCreateTags{
Tags: b.config.OMITags,
SnapshotTags: b.config.SnapshotTags,
Ctx: b.config.ctx,
},
)
// Run!
@ -285,9 +295,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, rawErr.(error)
}
// If there are no OMIs, then just return
if _, ok := state.GetOk("omis"); !ok {
return nil, nil
}
// Build the artifact and return it
artifact := &osccommon.Artifact{
Omis: state.Get("omis").(map[string]string),
BuilderIdValue: BuilderId,
Config: clientConfig,
}
return artifact, nil
}
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")

View File

@ -24,10 +24,18 @@ const testBuilderAccBasic = `
"type": "test",
"region": "eu-west-2",
"source_omi": "ami-99466096",
"omi_name": "packer-test {{timestamp}}",
"omi_name": "packer-test-{{timestamp}}",
"omi_virtualization_type": "hvm",
"device_path": "/dev/xvdf",
"mount_partition": "0"
}]
}],
"provisioners": [
{
"type": "shell",
"inline": [
"echo Packer-test | tee /tmp/test.txt"
]
}
]
}
`

View File

@ -9,18 +9,18 @@ import (
"github.com/outscale/osc-go/oapi"
)
// StepCheckRootDevice makes sure the root device on the AMI is EBS-backed.
// StepCheckRootDevice makes sure the root device on the OMI is BSU-backed.
type StepCheckRootDevice struct{}
func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
image := state.Get("source_image").(oapi.Image)
ui := state.Get("ui").(packer.Ui)
ui.Say("Checking the root device on source AMI...")
ui.Say("Checking the root device on source OMI...")
// It must be EBS-backed otherwise the build won't work
// It must be BSU-backed otherwise the build won't work
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 OMI must be BSU-backed.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt

View File

@ -24,14 +24,14 @@ func (s *StepCreateTags) Run(_ context.Context, state multistep.StateBag) multis
oapiconn := state.Get("oapi").(*oapi.Client)
config := state.Get("clientConfig").(*oapi.Config)
ui := state.Get("ui").(packer.Ui)
amis := state.Get("amis").(map[string]string)
omis := state.Get("omis").(map[string]string)
if !s.Tags.IsSet() && !s.SnapshotTags.IsSet() {
return multistep.ActionContinue
}
// Adds tags to OMIs and snapshots
for region, ami := range amis {
for region, ami := range omis {
ui.Say(fmt.Sprintf("Adding tags to OMI (%s)...", ami))
newConfig := &oapi.Config{