Commit 9ebf0435 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

provisioner/shell: Basic run

parent 33f8d295
......@@ -6,5 +6,6 @@
* packer: Communicator should have Close() method
* packer: Ui input
* packer/plugin: Better error messages/detection if plugin crashes
* packer/plugin: Testing of client struct/methods
* provisioner/shell: Upload file
* provisioner/shell: Arguments
{
"name": "my-custom-image",
"builders": [
{
"type": "amazon-ebs",
"region": "us-east-1",
"source_ami": "ami-de0d9eb7"
}
],
"provisioners": [
{
"type": "shell",
"path": "script.sh"
}
],
"outputs": [
{
"type": "vagrant"
}
]
}
name = "my-custom-image"
[builder.amazon-ebs]
region = "us-east-1"
source = "ami-de0d9eb7"
[provision]
[provision.shell]
type = "shell"
path = "script.sh"
[output]
[output.vagrant]
......@@ -3,8 +3,11 @@
package shell
import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"log"
"os"
)
const DefaultRemotePath = "/tmp/script.sh"
......@@ -33,5 +36,29 @@ func (p *Provisioner) Prepare(raw interface{}, ui packer.Ui) {
}
func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
ui.Say("PROVISIONING SOME STUFF")
log.Printf("Opening %s for reading", p.config.Path)
f, err := os.Open(p.config.Path)
if err != nil {
ui.Error(fmt.Sprintf("Error opening shell script: %s", err))
return
}
log.Printf("Uploading %s => %s", p.config.Path, p.config.RemotePath)
err = comm.Upload(p.config.RemotePath, f)
if err != nil {
ui.Error(fmt.Sprintf("Error uploading shell script: %s", err))
return
}
command := fmt.Sprintf("chmod +x %s && %s", p.config.RemotePath, p.config.RemotePath)
log.Printf("Executing command: %s", command)
cmd, err := comm.Start(command)
if err != nil {
ui.Error(fmt.Sprintf("Failed executing command: %s", err))
return
}
ui.Say("Waiting for remote command to finish...")
cmd.Wait()
ui.Say("Command run!")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment