builder/googlecompute: use helper/comm
This commit is contained in:
parent
669f301881
commit
502076c92e
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"github.com/mitchellh/packer/common"
|
"github.com/mitchellh/packer/common"
|
||||||
|
"github.com/mitchellh/packer/helper/communicator"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,10 +61,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&StepInstanceInfo{
|
&StepInstanceInfo{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
},
|
},
|
||||||
&common.StepConnectSSH{
|
&communicator.StepConnect{
|
||||||
SSHAddress: sshAddress,
|
Config: &b.config.Comm,
|
||||||
SSHConfig: sshConfig,
|
SSHAddress: sshAddress,
|
||||||
SSHWaitTimeout: b.config.sshTimeout,
|
SSHConfig: sshConfig,
|
||||||
},
|
},
|
||||||
new(common.StepProvision),
|
new(common.StepProvision),
|
||||||
new(StepTeardownInstance),
|
new(StepTeardownInstance),
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/mitchellh/packer/common"
|
"github.com/mitchellh/packer/common"
|
||||||
"github.com/mitchellh/packer/common/uuid"
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
|
"github.com/mitchellh/packer/helper/communicator"
|
||||||
"github.com/mitchellh/packer/helper/config"
|
"github.com/mitchellh/packer/helper/config"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"github.com/mitchellh/packer/template/interpolate"
|
"github.com/mitchellh/packer/template/interpolate"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
// state of the config object.
|
// state of the config object.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
common.PackerConfig `mapstructure:",squash"`
|
common.PackerConfig `mapstructure:",squash"`
|
||||||
|
Comm communicator.Config `mapstructure:",squash"`
|
||||||
|
|
||||||
AccountFile string `mapstructure:"account_file"`
|
AccountFile string `mapstructure:"account_file"`
|
||||||
ProjectId string `mapstructure:"project_id"`
|
ProjectId string `mapstructure:"project_id"`
|
||||||
|
@ -31,16 +33,12 @@ type Config struct {
|
||||||
Network string `mapstructure:"network"`
|
Network string `mapstructure:"network"`
|
||||||
SourceImage string `mapstructure:"source_image"`
|
SourceImage string `mapstructure:"source_image"`
|
||||||
SourceImageProjectId string `mapstructure:"source_image_project_id"`
|
SourceImageProjectId string `mapstructure:"source_image_project_id"`
|
||||||
SSHUsername string `mapstructure:"ssh_username"`
|
|
||||||
SSHPort uint `mapstructure:"ssh_port"`
|
|
||||||
RawSSHTimeout string `mapstructure:"ssh_timeout"`
|
|
||||||
RawStateTimeout string `mapstructure:"state_timeout"`
|
RawStateTimeout string `mapstructure:"state_timeout"`
|
||||||
Tags []string `mapstructure:"tags"`
|
Tags []string `mapstructure:"tags"`
|
||||||
Zone string `mapstructure:"zone"`
|
Zone string `mapstructure:"zone"`
|
||||||
|
|
||||||
account accountFile
|
account accountFile
|
||||||
privateKeyBytes []byte
|
privateKeyBytes []byte
|
||||||
sshTimeout time.Duration
|
|
||||||
stateTimeout time.Duration
|
stateTimeout time.Duration
|
||||||
ctx *interpolate.Context
|
ctx *interpolate.Context
|
||||||
}
|
}
|
||||||
|
@ -88,20 +86,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
c.MachineType = "n1-standard-1"
|
c.MachineType = "n1-standard-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.RawSSHTimeout == "" {
|
|
||||||
c.RawSSHTimeout = "5m"
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.RawStateTimeout == "" {
|
if c.RawStateTimeout == "" {
|
||||||
c.RawStateTimeout = "5m"
|
c.RawStateTimeout = "5m"
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.SSHUsername == "" {
|
if c.Comm.SSHUsername == "" {
|
||||||
c.SSHUsername = "root"
|
c.Comm.SSHUsername = "root"
|
||||||
}
|
|
||||||
|
|
||||||
if c.SSHPort == 0 {
|
|
||||||
c.SSHPort = 22
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var errs *packer.MultiError
|
var errs *packer.MultiError
|
||||||
|
@ -122,14 +112,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
errs, errors.New("a zone must be specified"))
|
errs, errors.New("a zone must be specified"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process timeout settings.
|
|
||||||
sshTimeout, err := time.ParseDuration(c.RawSSHTimeout)
|
|
||||||
if err != nil {
|
|
||||||
errs = packer.MultiErrorAppend(
|
|
||||||
errs, fmt.Errorf("Failed parsing ssh_timeout: %s", err))
|
|
||||||
}
|
|
||||||
c.sshTimeout = sshTimeout
|
|
||||||
|
|
||||||
stateTimeout, err := time.ParseDuration(c.RawStateTimeout)
|
stateTimeout, err := time.ParseDuration(c.RawStateTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = packer.MultiErrorAppend(
|
errs = packer.MultiErrorAppend(
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func sshAddress(state multistep.StateBag) (string, error) {
|
func sshAddress(state multistep.StateBag) (string, error) {
|
||||||
config := state.Get("config").(*Config)
|
config := state.Get("config").(*Config)
|
||||||
ipAddress := state.Get("instance_ip").(string)
|
ipAddress := state.Get("instance_ip").(string)
|
||||||
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
|
return fmt.Sprintf("%s:%d", ipAddress, config.Comm.SSHPort), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sshConfig returns the ssh configuration.
|
// sshConfig returns the ssh configuration.
|
||||||
|
@ -24,7 +24,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ssh.ClientConfig{
|
return &ssh.ClientConfig{
|
||||||
User: config.SSHUsername,
|
User: config.Comm.SSHUsername,
|
||||||
Auth: []ssh.AuthMethod{
|
Auth: []ssh.AuthMethod{
|
||||||
ssh.PublicKeys(signer),
|
ssh.PublicKeys(signer),
|
||||||
},
|
},
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (config *Config) getInstanceMetadata(sshPublicKey string) map[string]string
|
||||||
|
|
||||||
// Merge any existing ssh keys with our public key
|
// Merge any existing ssh keys with our public key
|
||||||
sshMetaKey := "sshKeys"
|
sshMetaKey := "sshKeys"
|
||||||
sshKeys := fmt.Sprintf("%s:%s", config.SSHUsername, sshPublicKey)
|
sshKeys := fmt.Sprintf("%s:%s", config.Comm.SSHUsername, sshPublicKey)
|
||||||
if confSshKeys, exists := instanceMetadata[sshMetaKey]; exists {
|
if confSshKeys, exists := instanceMetadata[sshMetaKey]; exists {
|
||||||
sshKeys = fmt.Sprintf("%s\n%s", sshKeys, confSshKeys)
|
sshKeys = fmt.Sprintf("%s\n%s", sshKeys, confSshKeys)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue