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{ &StepCreateOMI{
RootVolumeSize: b.config.RootVolumeSize, 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! // Run!
@ -285,7 +295,19 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, rawErr.(error) return nil, rawErr.(error)
} }
return nil, nil // 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() { func (b *Builder) Cancel() {

View File

@ -24,10 +24,18 @@ const testBuilderAccBasic = `
"type": "test", "type": "test",
"region": "eu-west-2", "region": "eu-west-2",
"source_omi": "ami-99466096", "source_omi": "ami-99466096",
"omi_name": "packer-test {{timestamp}}", "omi_name": "packer-test-{{timestamp}}",
"omi_virtualization_type": "hvm", "omi_virtualization_type": "hvm",
"device_path": "/dev/xvdf", "device_path": "/dev/xvdf",
"mount_partition": "0" "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" "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{} type StepCheckRootDevice struct{}
func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
image := state.Get("source_image").(oapi.Image) image := state.Get("source_image").(oapi.Image)
ui := state.Get("ui").(packer.Ui) 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" { 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) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt 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) oapiconn := state.Get("oapi").(*oapi.Client)
config := state.Get("clientConfig").(*oapi.Config) config := state.Get("clientConfig").(*oapi.Config)
ui := state.Get("ui").(packer.Ui) 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() { if !s.Tags.IsSet() && !s.SnapshotTags.IsSet() {
return multistep.ActionContinue return multistep.ActionContinue
} }
// Adds tags to OMIs and snapshots // 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)) ui.Say(fmt.Sprintf("Adding tags to OMI (%s)...", ami))
newConfig := &oapi.Config{ newConfig := &oapi.Config{