Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Basic support for -connection-info flag #6863

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions builder/amazon/common/step_get_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
// StepGetPassword reads the password from a Windows server and sets it
// on the WinRM config.
type StepGetPassword struct {
Debug bool
Comm *communicator.Config
Timeout time.Duration
BuildName string
DebugConnection bool
Comm *communicator.Config
Timeout time.Duration
BuildName string
}

func (s *StepGetPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down Expand Up @@ -89,13 +89,13 @@ WaitLoop:
}
}

// In debug-mode, we output the password
if s.Debug {
// If we're showing connection info, we output the password
if s.DebugConnection {
ui.Message(fmt.Sprintf(
"Password (since debug is enabled): %s", s.Comm.WinRMPassword))
"Password (since showing connection info is enabled): %s", s.Comm.WinRMPassword))
}
// 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.Comm.WinRMPassword, s.BuildName)
packer.LogSecretFilter.Set(s.Comm.WinRMPassword)

Expand Down
14 changes: 7 additions & 7 deletions builder/amazon/common/step_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

type StepKeyPair struct {
Debug bool
Comm *communicator.Config
DebugKeyPath string
DebugConnection bool
Comm *communicator.Config
DebugKeyPath string

doCleanup bool
}
Expand Down Expand Up @@ -68,10 +68,10 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
s.Comm.SSHKeyPairName = s.Comm.SSHTemporaryKeyPairName
s.Comm.SSHPrivateKey = []byte(*keyResp.KeyMaterial)

// If we're in debug mode, output the private key to the working
// If we're upposed to show connection info output the private key to the working
// directory.
if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
if s.DebugConnection {
ui.Message(fmt.Sprintf("[Connection] Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.Create(s.DebugKeyPath)
if err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
}

// Also remove the physical key if we're debugging.
if s.Debug {
if s.DebugConnection {
if err := os.Remove(s.DebugKeyPath); err != nil {
ui.Error(fmt.Sprintf(
"Error removing debug key '%s': %s", s.DebugKeyPath, err))
Expand Down
4 changes: 2 additions & 2 deletions builder/amazon/common/step_run_source_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type StepRunSourceInstance struct {
BlockDevices BlockDevices
Comm *communicator.Config
Ctx interpolate.Context
Debug bool
DebugConnection bool
EbsOptimized bool
EnableT2Unlimited bool
ExpectedRootDevice string
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
}
instance := r.Reservations[0].Instances[0]

if s.Debug {
if s.DebugConnection {
if instance.PublicDnsName != nil && *instance.PublicDnsName != "" {
ui.Message(fmt.Sprintf("Public DNS: %s", *instance.PublicDnsName))
}
Expand Down
4 changes: 2 additions & 2 deletions builder/amazon/common/step_run_spot_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type StepRunSpotInstance struct {
AssociatePublicIpAddress bool
BlockDevices BlockDevices
BlockDurationMinutes int64
Debug bool
DebugConnection bool
Comm *communicator.Config
EbsOptimized bool
ExpectedRootDevice string
Expand Down Expand Up @@ -340,7 +340,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)

}

if s.Debug {
if s.DebugConnection {
if instance.PublicDnsName != nil && *instance.PublicDnsName != "" {
ui.Message(fmt.Sprintf("Public DNS: %s", *instance.PublicDnsName))
}
Expand Down
21 changes: 11 additions & 10 deletions builder/amazon/ebs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
ExpectedRootDevice: "ebs",
IamInstanceProfile: b.config.IamInstanceProfile,
Expand All @@ -131,7 +131,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices: b.config.BlockDevices,
Comm: &b.config.RunConfig.Comm,
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
EnableT2Unlimited: b.config.EnableT2Unlimited,
ExpectedRootDevice: "ebs",
Expand Down Expand Up @@ -170,9 +170,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{
SecurityGroupFilter: b.config.SecurityGroupFilter,
Expand All @@ -185,17 +185,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
instanceStep,
&awscommon.StepGetPassword{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
},
&communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Host: awscommon.SSHHost(
ec2conn,
b.config.Comm.SSHInterface),
SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(),
SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(),
DebugConnection: b.config.PackerDebugConnection,
},
&common.StepProvision{},
&common.StepCleanupTempKeys{
Expand Down
18 changes: 9 additions & 9 deletions builder/amazon/ebssurrogate/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
ExpectedRootDevice: "ebs",
IamInstanceProfile: b.config.IamInstanceProfile,
Expand All @@ -145,7 +145,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices: b.config.BlockDevices,
Comm: &b.config.RunConfig.Comm,
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
EnableT2Unlimited: b.config.EnableT2Unlimited,
ExpectedRootDevice: "ebs",
Expand Down Expand Up @@ -187,9 +187,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{
SecurityGroupFilter: b.config.SecurityGroupFilter,
Expand All @@ -202,10 +202,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
instanceStep,
&awscommon.StepGetPassword{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
},
&communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Expand Down
18 changes: 9 additions & 9 deletions builder/amazon/ebsvolume/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
ExpectedRootDevice: "ebs",
IamInstanceProfile: b.config.IamInstanceProfile,
Expand All @@ -128,7 +128,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices: b.config.launchBlockDevices,
Comm: &b.config.RunConfig.Comm,
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
EnableT2Unlimited: b.config.EnableT2Unlimited,
ExpectedRootDevice: "ebs",
Expand Down Expand Up @@ -161,9 +161,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{
SecurityGroupFilter: b.config.SecurityGroupFilter,
Expand All @@ -177,10 +177,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx: b.config.ctx,
},
&awscommon.StepGetPassword{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
},
&communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Expand Down
18 changes: 9 additions & 9 deletions builder/amazon/instance/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDurationMinutes: b.config.BlockDurationMinutes,
Ctx: b.config.ctx,
Comm: &b.config.RunConfig.Comm,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
IamInstanceProfile: b.config.IamInstanceProfile,
InstanceType: b.config.InstanceType,
Expand All @@ -212,7 +212,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices: b.config.BlockDevices,
Comm: &b.config.RunConfig.Comm,
Ctx: b.config.ctx,
Debug: b.config.PackerDebug,
DebugConnection: b.config.PackerDebugConnection,
EbsOptimized: b.config.EbsOptimized,
EnableT2Unlimited: b.config.EnableT2Unlimited,
IamInstanceProfile: b.config.IamInstanceProfile,
Expand Down Expand Up @@ -248,9 +248,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AvailabilityZone: b.config.AvailabilityZone,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{
CommConfig: &b.config.RunConfig.Comm,
Expand All @@ -260,10 +260,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
instanceStep,
&awscommon.StepGetPassword{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
DebugConnection: b.config.PackerDebugConnection,
Comm: &b.config.RunConfig.Comm,
Timeout: b.config.WindowsPasswordTimeout,
BuildName: b.config.PackerBuildName,
},
&communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Expand Down
2 changes: 1 addition & 1 deletion builder/virtualbox/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("debug", b.config.PackerDebug)
state.Put("debug", b.config.PackerDebug) // TODO rickard remove
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commenting on TODO so that we don't forget, just resolve me !

state.Put("driver", driver)
state.Put("hook", hook)
state.Put("ui", ui)
Expand Down
8 changes: 7 additions & 1 deletion command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type BuildCommand struct {
}

func (c *BuildCommand) Run(args []string) int {
var cfgColor, cfgDebug, cfgForce, cfgTimestamp, cfgParallel bool
var cfgColor, cfgDebug, cfgDebugConn, cfgForce, cfgTimestamp, cfgParallel bool
var cfgOnError string
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars)
flags.Usage = func() { c.Ui.Say(c.Help()) }
flags.BoolVar(&cfgColor, "color", true, "")
flags.BoolVar(&cfgDebug, "debug", false, "")
flags.BoolVar(&cfgDebugConn, "debug-connection", false, "")
flags.BoolVar(&cfgForce, "force", false, "")
flags.BoolVar(&cfgTimestamp, "timestamp-ui", false, "")
flagOnError := enumflag.New(&cfgOnError, "cleanup", "abort", "ask")
Expand Down Expand Up @@ -76,6 +77,7 @@ func (c *BuildCommand) Run(args []string) int {
}

if cfgDebug {
cfgDebugConn = true
c.Ui.Say("Debug mode enabled. Builds will not be parallelized.")
}

Expand Down Expand Up @@ -115,12 +117,14 @@ func (c *BuildCommand) Run(args []string) int {
}

log.Printf("Build debug mode: %v", cfgDebug)
log.Printf("Provide connection information: %v", cfgDebugConn)
log.Printf("Force build: %v", cfgForce)
log.Printf("On error: %v", cfgOnError)

// Set the debug and force mode and prepare all the builds
for _, b := range builds {
log.Printf("Preparing build: %s", b.Name())
b.SetDebugConnection(cfgDebugConn)
b.SetDebug(cfgDebug)
b.SetForce(cfgForce)
b.SetOnError(cfgOnError)
Expand Down Expand Up @@ -302,6 +306,7 @@ Usage: packer build [options] TEMPLATE
Options:

-color=false Disable color output. (Default: color)
-debug-connection Show connection information for builds, implicitly enabled if debug is used.
-debug Debug mode enabled for builds.
-except=foo,bar,baz Build all builds other than these.
-only=foo,bar,baz Build only the specified builds.
Expand All @@ -328,6 +333,7 @@ func (*BuildCommand) AutocompleteArgs() complete.Predictor {
func (*BuildCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{
"-color": complete.PredictNothing,
"-debug-connection": complete.PredictNothing,
"-debug": complete.PredictNothing,
"-except": complete.PredictNothing,
"-only": complete.PredictNothing,
Expand Down
15 changes: 8 additions & 7 deletions common/packer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package common
// are sent by packer, properly tagged already so mapstructure can load
// them. Embed this structure into your configuration class to get it.
type PackerConfig struct {
PackerBuildName string `mapstructure:"packer_build_name"`
PackerBuilderType string `mapstructure:"packer_builder_type"`
PackerDebug bool `mapstructure:"packer_debug"`
PackerForce bool `mapstructure:"packer_force"`
PackerOnError string `mapstructure:"packer_on_error"`
PackerUserVars map[string]string `mapstructure:"packer_user_variables"`
PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables"`
PackerBuildName string `mapstructure:"packer_build_name"`
PackerBuilderType string `mapstructure:"packer_builder_type"`
PackerDebugConnection bool `mapstructure:"packer_debug_connection"`
PackerDebug bool `mapstructure:"packer_debug"`
PackerForce bool `mapstructure:"packer_force"`
PackerOnError string `mapstructure:"packer_on_error"`
PackerUserVars map[string]string `mapstructure:"packer_user_variables"`
PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables"`
}
Loading