--- a/docker/run.go Tue Sep 05 20:15:28 2017 -0500
+++ b/docker/run.go Tue Sep 05 20:41:11 2017 -0500
@@ -73,6 +73,53 @@
{{range .Environment}} -e {{.}}{{end}}
{{.Image}}{{if .Command}} {{.Command}}{{end}}`
+// buildScript will create a shell script for the given commands +func (r *Run) buildScript(fullEnv []string) (string, string, string, error) { + // figure out the current working directory + // now get the absolute path + absPwd, err := filepath.Abs(pwd) + // create the temp file to write the script to + script, err := ioutil.TempFile(absPwd, "convey-script-") + // set scriptFile to the name of the temp file + scriptFile := script.Name() + // set the run command argument to the script file + commandArg := scriptFile + // iterate the script and run the environment variable exapansion on each line + for idx, item := range r.Script { + r.Script[idx] = environment.Mapper(item, fullEnv) + // write the script to the file + script.WriteString(strings.Join(r.Script, "\n")) + // make the script executable to the user + os.Chmod(scriptFile, 0700) + return scriptFile, entryPoint, commandArg, nil func (r *Run) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, r.Environment)
fullEnv = environment.Merge(fullEnv, st.Environment)
@@ -101,49 +148,13 @@
// if we're using a script defined in the yaml, create it and override
- // figure out the current working directory
- // now get the absolute path
- absPwd, err := filepath.Abs(pwd)
+ scriptFile, entryPoint, commandArg, err = r.buildScript(fullEnv) - // create the temp file to write the script to
- script, err := ioutil.TempFile(absPwd, "convey-script-")
- // set scriptFile to the name of the temp file
- scriptFile = script.Name()
- // set the run command argument to the script file
- commandArg = scriptFile
// remove the file when the function exits
defer os.Remove(scriptFile)
- // iterate the script and run the environment variable exapansion on each line
- for idx, item := range r.Script {
- r.Script[idx] = environment.Mapper(item, fullEnv)
- // write the script to the file
- script.WriteString(strings.Join(r.Script, "\n"))
- // make the script executable to the user
- os.Chmod(scriptFile, 0700)
// build the dict for the template