Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
4a8278d4
Commit
4a8278d4
authored
Jun 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: Support setting the execute command
parent
e9b552ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
10 deletions
+28
-10
packer/provisioner_test.go
packer/provisioner_test.go
+2
-2
packer/rpc/provisioner.go
packer/rpc/provisioner.go
+1
-1
packer/rpc/provisioner_test.go
packer/rpc/provisioner_test.go
+4
-4
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+21
-3
No files found.
packer/provisioner_test.go
View file @
4a8278d4
...
@@ -3,9 +3,9 @@ package packer
...
@@ -3,9 +3,9 @@ package packer
import
"testing"
import
"testing"
type
TestProvisioner
struct
{
type
TestProvisioner
struct
{
prepCalled
bool
prepCalled
bool
prepConfigs
[]
interface
{}
prepConfigs
[]
interface
{}
provCalled
bool
provCalled
bool
}
}
func
(
t
*
TestProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
func
(
t
*
TestProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
...
...
packer/rpc/provisioner.go
View file @
4a8278d4
...
@@ -18,7 +18,7 @@ type ProvisionerServer struct {
...
@@ -18,7 +18,7 @@ type ProvisionerServer struct {
}
}
type
ProvisionerPrepareArgs
struct
{
type
ProvisionerPrepareArgs
struct
{
Configs
[]
interface
{}
Configs
[]
interface
{}
}
}
type
ProvisionerProvisionArgs
struct
{
type
ProvisionerProvisionArgs
struct
{
...
...
packer/rpc/provisioner_test.go
View file @
4a8278d4
...
@@ -8,11 +8,11 @@ import (
...
@@ -8,11 +8,11 @@ import (
)
)
type
testProvisioner
struct
{
type
testProvisioner
struct
{
prepareCalled
bool
prepareCalled
bool
prepareConfigs
[]
interface
{}
prepareConfigs
[]
interface
{}
provCalled
bool
provCalled
bool
provComm
packer
.
Communicator
provComm
packer
.
Communicator
provUi
packer
.
Ui
provUi
packer
.
Ui
}
}
func
(
p
*
testProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
func
(
p
*
testProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
...
...
provisioner/shell/provisioner.go
View file @
4a8278d4
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
package
shell
package
shell
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/mitchellh/iochan"
"github.com/mitchellh/iochan"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/mapstructure"
...
@@ -11,24 +12,32 @@ import (
...
@@ -11,24 +12,32 @@ import (
"log"
"log"
"os"
"os"
"strings"
"strings"
"text/template"
)
)
const
DefaultRemotePath
=
"/tmp/script.sh"
const
DefaultRemotePath
=
"/tmp/script.sh"
// TODO(mitchellh): config
type
config
struct
{
type
config
struct
{
// The local path of the shell script to upload and execute.
// The local path of the shell script to upload and execute.
Path
string
Path
string
// The remote path where the local shell script will be uploaded to.
// The remote path where the local shell script will be uploaded to.
// This should be set to a writable file that is in a pre-existing directory.
// This should be set to a writable file that is in a pre-existing directory.
RemotePath
string
RemotePath
string
`mapstructure:"remote_path"`
// The command used to execute the script. The '{{ .Path }}' variable
// should be used to specify where the script goes.
ExecuteCommand
string
`mapstructure:"execute_command"`
}
}
type
Provisioner
struct
{
type
Provisioner
struct
{
config
config
config
config
}
}
type
ExecuteCommandTemplate
struct
{
Path
string
}
func
(
p
*
Provisioner
)
Prepare
(
raws
...
interface
{})
error
{
func
(
p
*
Provisioner
)
Prepare
(
raws
...
interface
{})
error
{
for
_
,
raw
:=
range
raws
{
for
_
,
raw
:=
range
raws
{
if
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
);
err
!=
nil
{
if
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
);
err
!=
nil
{
...
@@ -36,6 +45,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
...
@@ -36,6 +45,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
}
}
}
if
p
.
config
.
ExecuteCommand
==
""
{
p
.
config
.
ExecuteCommand
=
"chmod +x {{.Path}} && {{.Path}}"
}
if
p
.
config
.
RemotePath
==
""
{
if
p
.
config
.
RemotePath
==
""
{
p
.
config
.
RemotePath
=
DefaultRemotePath
p
.
config
.
RemotePath
=
DefaultRemotePath
}
}
...
@@ -60,12 +73,17 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
...
@@ -60,12 +73,17 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
return
return
}
}
// Compile the command
var
command
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"command"
)
.
Parse
(
p
.
config
.
ExecuteCommand
))
t
.
Execute
(
&
command
,
&
ExecuteCommandTemplate
{
p
.
config
.
RemotePath
})
// Setup the remote command
// Setup the remote command
stdout_r
,
stdout_w
:=
io
.
Pipe
()
stdout_r
,
stdout_w
:=
io
.
Pipe
()
stderr_r
,
stderr_w
:=
io
.
Pipe
()
stderr_r
,
stderr_w
:=
io
.
Pipe
()
var
cmd
packer
.
RemoteCmd
var
cmd
packer
.
RemoteCmd
cmd
.
Command
=
fmt
.
Sprintf
(
"chmod +x %s && %s"
,
p
.
config
.
RemotePath
,
p
.
config
.
RemotePath
)
cmd
.
Command
=
command
.
String
(
)
cmd
.
Stdout
=
stdout_w
cmd
.
Stdout
=
stdout_w
cmd
.
Stderr
=
stderr_w
cmd
.
Stderr
=
stderr_w
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment