Fix run env vars passed in via command line to test locally and updated docs to match.

This commit is contained in:
Travis Reeder
2017-05-30 10:54:34 -07:00
committed by Reed Allman
parent 7b408468fa
commit af918fdfe9
14 changed files with 79 additions and 41 deletions

View File

@@ -45,7 +45,6 @@ func (b *buildcmd) build(c *cli.Context) error {
return err
}
fmt.Fprintln(verbwriter, "building", fn)
ff, err := buildfunc(verbwriter, fn)
if err != nil {
return err

View File

@@ -96,7 +96,10 @@ func dockerbuild(verbwriter io.Writer, path string, ff *funcfile) error {
}
fmt.Printf("Building image %v\n", ff.FullName())
cmd := exec.Command("docker", "build", "-t", ff.FullName(), ".")
cmd := exec.Command("docker", "build",
"-t", ff.FullName(),
"--build-arg", "HTTP_PROXY",
".")
cmd.Dir = dir
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
@@ -206,6 +209,7 @@ func extractEnvConfig(configs []string) map[string]string {
}
func dockerpush(ff *funcfile) error {
fmt.Println("Pushing to docker registry...")
cmd := exec.Command("docker", "push", ff.FullName())
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

View File

@@ -4,12 +4,12 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path"
"path/filepath"
"time"
"github.com/Sirupsen/logrus"
functions "github.com/iron-io/functions_go"
"github.com/iron-io/functions_go/models"
"github.com/urfave/cli"
@@ -76,9 +76,8 @@ func (p *deploycmd) scan(c *cli.Context) error {
var walked bool
wd, err := os.Getwd()
if err != nil {
logrus.Fatalln("Couldn't get current directory:", err)
log.Fatalln("Couldn't get working directory:", err)
}
// logrus.Infoln("wd:", wd)
err = filepath.Walk(wd, func(path string, info os.FileInfo, err error) error {
if path != wd && info.IsDir() {
@@ -134,7 +133,6 @@ func (p *deploycmd) deploy(c *cli.Context, funcFilePath string) error {
dirName := "/" + path.Base(path.Dir(funcFilePath))
funcfile.Path = &dirName
}
logrus.Infof("funcfile %+v", funcfile)
if p.skippush {
return nil
@@ -148,6 +146,7 @@ func (p *deploycmd) deploy(c *cli.Context, funcFilePath string) error {
}
func (p *deploycmd) route(c *cli.Context, ff *funcfile) error {
fmt.Printf("Updating route, setting %s -> %s...", ff.Path, ff.Name)
if err := resetBasePath(p.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

View File

@@ -63,14 +63,11 @@ func (r *runCmd) run(c *cli.Context) error {
return runff(image, stdin(), os.Stdout, os.Stderr, c.String("method"), c.StringSlice("e"), c.StringSlice("link"))
}
func runff(image string, stdin io.Reader, stdout, stderr io.Writer, method string, restrictedEnv []string, links []string) error {
func runff(image string, stdin io.Reader, stdout, stderr io.Writer, method string, envVars []string, links []string) error {
sh := []string{"docker", "run", "--rm", "-i"}
var env []string
detectedEnv := os.Environ()
if len(restrictedEnv) > 0 {
detectedEnv = restrictedEnv
}
var env []string // env for the shelled out docker run command
var runEnv []string // env to pass into the container via -e's
if method == "" {
if stdin == nil {
@@ -79,13 +76,13 @@ func runff(image string, stdin io.Reader, stdout, stderr io.Writer, method strin
method = "POST"
}
}
sh = append(sh, "-e", kvEq("METHOD", method))
for _, e := range detectedEnv {
shellvar, envvar := extractEnvVar(e)
sh = append(sh, shellvar...)
env = append(env, envvar)
}
// Add expected env vars that service will add
runEnv = append(runEnv, kvEq("METHOD", method))
runEnv = append(runEnv, kvEq("REQUEST_URL", "http://localhost:8080/myapp/hello"))
runEnv = append(runEnv, kvEq("APP_NAME", "myapp"))
runEnv = append(runEnv, kvEq("ROUTE", "/hello"))
// add user defined envs
runEnv = append(runEnv, envVars...)
for _, l := range links {
sh = append(sh, "--link", l)
@@ -96,12 +93,16 @@ func runff(image string, stdin io.Reader, stdout, stderr io.Writer, method strin
env = append(env, fmt.Sprint(e, "=", os.Getenv(e)))
}
for _, e := range runEnv {
sh = append(sh, "-e", e)
}
sh = append(sh, image)
cmd := exec.Command(sh[0], sh[1:]...)
cmd.Stdin = stdin
cmd.Stdout = stdout
cmd.Stderr = stderr
cmd.Env = env
// cmd.Env = env
return cmd.Run()
}