github.com/angdraug/packer@v1.3.2/builder/oracle/oci/step_image.go (about)

     1  package oci
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  	"github.com/hashicorp/packer/packer"
     9  )
    10  
    11  type stepImage struct{}
    12  
    13  func (s *stepImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
    14  	var (
    15  		driver     = state.Get("driver").(Driver)
    16  		ui         = state.Get("ui").(packer.Ui)
    17  		instanceID = state.Get("instance_id").(string)
    18  	)
    19  
    20  	ui.Say("Creating image from instance...")
    21  
    22  	image, err := driver.CreateImage(ctx, instanceID)
    23  	if err != nil {
    24  		err = fmt.Errorf("Error creating image from instance: %s", err)
    25  		ui.Error(err.Error())
    26  		state.Put("error", err)
    27  		return multistep.ActionHalt
    28  	}
    29  
    30  	err = driver.WaitForImageCreation(ctx, *image.Id)
    31  	if err != nil {
    32  		err = fmt.Errorf("Error waiting for image creation to finish: %s", err)
    33  		ui.Error(err.Error())
    34  		state.Put("error", err)
    35  		return multistep.ActionHalt
    36  	}
    37  
    38  	// TODO(apryde): This is stale as .LifecycleState has changed to
    39  	// AVAILABLE at this point. Does it matter?
    40  	state.Put("image", image)
    41  
    42  	ui.Say("Image created.")
    43  
    44  	return multistep.ActionContinue
    45  }
    46  
    47  func (s *stepImage) Cleanup(state multistep.StateBag) {
    48  	// Nothing to do
    49  }