provisioner/shell: Start working on shell provisioner
This commit is contained in:
parent
81d8b20730
commit
f726ea2800
|
@ -3,11 +3,20 @@
|
|||
package shell
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
const DefaultRemotePath = "/tmp/script.sh"
|
||||
|
||||
// TODO(mitchellh): config
|
||||
type config struct {
|
||||
// The local path of the shell script to upload and execute.
|
||||
Path string
|
||||
|
||||
// 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.
|
||||
RemotePath string
|
||||
}
|
||||
|
||||
type Provisioner struct {
|
||||
|
@ -15,6 +24,12 @@ type Provisioner struct {
|
|||
}
|
||||
|
||||
func (p *Provisioner) Prepare(raw interface{}, ui packer.Ui) {
|
||||
// TODO: errors
|
||||
_ = mapstructure.Decode(raw, &p.config)
|
||||
|
||||
if p.config.RemotePath == "" {
|
||||
p.config.RemotePath = DefaultRemotePath
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
|
||||
|
|
|
@ -13,3 +13,13 @@ func TestProvisioner_Impl(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProvisionerPrepare_Defaults(t *testing.T) {
|
||||
raw := map[string]interface{} {}
|
||||
|
||||
p := &Provisioner{}
|
||||
p.Prepare(raw, nil)
|
||||
|
||||
if p.config.RemotePath != DefaultRemotePath {
|
||||
t.Errorf("unexpected remote path: %s", p.config.RemotePath)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue