2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2017-02-13 05:35:14 -05:00
|
|
|
"fmt"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-07 06:20:33 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2017-02-13 05:35:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepImage struct{}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *stepImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2017-02-13 05:35:14 -05:00
|
|
|
var (
|
|
|
|
driver = state.Get("driver").(Driver)
|
|
|
|
ui = state.Get("ui").(packer.Ui)
|
|
|
|
instanceID = state.Get("instance_id").(string)
|
|
|
|
)
|
|
|
|
|
|
|
|
ui.Say("Creating image from instance...")
|
|
|
|
|
|
|
|
image, err := driver.CreateImage(instanceID)
|
|
|
|
if err != nil {
|
2017-08-02 06:53:14 -04:00
|
|
|
err = fmt.Errorf("Error creating image from instance: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
2017-02-13 05:35:14 -05:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
err = driver.WaitForImageCreation(image.ID)
|
|
|
|
if err != nil {
|
2017-08-02 06:53:14 -04:00
|
|
|
err = fmt.Errorf("Error waiting for image creation to finish: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
2017-02-13 05:35:14 -05:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(apryde): This is stale as .LifecycleState has changed to
|
|
|
|
// AVAILABLE at this point. Does it matter?
|
|
|
|
state.Put("image", image)
|
|
|
|
|
|
|
|
ui.Say("Image created.")
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepImage) Cleanup(state multistep.StateBag) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|