-
Notifications
You must be signed in to change notification settings - Fork 46
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
Update packer-provisioner-goss.go #7
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ type GossConfig struct { | |
Arch string | ||
URL string | ||
DownloadPath string | ||
Username string | ||
Password string | ||
SkipInstall bool | ||
|
||
// Enable debug for goss (defaults to false) | ||
|
@@ -27,6 +29,15 @@ type GossConfig struct { | |
// An array of tests to run. | ||
Tests []string | ||
|
||
// Use Sudo | ||
UseSudo bool `mapstructure:"use_sudo"` | ||
|
||
// skip ssl check flag | ||
SkipSSLChk bool `mapstructure:"skip_ssl"` | ||
|
||
// The --gossfile flag | ||
GossFile string `mapstructure:"goss_file"` | ||
|
||
// The remote folder where the goss tests will be uploaded to. | ||
// This should be set to a pre-existing directory, it defaults to /tmp | ||
RemoteFolder string `mapstructure:"remote_folder"` | ||
|
@@ -95,6 +106,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { | |
p.config.Tests = make([]string, 0) | ||
} | ||
|
||
if p.config.GossFile != "" { | ||
p.config.GossFile = fmt.Sprintf("--gossfile %s", p.config.GossFile) | ||
} | ||
|
||
var errs *packer.MultiError | ||
if len(p.config.Tests) == 0 { | ||
errs = packer.MultiErrorAppend(errs, | ||
|
@@ -144,6 +159,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { | |
if err := p.uploadFile(ui, comm, dst, src); err != nil { | ||
return fmt.Errorf("Error uploading goss test: %s", err) | ||
} | ||
} else if s.Mode().IsDir() == true { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
also, you can fix the one above it too :) |
||
ui.Message(fmt.Sprintf("Uploading Dir %s", src)) | ||
dst := filepath.ToSlash(filepath.Join(p.config.RemotePath, filepath.Base(src))) | ||
if err := p.uploadDir(ui, comm, dst, src); err != nil { | ||
return fmt.Errorf("Error uploading goss test: %s", err) | ||
} | ||
} else { | ||
ui.Message(fmt.Sprintf("Ignoring %s... not a regular file", src)) | ||
} | ||
|
@@ -169,8 +190,9 @@ func (p *Provisioner) installGoss(ui packer.Ui, comm packer.Communicator) error | |
cmd := &packer.RemoteCmd{ | ||
// Fallback on wget if curl failed for any reason (such as not being installed) | ||
Command: fmt.Sprintf( | ||
"curl -L -o %s %s || wget -O %s %s", | ||
p.config.DownloadPath, p.config.URL, p.config.DownloadPath, p.config.URL), | ||
"curl -L %s %s -o %s %s || wget %s %s -O %s %s", | ||
p.sslFlag("curl"), p.userPass("curl"), p.config.DownloadPath, p.config.URL, | ||
p.sslFlag("wget"), p.userPass("wget"), p.config.DownloadPath, p.config.URL), | ||
} | ||
ui.Message(fmt.Sprintf("Downloading Goss to %s", p.config.DownloadPath)) | ||
if err := cmd.StartWithUi(comm, ui); err != nil { | ||
|
@@ -191,7 +213,8 @@ func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator) error { | |
goss := fmt.Sprintf("%s", p.config.DownloadPath) | ||
cmd := &packer.RemoteCmd{ | ||
Command: fmt.Sprintf( | ||
"cd %s && %s %s validate", p.config.RemotePath, goss, p.debug()), | ||
"cd %s && %s %s %s %s validate", | ||
p.config.RemotePath, p.enableSudo(), goss, p.config.GossFile, p.debug()), | ||
} | ||
if err := cmd.StartWithUi(comm, ui); err != nil { | ||
return err | ||
|
@@ -211,6 +234,49 @@ func (p *Provisioner) debug() string { | |
return "" | ||
} | ||
|
||
func (p *Provisioner) sslFlag(cmdType string) string { | ||
if p.config.SkipSSLChk == true { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
switch(cmdType) { | ||
case "curl": | ||
return "-k" | ||
case "wget": | ||
return "--no-check-certificate" | ||
default: | ||
return "" | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
// enable sudo if required | ||
func (p *Provisioner) enableSudo() string { | ||
if p.config.UseSudo == true { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return "sudo" | ||
} | ||
return "" | ||
} | ||
|
||
// Deal with curl & wget username and password | ||
func (p *Provisioner) userPass(cmdType string) string { | ||
if p.config.Username != "" { | ||
switch(cmdType) { | ||
case "curl": | ||
if p.config.Password == "" { | ||
return fmt.Sprintf("-u %s", p.config.Username) | ||
} | ||
return fmt.Sprintf("-u %s:%s", p.config.Username, p.config.Password) | ||
case "wget": | ||
if p.config.Password == "" { | ||
return fmt.Sprintf("--user=%s", p.config.Username) | ||
} | ||
return fmt.Sprintf("--user=%s --password=%s", p.config.Username, p.config.Password) | ||
default: | ||
return "" | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
// createDir creates a directory on the remote server | ||
func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir string) error { | ||
ui.Message(fmt.Sprintf("Creating directory: %s", dir)) | ||
|
@@ -241,7 +307,8 @@ func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst, sr | |
} | ||
|
||
// uploadDir uploads a directory | ||
func (p *Provisioner) uploadDir(ui packer.Ui, comm packer.Communicator, dst, src string, ignore []string) error { | ||
func (p *Provisioner) uploadDir(ui packer.Ui, comm packer.Communicator, dst, src string) error { | ||
var ignore []string | ||
if err := p.createDir(ui, comm, dst); err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be
username
andpassword