Merge pull request #7440 from hashicorp/context_provisioner

Context parameter for cancellation in Builder, Provisioner, Hook & PostProcessor
This commit is contained in:
Megan Marsh 2019-04-10 10:50:59 -07:00 committed by GitHub
commit 7742ae1981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
409 changed files with 1194 additions and 1549 deletions

View File

@ -3,8 +3,7 @@
package ecs package ecs
import ( import (
"log" "context"
"fmt" "fmt"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
@ -76,7 +75,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
client, err := b.config.Client() client, err := b.config.Client()
if err != nil { if err != nil {
@ -205,7 +204,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -227,13 +226,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}
func (b *Builder) chooseNetworkType() InstanceNetWork { func (b *Builder) chooseNetworkType() InstanceNetWork {
if b.isVpcNetRequired() { if b.isVpcNetRequired() {
return VpcNet return VpcNet

View File

@ -15,7 +15,7 @@ import (
type stepAttachKeyPair struct { type stepAttachKeyPair struct {
} }
func (s *stepAttachKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepAttachKeyPair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)

View File

@ -14,7 +14,7 @@ type stepCheckAlicloudSourceImage struct {
SourceECSImageId string SourceECSImageId string
} }
func (s *stepCheckAlicloudSourceImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCheckAlicloudSourceImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -19,7 +19,7 @@ type stepConfigAlicloudEIP struct {
SSHPrivateIp bool SSHPrivateIp bool
} }
func (s *stepConfigAlicloudEIP) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudEIP) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance").(*ecs.InstanceAttributesType) instance := state.Get("instance").(*ecs.InstanceAttributesType)

View File

@ -22,7 +22,7 @@ type stepConfigAlicloudKeyPair struct {
keyName string keyName string
} }
func (s *stepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudKeyPair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.Comm.SSHPrivateKeyFile != "" { if s.Comm.SSHPrivateKeyFile != "" {

View File

@ -15,7 +15,7 @@ type stepConfigAlicloudPublicIP struct {
SSHPrivateIp bool SSHPrivateIp bool
} }
func (s *stepConfigAlicloudPublicIP) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudPublicIP) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance").(*ecs.InstanceAttributesType) instance := state.Get("instance").(*ecs.InstanceAttributesType)

View File

@ -21,7 +21,7 @@ type stepConfigAlicloudSecurityGroup struct {
isCreate bool isCreate bool
} }
func (s *stepConfigAlicloudSecurityGroup) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudSecurityGroup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
networkType := state.Get("networktype").(InstanceNetWork) networkType := state.Get("networktype").(InstanceNetWork)

View File

@ -19,7 +19,7 @@ type stepConfigAlicloudVPC struct {
isCreate bool isCreate bool
} }
func (s *stepConfigAlicloudVPC) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudVPC) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -20,7 +20,7 @@ type stepConfigAlicloudVSwitch struct {
VSwitchName string VSwitchName string
} }
func (s *stepConfigAlicloudVSwitch) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepConfigAlicloudVSwitch) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vpcId := state.Get("vpcid").(string) vpcId := state.Get("vpcid").(string)

View File

@ -16,7 +16,7 @@ type stepCreateAlicloudImage struct {
image *ecs.ImageType image *ecs.ImageType
} }
func (s *stepCreateAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateAlicloudImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -26,7 +26,7 @@ type stepCreateAlicloudInstance struct {
instance *ecs.InstanceAttributesType instance *ecs.InstanceAttributesType
} }
func (s *stepCreateAlicloudInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateAlicloudInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -15,7 +15,7 @@ type stepCreateAlicloudSnapshot struct {
WaitSnapshotReadyTimeout int WaitSnapshotReadyTimeout int
} }
func (s *stepCreateAlicloudSnapshot) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateAlicloudSnapshot) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -3,6 +3,7 @@ package ecs
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/denverdino/aliyungo/common" "github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs" "github.com/denverdino/aliyungo/ecs"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
@ -13,7 +14,7 @@ type stepCreateTags struct {
Tags map[string]string Tags map[string]string
} }
func (s *stepCreateTags) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateTags) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -19,7 +19,7 @@ type stepDeleteAlicloudImageSnapshots struct {
AlicloudImageDestinationNames []string AlicloudImageDestinationNames []string
} }
func (s *stepDeleteAlicloudImageSnapshots) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepDeleteAlicloudImageSnapshots) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
// Check for force delete // Check for force delete

View File

@ -12,7 +12,7 @@ import (
type stepMountAlicloudDisk struct { type stepMountAlicloudDisk struct {
} }
func (s *stepMountAlicloudDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepMountAlicloudDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -15,7 +15,7 @@ type stepPreValidate struct {
ForceDelete bool ForceDelete bool
} }
func (s *stepPreValidate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.ForceDelete { if s.ForceDelete {
ui.Say("Force delete flag found, skipping prevalidating image name.") ui.Say("Force delete flag found, skipping prevalidating image name.")

View File

@ -16,7 +16,7 @@ type stepRegionCopyAlicloudImage struct {
RegionId string RegionId string
} }
func (s *stepRegionCopyAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepRegionCopyAlicloudImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
if len(s.AlicloudImageDestinationRegions) == 0 { if len(s.AlicloudImageDestinationRegions) == 0 {
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -12,7 +12,7 @@ import (
type stepRunAlicloudInstance struct { type stepRunAlicloudInstance struct {
} }
func (s *stepRunAlicloudInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepRunAlicloudInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance").(*ecs.InstanceAttributesType) instance := state.Get("instance").(*ecs.InstanceAttributesType)

View File

@ -16,7 +16,7 @@ type stepShareAlicloudImage struct {
RegionId string RegionId string
} }
func (s *stepShareAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepShareAlicloudImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
alicloudImages := state.Get("alicloudimages").(map[string]string) alicloudImages := state.Get("alicloudimages").(map[string]string)

View File

@ -14,7 +14,7 @@ type stepStopAlicloudInstance struct {
DisableStop bool DisableStop bool
} }
func (s *stepStopAlicloudInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepStopAlicloudInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*ecs.Client) client := state.Get("client").(*ecs.Client)
instance := state.Get("instance").(*ecs.InstanceAttributesType) instance := state.Get("instance").(*ecs.InstanceAttributesType)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -5,8 +5,8 @@
package chroot package chroot
import ( import (
"context"
"errors" "errors"
"log"
"runtime" "runtime"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
@ -190,7 +190,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warns, nil return warns, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
return nil, errors.New("The amazon-chroot builder only works on Linux environments.") return nil, errors.New("The amazon-chroot builder only works on Linux environments.")
} }
@ -202,9 +202,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ec2conn := ec2.New(session) ec2conn := ec2.New(session)
wrappedCommand := func(command string) (string, error) { wrappedCommand := func(command string) (string, error) {
ctx := b.config.ctx ictx := b.config.ctx
ctx.Data = &wrappedCommandTemplate{Command: command} ictx.Data = &wrappedCommandTemplate{Command: command}
return interpolate.Render(b.config.CommandWrapper, &ctx) return interpolate.Render(b.config.CommandWrapper, &ictx)
} }
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps
@ -303,7 +303,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -324,10 +324,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -8,9 +8,9 @@ import (
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
) )
func RunLocalCommands(commands []string, wrappedCommand CommandWrapper, ctx interpolate.Context, ui packer.Ui) error { func RunLocalCommands(commands []string, wrappedCommand CommandWrapper, ictx interpolate.Context, ui packer.Ui) error {
for _, rawCmd := range commands { for _, rawCmd := range commands {
intCmd, err := interpolate.Render(rawCmd, &ctx) intCmd, err := interpolate.Render(rawCmd, &ictx)
if err != nil { if err != nil {
return fmt.Errorf("Error interpolating: %s", err) return fmt.Errorf("Error interpolating: %s", err)
} }

View File

@ -12,7 +12,7 @@ import (
// StepCheckRootDevice makes sure the root device on the AMI is EBS-backed. // StepCheckRootDevice makes sure the root device on the AMI is EBS-backed.
type StepCheckRootDevice struct{} type StepCheckRootDevice struct{}
func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCheckRootDevice) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
image := state.Get("source_image").(*ec2.Image) image := state.Get("source_image").(*ec2.Image)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -12,7 +12,7 @@ import (
type StepChrootProvision struct { type StepChrootProvision struct {
} }
func (s *StepChrootProvision) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepChrootProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook) hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
@ -26,7 +26,7 @@ func (s *StepChrootProvision) Run(_ context.Context, state multistep.StateBag) m
// Provision // Provision
log.Println("Running the provision hook") log.Println("Running the provision hook")
if err := hook.Run(packer.HookProvision, ui, comm, nil); err != nil { if err := hook.Run(ctx, packer.HookProvision, ui, comm, nil); err != nil {
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }

View File

@ -20,7 +20,7 @@ type StepCopyFiles struct {
files []string files []string
} }
func (s *StepCopyFiles) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCopyFiles) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -1,10 +1,11 @@
package chroot package chroot
import ( import (
"testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func buildTestRootDevice() *ec2.BlockDeviceMapping { func buildTestRootDevice() *ec2.BlockDeviceMapping {

View File

@ -13,7 +13,7 @@ import (
// prepare for snapshotting and creating an AMI. // prepare for snapshotting and creating an AMI.
type StepEarlyCleanup struct{} type StepEarlyCleanup struct{}
func (s *StepEarlyCleanup) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepEarlyCleanup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
cleanupKeys := []string{ cleanupKeys := []string{
"copy_files_cleanup", "copy_files_cleanup",

View File

@ -12,7 +12,7 @@ import (
// StepEarlyUnflock unlocks the flock. // StepEarlyUnflock unlocks the flock.
type StepEarlyUnflock struct{} type StepEarlyUnflock struct{}
func (s *StepEarlyUnflock) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepEarlyUnflock) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
cleanup := state.Get("flock_cleanup").(Cleanup) cleanup := state.Get("flock_cleanup").(Cleanup)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -19,7 +19,7 @@ type StepFlock struct {
fh *os.File fh *os.File
} }
func (s *StepFlock) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepFlock) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
lockfile := "/var/lock/packer-chroot/lock" lockfile := "/var/lock/packer-chroot/lock"

View File

@ -15,7 +15,7 @@ import (
// StepInstanceInfo verifies that this builder is running on an EC2 instance. // StepInstanceInfo verifies that this builder is running on an EC2 instance.
type StepInstanceInfo struct{} type StepInstanceInfo struct{}
func (s *StepInstanceInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepInstanceInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
session := state.Get("awsSession").(*session.Session) session := state.Get("awsSession").(*session.Session)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -31,7 +31,7 @@ type StepMountDevice struct {
mountPath string mountPath string
} }
func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepMountDevice) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
device := state.Get("device").(string) device := state.Get("device").(string)
@ -50,10 +50,10 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
log.Printf("Source image virtualization type is: %s", virtualizationType) log.Printf("Source image virtualization type is: %s", virtualizationType)
} }
ctx := config.ctx ictx := config.ctx
ctx.Data = &mountPathData{Device: filepath.Base(device)} ictx.Data = &mountPathData{Device: filepath.Base(device)}
mountPath, err := interpolate.Render(config.MountPath, &ctx) mountPath, err := interpolate.Render(config.MountPath, &ictx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing mount directory: %s", err) err := fmt.Errorf("Error preparing mount directory: %s", err)

View File

@ -20,7 +20,7 @@ type StepMountExtra struct {
mounts []string mounts []string
} }
func (s *StepMountExtra) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -18,7 +18,7 @@ type StepPostMountCommands struct {
Commands []string Commands []string
} }
func (s *StepPostMountCommands) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepPostMountCommands) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
device := state.Get("device").(string) device := state.Get("device").(string)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
@ -29,14 +29,14 @@ func (s *StepPostMountCommands) Run(_ context.Context, state multistep.StateBag)
return multistep.ActionContinue return multistep.ActionContinue
} }
ctx := config.ctx ictx := config.ctx
ctx.Data = &postMountCommandsData{ ictx.Data = &postMountCommandsData{
Device: device, Device: device,
MountPath: mountPath, MountPath: mountPath,
} }
ui.Say("Running post-mount commands...") ui.Say("Running post-mount commands...")
if err := RunLocalCommands(s.Commands, wrappedCommand, ctx, ui); err != nil { if err := RunLocalCommands(s.Commands, wrappedCommand, ictx, ui); err != nil {
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt

View File

@ -16,7 +16,7 @@ type StepPreMountCommands struct {
Commands []string Commands []string
} }
func (s *StepPreMountCommands) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepPreMountCommands) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
device := state.Get("device").(string) device := state.Get("device").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
@ -26,11 +26,11 @@ func (s *StepPreMountCommands) Run(_ context.Context, state multistep.StateBag)
return multistep.ActionContinue return multistep.ActionContinue
} }
ctx := config.ctx ictx := config.ctx
ctx.Data = &preMountCommandsData{Device: device} ictx.Data = &preMountCommandsData{Device: device}
ui.Say("Running device setup commands...") ui.Say("Running device setup commands...")
if err := RunLocalCommands(s.Commands, wrappedCommand, ctx, ui); err != nil { if err := RunLocalCommands(s.Commands, wrappedCommand, ictx, ui); err != nil {
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt

View File

@ -14,7 +14,7 @@ import (
type StepPrepareDevice struct { type StepPrepareDevice struct {
} }
func (s *StepPrepareDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepPrepareDevice) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -1,9 +1,10 @@
package chroot package chroot
import ( import (
"testing"
amazon "github.com/hashicorp/packer/builder/amazon/common" amazon "github.com/hashicorp/packer/builder/amazon/common"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
"testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"

View File

@ -17,7 +17,7 @@ type StepCleanupVolumes struct {
BlockDevices BlockDevices BlockDevices BlockDevices
} }
func (s *StepCleanupVolumes) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCleanupVolumes) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
// stepCleanupVolumes is for Cleanup only // stepCleanupVolumes is for Cleanup only
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -20,7 +20,7 @@ type StepCreateTags struct {
Ctx interpolate.Context Ctx interpolate.Context
} }
func (s *StepCreateTags) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
session := state.Get("awsSession").(*session.Session) session := state.Get("awsSession").(*session.Session)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -18,7 +18,7 @@ type StepDeregisterAMI struct {
Regions []string Regions []string
} }
func (s *StepDeregisterAMI) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepDeregisterAMI) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
// Check for force deregister // Check for force deregister
if !s.ForceDeregister { if !s.ForceDeregister {
return multistep.ActionContinue return multistep.ActionContinue

View File

@ -27,7 +27,7 @@ type StepGetPassword struct {
BuildName string BuildName string
} }
func (s *StepGetPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepGetPassword) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
// Skip if we're not using winrm // Skip if we're not using winrm

View File

@ -20,7 +20,7 @@ type StepKeyPair struct {
doCleanup bool doCleanup bool
} }
func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepKeyPair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.Comm.SSHPrivateKeyFile != "" { if s.Comm.SSHPrivateKeyFile != "" {

View File

@ -22,7 +22,7 @@ type StepModifyAMIAttributes struct {
Ctx interpolate.Context Ctx interpolate.Context
} }
func (s *StepModifyAMIAttributes) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepModifyAMIAttributes) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
session := state.Get("awsSession").(*session.Session) session := state.Get("awsSession").(*session.Session)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -16,7 +16,7 @@ type StepModifyEBSBackedInstance struct {
EnableAMISriovNetSupport bool EnableAMISriovNetSupport bool
} }
func (s *StepModifyEBSBackedInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepModifyEBSBackedInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
instance := state.Get("instance").(*ec2.Instance) instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -45,7 +45,7 @@ func mostFreeSubnet(subnets []*ec2.Subnet) *ec2.Subnet {
return sortedSubnets[len(sortedSubnets)-1] return sortedSubnets[len(sortedSubnets)-1]
} }
func (s *StepNetworkInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepNetworkInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -21,7 +21,7 @@ type StepPreValidate struct {
ForceDeregister bool ForceDeregister bool
} }
func (s *StepPreValidate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepPreValidate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if accessConfig, ok := state.GetOk("access_config"); ok { if accessConfig, ok := state.GetOk("access_config"); ok {

View File

@ -25,7 +25,7 @@ type StepSecurityGroup struct {
createdGroupId string createdGroupId string
} }
func (s *StepSecurityGroup) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepSecurityGroup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vpcId := state.Get("vpc_id").(string) vpcId := state.Get("vpc_id").(string)

View File

@ -42,7 +42,7 @@ func mostRecentAmi(images []*ec2.Image) *ec2.Image {
return sortedImages[len(sortedImages)-1] return sortedImages[len(sortedImages)-1]
} }
func (s *StepSourceAMIInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepSourceAMIInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -1,10 +1,11 @@
package common package common
import ( import (
"testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestStepSourceAmiInfo_PVImage(t *testing.T) { func TestStepSourceAmiInfo_PVImage(t *testing.T) {

View File

@ -24,16 +24,16 @@ func (t TagMap) IsSet() bool {
return len(t) > 0 return len(t) > 0
} }
func (t TagMap) EC2Tags(ctx interpolate.Context, region string, state multistep.StateBag) (EC2Tags, error) { func (t TagMap) EC2Tags(ictx interpolate.Context, region string, state multistep.StateBag) (EC2Tags, error) {
var ec2Tags []*ec2.Tag var ec2Tags []*ec2.Tag
ctx.Data = extractBuildInfo(region, state) ictx.Data = extractBuildInfo(region, state)
for key, value := range t { for key, value := range t {
interpolatedKey, err := interpolate.Render(key, &ctx) interpolatedKey, err := interpolate.Render(key, &ictx)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error processing tag: %s:%s - %s", key, value, err) return nil, fmt.Errorf("Error processing tag: %s:%s - %s", key, value, err)
} }
interpolatedValue, err := interpolate.Render(value, &ctx) interpolatedValue, err := interpolate.Render(value, &ictx)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error processing tag: %s:%s - %s", key, value, err) return nil, fmt.Errorf("Error processing tag: %s:%s - %s", key, value, err)
} }

View File

@ -6,8 +6,8 @@
package ebs package ebs
import ( import (
"context"
"fmt" "fmt"
"log"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
awscommon "github.com/hashicorp/packer/builder/amazon/common" awscommon "github.com/hashicorp/packer/builder/amazon/common"
@ -85,7 +85,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session() session, err := b.config.Session()
if err != nil { if err != nil {
@ -245,7 +245,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
return nil, rawErr.(error) return nil, rawErr.(error)
@ -265,10 +265,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -3,9 +3,9 @@
package ebssurrogate package ebssurrogate
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"log"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
awscommon "github.com/hashicorp/packer/builder/amazon/common" awscommon "github.com/hashicorp/packer/builder/amazon/common"
@ -100,7 +100,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session() session, err := b.config.Session()
if err != nil { if err != nil {
return nil, err return nil, err
@ -270,7 +270,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -290,10 +290,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -3,8 +3,8 @@
package ebsvolume package ebsvolume
import ( import (
"context"
"fmt" "fmt"
"log"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
awscommon "github.com/hashicorp/packer/builder/amazon/common" awscommon "github.com/hashicorp/packer/builder/amazon/common"
@ -89,7 +89,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session() session, err := b.config.Session()
if err != nil { if err != nil {
return nil, err return nil, err
@ -210,7 +210,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -226,10 +226,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ui.Say(fmt.Sprintf("Created Volumes: %s", artifact)) ui.Say(fmt.Sprintf("Created Volumes: %s", artifact))
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -15,7 +15,7 @@ type stepTagEBSVolumes struct {
Ctx interpolate.Context Ctx interpolate.Context
} }
func (s *stepTagEBSVolumes) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepTagEBSVolumes) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2) ec2conn := state.Get("ec2").(*ec2.EC2)
instance := state.Get("instance").(*ec2.Instance) instance := state.Get("instance").(*ec2.Instance)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -3,9 +3,9 @@
package instance package instance
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
@ -170,7 +170,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session() session, err := b.config.Session()
if err != nil { if err != nil {
return nil, err return nil, err
@ -321,7 +321,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -342,10 +342,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -24,7 +24,7 @@ type StepBundleVolume struct {
Debug bool Debug bool
} }
func (s *StepBundleVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepBundleVolume) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
comm := state.Get("communicator").(packer.Communicator) comm := state.Get("communicator").(packer.Communicator)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
instance := state.Get("instance").(*ec2.Instance) instance := state.Get("instance").(*ec2.Instance)

View File

@ -23,7 +23,7 @@ type StepUploadBundle struct {
Debug bool Debug bool
} }
func (s *StepUploadBundle) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepUploadBundle) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
comm := state.Get("communicator").(packer.Communicator) comm := state.Get("communicator").(packer.Communicator)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
manifestName := state.Get("manifest_name").(string) manifestName := state.Get("manifest_name").(string)

View File

@ -11,7 +11,7 @@ import (
type StepUploadX509Cert struct{} type StepUploadX509Cert struct{}
func (s *StepUploadX509Cert) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepUploadX509Cert) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
comm := state.Get("communicator").(packer.Communicator) comm := state.Get("communicator").(packer.Communicator)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -4,7 +4,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/approvals/go-approval-tests" approvaltests "github.com/approvals/go-approval-tests"
"github.com/hashicorp/packer/common/json" "github.com/hashicorp/packer/common/json"
) )

View File

@ -27,7 +27,6 @@ type Builder struct {
config *Config config *Config
stateBag multistep.StateBag stateBag multistep.StateBag
runner multistep.Runner runner multistep.Runner
ctxCancel context.CancelFunc
} }
const ( const (
@ -51,12 +50,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, errs return warnings, errs
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ui.Say("Running builder ...") ui.Say("Running builder ...")
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(ctx)
b.ctxCancel = cancel
defer cancel() defer cancel()
// User's intent to use MSI is indicated with empty subscription id, tenant, client id, client cert, client secret and jwt. // User's intent to use MSI is indicated with empty subscription id, tenant, client id, client cert, client secret and jwt.
@ -259,7 +257,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
} }
b.runner = packerCommon.NewRunner(steps, b.config.PackerConfig, ui) b.runner = packerCommon.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(b.stateBag) b.runner.Run(ctx, b.stateBag)
// Report any errors. // Report any errors.
if rawErr, ok := b.stateBag.GetOk(constants.Error); ok { if rawErr, ok := b.stateBag.GetOk(constants.Error); ok {
@ -324,17 +322,6 @@ func (b *Builder) isPrivateNetworkCommunication() bool {
return b.config.VirtualNetworkName != "" return b.config.VirtualNetworkName != ""
} }
func (b *Builder) Cancel() {
if b.ctxCancel != nil {
log.Printf("Cancelling Azure builder...")
b.ctxCancel()
}
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}
func equalLocation(location1, location2 string) bool { func equalLocation(location1, location2 string) bool {
return strings.EqualFold(canonicalizeLocation(location1), canonicalizeLocation(location2)) return strings.EqualFold(canonicalizeLocation(location1), canonicalizeLocation(location2))
} }

View File

@ -24,8 +24,9 @@ import (
"testing" "testing"
"fmt" "fmt"
builderT "github.com/hashicorp/packer/helper/builder/testing"
"os" "os"
builderT "github.com/hashicorp/packer/helper/builder/testing"
) )
const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST" const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST"

View File

@ -74,7 +74,7 @@ func TestStepCaptureImageShouldTakeStepArgumentsFromStateBag(t *testing.T) {
} }
var testSubject = &StepCaptureImage{ var testSubject = &StepCaptureImage{
captureVhd: func(_ context.Context, resourceGroupName string, computeName string, parameters *compute.VirtualMachineCaptureParameters) error { captureVhd: func(ctx context.Context, resourceGroupName string, computeName string, parameters *compute.VirtualMachineCaptureParameters) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualComputeName = computeName actualComputeName = computeName
actualVirtualMachineCaptureParameters = parameters actualVirtualMachineCaptureParameters = parameters

View File

@ -105,7 +105,7 @@ func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T
var actualTags map[string]*string var actualTags map[string]*string
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(_ context.Context, resourceGroupName string, location string, tags map[string]*string) error { create: func(ctx context.Context, resourceGroupName string, location string, tags map[string]*string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualLocation = location actualLocation = location
actualTags = tags actualTags = tags

View File

@ -54,7 +54,7 @@ func TestStepDeployTemplateShouldTakeStepArgumentsFromStateBag(t *testing.T) {
var actualDeploymentName string var actualDeploymentName string
var testSubject = &StepDeployTemplate{ var testSubject = &StepDeployTemplate{
deploy: func(_ context.Context, resourceGroupName string, deploymentName string) error { deploy: func(ctx context.Context, resourceGroupName string, deploymentName string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualDeploymentName = deploymentName actualDeploymentName = deploymentName

View File

@ -40,7 +40,7 @@ func (s *StepGetCertificate) getCertificateUrl(keyVaultName string, secretName s
return *secret.ID, err return *secret.ID, err
} }
func (s *StepGetCertificate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepGetCertificate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
s.say("Getting the certificate's URL ...") s.say("Getting the certificate's URL ...")
var keyVaultName = state.Get(constants.ArmKeyVaultName).(string) var keyVaultName = state.Get(constants.ArmKeyVaultName).(string)

View File

@ -13,7 +13,7 @@ type StepSaveWinRMPassword struct {
BuildName string BuildName string
} }
func (s *StepSaveWinRMPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepSaveWinRMPassword) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
// store so that we can access this later during provisioning // store so that we can access this later during provisioning
commonhelper.SetSharedState("winrm_password", s.Password, s.BuildName) commonhelper.SetSharedState("winrm_password", s.Password, s.BuildName)
packer.LogSecretFilter.Set(s.Password) packer.LogSecretFilter.Set(s.Password)

View File

@ -24,7 +24,7 @@ func NewStepSetCertificate(config *Config, ui packer.Ui) *StepSetCertificate {
return step return step
} }
func (s *StepSetCertificate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepSetCertificate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
s.say("Setting the certificate's URL ...") s.say("Setting the certificate's URL ...")
var winRMCertificateUrl = state.Get(constants.ArmCertificateUrl).(string) var winRMCertificateUrl = state.Get(constants.ArmCertificateUrl).(string)

View File

@ -3,9 +3,10 @@ package arm
import ( import (
"context" "context"
"fmt" "fmt"
"testing"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"testing"
) )
func TestStepSnapshotDataDisksShouldFailIfSnapshotFails(t *testing.T) { func TestStepSnapshotDataDisksShouldFailIfSnapshotFails(t *testing.T) {

View File

@ -3,6 +3,7 @@ package arm
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"

View File

@ -3,9 +3,10 @@ package arm
import ( import (
"context" "context"
"fmt" "fmt"
"testing"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"testing"
) )
func TestStepSnapshotOSDiskShouldFailIfSnapshotFails(t *testing.T) { func TestStepSnapshotOSDiskShouldFailIfSnapshotFails(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources"
"github.com/approvals/go-approval-tests" approvaltests "github.com/approvals/go-approval-tests"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/builder/azure/common/template" "github.com/hashicorp/packer/builder/azure/common/template"
) )

View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/approvals/go-approval-tests" approvaltests "github.com/approvals/go-approval-tests"
) )
// Ensure that a Linux template is configured as expected. // Ensure that a Linux template is configured as expected.

View File

@ -1,6 +1,7 @@
package cloudstack package cloudstack
import ( import (
"context"
"fmt" "fmt"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
@ -31,7 +32,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
// Run implements the packer.Builder interface. // Run implements the packer.Builder interface.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
b.ui = ui b.ui = ui
// Create a CloudStack API client. // Create a CloudStack API client.
@ -91,7 +92,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Configure the runner and run the steps. // Configure the runner and run the steps.
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -113,11 +114,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
// Cancel the step runner.
func (b *Builder) Cancel() {
if b.runner != nil {
b.ui.Say("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -17,7 +17,7 @@ type stepSetupNetworking struct {
publicPort int publicPort int
} }
func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepSetupNetworking) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -28,7 +28,7 @@ type stepCreateInstance struct {
} }
// Run executes the Packer build step that creates a CloudStack instance. // Run executes the Packer build step that creates a CloudStack instance.
func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -14,7 +14,7 @@ type stepCreateSecurityGroup struct {
tempSG string tempSG string
} }
func (s *stepCreateSecurityGroup) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateSecurityGroup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -12,7 +12,7 @@ import (
type stepCreateTemplate struct{} type stepCreateTemplate struct{}
func (s *stepCreateTemplate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateTemplate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -18,7 +18,7 @@ type stepKeypair struct {
DebugKeyPath string DebugKeyPath string
} }
func (s *stepKeypair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepKeypair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.Comm.SSHPrivateKeyFile != "" { if s.Comm.SSHPrivateKeyFile != "" {

View File

@ -13,7 +13,7 @@ import (
type stepPrepareConfig struct{} type stepPrepareConfig struct{}
func (s *stepPrepareConfig) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepPrepareConfig) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -11,7 +11,7 @@ import (
type stepShutdownInstance struct{} type stepShutdownInstance struct{}
func (s *stepShutdownInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepShutdownInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*cloudstack.CloudStackClient) client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -35,7 +35,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, &apiTokenSource{ client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, &apiTokenSource{
AccessToken: b.config.APIToken, AccessToken: b.config.APIToken,
})) }))
@ -100,7 +100,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run the steps // Run the steps
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -121,10 +121,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -15,7 +15,7 @@ type stepCreateDroplet struct {
dropletId int dropletId int
} }
func (s *stepCreateDroplet) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)

View File

@ -25,7 +25,7 @@ type stepCreateSSHKey struct {
keyId int keyId int
} }
func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepCreateSSHKey) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)

View File

@ -11,7 +11,7 @@ import (
type stepDropletInfo struct{} type stepDropletInfo struct{}
func (s *stepDropletInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepDropletInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)

View File

@ -12,7 +12,7 @@ import (
type stepPowerOff struct{} type stepPowerOff struct{}
func (s *stepPowerOff) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepPowerOff) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -13,7 +13,7 @@ import (
type stepShutdown struct{} type stepShutdown struct{}
func (s *stepShutdown) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -14,7 +14,7 @@ import (
type stepSnapshot struct{} type stepSnapshot struct{}
func (s *stepSnapshot) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client) client := state.Get("client").(*godo.Client)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config) c := state.Get("config").(*Config)

View File

@ -1,6 +1,7 @@
package docker package docker
import ( import (
"context"
"log" "log"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
@ -29,7 +30,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, nil return warnings, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
driver := &DockerDriver{Ctx: &b.config.ctx, Ui: ui} driver := &DockerDriver{Ctx: &b.config.ctx, Ui: ui}
if err := driver.Verify(); err != nil { if err := driver.Verify(); err != nil {
return nil, err return nil, err
@ -83,7 +84,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run! // Run!
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// If there was an error, return that // If there was an error, return that
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -109,10 +110,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -1,6 +1,7 @@
package docker package docker
import ( import (
"context"
"crypto/sha256" "crypto/sha256"
"io/ioutil" "io/ioutil"
"os" "os"
@ -75,7 +76,7 @@ func TestUploadDownload(t *testing.T) {
hook := &packer.DispatchHook{Mapping: hooks} hook := &packer.DispatchHook{Mapping: hooks}
// Run things // Run things
artifact, err := builder.Run(ui, hook) artifact, err := builder.Run(context.Background(), ui, hook)
if err != nil { if err != nil {
t.Fatalf("Error running build %s", err) t.Fatalf("Error running build %s", err)
} }
@ -164,7 +165,7 @@ func TestLargeDownload(t *testing.T) {
hook := &packer.DispatchHook{Mapping: hooks} hook := &packer.DispatchHook{Mapping: hooks}
// Run things // Run things
artifact, err := builder.Run(ui, hook) artifact, err := builder.Run(context.Background(), ui, hook)
if err != nil { if err != nil {
t.Fatalf("Error running build %s", err) t.Fatalf("Error running build %s", err)
} }
@ -272,7 +273,7 @@ func TestFixUploadOwner(t *testing.T) {
} }
hook := &packer.DispatchHook{Mapping: hooks} hook := &packer.DispatchHook{Mapping: hooks}
artifact, err := builder.Run(ui, hook) artifact, err := builder.Run(context.Background(), ui, hook)
if err != nil { if err != nil {
t.Fatalf("Error running build %s", err) t.Fatalf("Error running build %s", err)
} }

View File

@ -260,8 +260,8 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
// Build up the template data // Build up the template data
var tplData startContainerTemplate var tplData startContainerTemplate
tplData.Image = config.Image tplData.Image = config.Image
ctx := *d.Ctx ictx := *d.Ctx
ctx.Data = &tplData ictx.Data = &tplData
// Args that we're going to pass to Docker // Args that we're going to pass to Docker
args := []string{"run"} args := []string{"run"}
@ -272,7 +272,7 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
args = append(args, "-v", fmt.Sprintf("%s:%s", host, guest)) args = append(args, "-v", fmt.Sprintf("%s:%s", host, guest))
} }
for _, v := range config.RunCommand { for _, v := range config.RunCommand {
v, err := interpolate.Render(v, &ctx) v, err := interpolate.Render(v, &ictx)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -13,7 +13,7 @@ type StepCommit struct {
imageId string imageId string
} }
func (s *StepCommit) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCommit) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
containerId := state.Get("container_id").(string) containerId := state.Get("container_id").(string)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)

View File

@ -11,7 +11,7 @@ import (
type StepConnectDocker struct{} type StepConnectDocker struct{}
func (s *StepConnectDocker) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepConnectDocker) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
containerId := state.Get("container_id").(string) containerId := state.Get("container_id").(string)
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)

View File

@ -13,7 +13,7 @@ import (
// StepExport exports the container to a flat tar file. // StepExport exports the container to a flat tar file.
type StepExport struct{} type StepExport struct{}
func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)

View File

@ -11,7 +11,7 @@ import (
type StepPull struct{} type StepPull struct{}
func (s *StepPull) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepPull) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -12,7 +12,7 @@ type StepRun struct {
containerId string containerId string
} }
func (s *StepRun) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
tempDir := state.Get("temp_dir").(string) tempDir := state.Get("temp_dir").(string)

View File

@ -37,7 +37,7 @@ func ConfigTmpDir() (string, error) {
return td, nil return td, nil
} }
func (s *StepTempDir) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepTempDir) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
ui.Say("Creating a temporary directory for sharing data...") ui.Say("Creating a temporary directory for sharing data...")

View File

@ -6,6 +6,7 @@ any virtualization or network resources, it's very fast and useful for testing.
*/ */
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -33,7 +34,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
// Run is where the actual build should take place. It takes a Build and a Ui. // Run is where the actual build should take place. It takes a Build and a Ui.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
artifact := new(FileArtifact) artifact := new(FileArtifact)
if b.config.Source != "" { if b.config.Source != "" {
@ -69,9 +70,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
return artifact, nil return artifact, nil
} }
// Cancel cancels a possibly running Builder. This should block until
// the builder actually cancels and cleans up after itself.
func (b *Builder) Cancel() {
b.runner.Cancel()
}

View File

@ -3,6 +3,7 @@
package googlecompute package googlecompute
import ( import (
"context"
"fmt" "fmt"
"log" "log"
@ -33,7 +34,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Run executes a googlecompute Packer build and returns a packer.Artifact // Run executes a googlecompute Packer build and returns a packer.Artifact
// representing a GCE machine image. // representing a GCE machine image.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
driver, err := NewDriverGCE( driver, err := NewDriverGCE(
ui, b.config.ProjectId, &b.config.Account) ui, b.config.ProjectId, &b.config.Account)
if err != nil { if err != nil {
@ -82,7 +83,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Run the steps. // Run the steps.
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner.Run(state) b.runner.Run(ctx, state)
// Report any errors. // Report any errors.
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
@ -102,9 +103,3 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
} }
// Cancel. // Cancel.
func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}

View File

@ -13,7 +13,7 @@ import (
type StepCheckExistingImage int type StepCheckExistingImage int
// Run executes the Packer build step that checks if the image already exists. // Run executes the Packer build step that checks if the image already exists.
func (s *StepCheckExistingImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCheckExistingImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config) c := state.Get("config").(*Config)
d := state.Get("driver").(Driver) d := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -18,7 +18,7 @@ type StepCreateImage int
// //
// The image is created from the persistent disk used by the instance. The // The image is created from the persistent disk used by the instance. The
// instance must be deleted and the disk retained before doing this step. // instance must be deleted and the disk retained before doing this step.
func (s *StepCreateImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)

View File

@ -73,7 +73,7 @@ func getImage(c *Config, d Driver) (*Image, error) {
} }
// Run executes the Packer build step that creates a GCE instance. // Run executes the Packer build step that creates a GCE instance.
func (s *StepCreateInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config) c := state.Get("config").(*Config)
d := state.Get("driver").(Driver) d := state.Get("driver").(Driver)

Some files were not shown because too many files have changed in this diff Show More