From 5370bc86fa056ca4d085083e058f09dceee26227 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Thu, 20 Jul 2017 16:35:07 -0700 Subject: [PATCH 01/11] Added Go boilerplate --- cli/langs/go.go | 87 ++++++++++++++++++++++++++++++ examples/tutorial/hello/go/func.go | 1 - 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/cli/langs/go.go b/cli/langs/go.go index 264ea80cc..e74f2f368 100644 --- a/cli/langs/go.go +++ b/cli/langs/go.go @@ -1,5 +1,11 @@ package langs +import ( + "io/ioutil" + "os" + "path/filepath" +) + type GoLangHelper struct { BaseHelper } @@ -38,3 +44,84 @@ func (h *GoLangHelper) DockerfileCopyCmds() []string { func (lh *GoLangHelper) Entrypoint() string { return "./func" } + +// HasPreBuild returns whether the Java runtime has boilerplate that can be generated. +func (lh *GoLangHelper) HasBoilerplate() bool { return true } + +// GenerateBoilerplate will generate function boilerplate for a Java runtime. The default boilerplate is for a Maven +// project. +func (lh *GoLangHelper) GenerateBoilerplate() error { + wd, err := os.Getwd() + if err != nil { + return err + } + codeFile := filepath.Join(wd, "func.go") + if exists(codeFile) { + return ErrBoilerplateExists + } + testFile := filepath.Join(wd, "test.json") + if exists(testFile) { + return ErrBoilerplateExists + } + + if err := ioutil.WriteFile(codeFile, []byte(helloGoSrcBoilerplate), os.FileMode(0644)); err != nil { + return err + } + + if err := ioutil.WriteFile(testFile, []byte(testBoilerPlate), os.FileMode(0644)); err != nil { + return err + } + return nil +} + +const ( + helloGoSrcBoilerplate = `package main + +import ( + "encoding/json" + "fmt" + "os" +) + +type Person struct { + Name string +} + +func main() { + p := &Person{Name: "World"} + json.NewDecoder(os.Stdin).Decode(p) + mapD := map[string]string{"message": fmt.Sprintf("Hello %s", p.Name)} + mapB, _ := json.Marshal(mapD) + fmt.Println(string(mapB)) +} +` + + // Could use same test for most langs + testBoilerPlate = `{ + "tests": [ + { + "input": { + "body": { + "name": "Johnny" + } + }, + "output": { + "body": { + "message": "Hello Johnny" + } + } + }, + { + "input": { + "body": "" + }, + "output": { + "body": { + "message": "Hello World" + } + } + } + ] +} +` +) diff --git a/examples/tutorial/hello/go/func.go b/examples/tutorial/hello/go/func.go index adaac4144..c1f3f8401 100644 --- a/examples/tutorial/hello/go/func.go +++ b/examples/tutorial/hello/go/func.go @@ -14,7 +14,6 @@ type Person struct { func main() { p := &Person{Name: "World"} json.NewDecoder(os.Stdin).Decode(p) - // fmt.Printf("Hello %v!\n", p.Name) mapD := map[string]string{"message": fmt.Sprintf("Hello %s", p.Name)} mapB, _ := json.Marshal(mapD) fmt.Println(string(mapB)) From 2d4d1591ab5d36f6f0e34c1555e0d4ebcccc6653 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Thu, 20 Jul 2017 17:22:07 -0700 Subject: [PATCH 02/11] Runs through the common `fn` commands to ensure we don't break em. --- cli/client/call_fn.go | 5 ++ fn/.gitignore | 6 ++ fn/Makefile | 29 ++++++++ fn/main.go | 152 ++++++++++++++++++++++++++++++++++++++++++ fn/test.sh | 25 +++++++ 5 files changed, 217 insertions(+) create mode 100644 fn/.gitignore create mode 100644 fn/Makefile create mode 100644 fn/main.go create mode 100755 fn/test.sh diff --git a/cli/client/call_fn.go b/cli/client/call_fn.go index 4bd4d0315..3b9bfe7b0 100644 --- a/cli/client/call_fn.go +++ b/cli/client/call_fn.go @@ -48,5 +48,10 @@ func CallFN(u string, content io.Reader, output io.Writer, method string, env [] io.Copy(output, resp.Body) + if resp.StatusCode >= 400 { + // TODO: parse out error message + return fmt.Errorf("error calling function: status %v", resp.StatusCode) + } + return nil } diff --git a/fn/.gitignore b/fn/.gitignore new file mode 100644 index 000000000..f4e62805c --- /dev/null +++ b/fn/.gitignore @@ -0,0 +1,6 @@ +/fn.exe +/fn_linux +/fn_mac +/fn +/fn_alpine +/tmp diff --git a/fn/Makefile b/fn/Makefile new file mode 100644 index 000000000..53c6ce053 --- /dev/null +++ b/fn/Makefile @@ -0,0 +1,29 @@ +all: vendor build + ./fn + +build: + go build -o fn + +docker: vendor + GOOS=linux go build -o fn + docker build -t treeder/fn . + docker push treeder/fn + +dep: + glide install -v + +dep-up: + glide up -v + +test: + go test $(go list ./... | grep -v /vendor/ | grep -v /tests) + ./test.sh + +test-integration: + cd tests/ && go test -v ./...; cd .. + +release: + GOOS=linux go build -o fn_linux + GOOS=darwin go build -o fn_mac + GOOS=windows go build -o fn.exe + docker run --rm -v ${PWD}:/go/src/gitlab-odx.oracle.com/odx/functions/fn -w /go/src/gitlab-odx.oracle.com/odx/functions/fn funcy/go:dev go build -o fn_alpine diff --git a/fn/main.go b/fn/main.go new file mode 100644 index 000000000..6d5919e05 --- /dev/null +++ b/fn/main.go @@ -0,0 +1,152 @@ +package main + +import ( + "bytes" + "fmt" + "net/url" + "os" + "strings" + + functions "github.com/funcy/functions_go" + "github.com/urfave/cli" +) + +var aliases = map[string]cli.Command{ + "build": build(), + "bump": bump(), + "deploy": deploy(), + "push": push(), + "run": run(), + "call": call(), + "calls": calls(), +} + +func aliasesFn() []cli.Command { + cmds := []cli.Command{} + for alias, cmd := range aliases { + cmd.Name = alias + cmd.Hidden = true + cmds = append(cmds, cmd) + } + return cmds +} + +func newFn() *cli.App { + app := cli.NewApp() + app.Name = "fn" + app.Version = Version + app.Authors = []cli.Author{{Name: "Oracle Corporation"}} + app.Description = "Oracle Functions command line tools" + app.UsageText = `Check the manual at https://gitlab-odx.oracle.com/odx/functions/blob/master/fn/README.md` + + cli.AppHelpTemplate = `{{.Name}} {{.Version}}{{if .Description}} + +{{.Description}}{{end}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} + +ENVIRONMENT VARIABLES: + API_URL - Oracle Functions remote API address{{if .VisibleCommands}} + +COMMANDS:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{end}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + +ALIASES: + build (images build) + bump (images bump) + deploy (images deploy) + run (images run) + call (routes call) + push (images push) + +GLOBAL OPTIONS: + {{range $index, $option := .VisibleFlags}}{{if $index}} + {{end}}{{$option}}{{end}}{{end}} +` + + app.CommandNotFound = func(c *cli.Context, cmd string) { + fmt.Fprintf(os.Stderr, "command not found: %v\n", cmd) + } + app.Commands = []cli.Command{ + startCmd(), + updateCmd(), + initFn(), + apps(), + routes(), + images(), + lambda(), + version(), + calls(), + testfn(), + } + app.Commands = append(app.Commands, aliasesFn()...) + + prepareCmdArgsValidation(app.Commands) + + return app +} + +func parseArgs(c *cli.Context) ([]string, []string) { + args := strings.Split(c.Command.ArgsUsage, " ") + var reqArgs []string + var optArgs []string + for _, arg := range args { + if strings.HasPrefix(arg, "[") { + optArgs = append(optArgs, arg) + } else if strings.Trim(arg, " ") != "" { + reqArgs = append(reqArgs, arg) + } + } + return reqArgs, optArgs +} + +func prepareCmdArgsValidation(cmds []cli.Command) { + // TODO: refactor fn to use urfave/cli.v2 + // v1 doesn't let us validate args before the cmd.Action + + for i, cmd := range cmds { + prepareCmdArgsValidation(cmd.Subcommands) + if cmd.Action == nil { + continue + } + action := cmd.Action + cmd.Action = func(c *cli.Context) error { + reqArgs, _ := parseArgs(c) + if c.NArg() < len(reqArgs) { + var help bytes.Buffer + cli.HelpPrinter(&help, cli.CommandHelpTemplate, c.Command) + return fmt.Errorf("ERROR: Missing required arguments: %s\n\n%s", strings.Join(reqArgs[c.NArg():], " "), help.String()) + } + return cli.HandleAction(action, c) + } + cmds[i] = cmd + } +} + +func main() { + app := newFn() + err := app.Run(os.Args) + if err != nil { + // TODO: this doesn't seem to get called even when an error returns from a command, but maybe urfave is doing a non zero exit anyways + fmt.Printf("Error occurred: %v, exiting...\n", err) + os.Exit(1) + } +} + +func resetBasePath(c *functions.Configuration) error { + apiURL := os.Getenv("API_URL") + if apiURL == "" { + apiURL = "http://localhost:8080" + } + + u, err := url.Parse(apiURL) + if err != nil { + return err + } + u.Path = "/v1" + c.BasePath = u.String() + + return nil +} diff --git a/fn/test.sh b/fn/test.sh new file mode 100755 index 000000000..157d9c47d --- /dev/null +++ b/fn/test.sh @@ -0,0 +1,25 @@ +set -ex + +make build +export fn="$(pwd)/fn" +$fn --version + +# This tests all the quickstart commands on the cli on a live server +rm -rf tmp +mkdir tmp +cd tmp +$fn init --runtime go $DOCKER_USER/fn-test-go +$fn test + +docker rm --force functions || true # just in case +docker run --name functions -d -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 funcy/functions + +sleep 10 +$fn apps l +$fn apps create myapp +$fn deploy myapp +$fn call myapp /fn-test-go3 + +docker rm --force functions + +cd .. From 3df557fecc868cf74fc93b11cbae6e9a47993d4f Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Fri, 21 Jul 2017 15:06:21 -0700 Subject: [PATCH 03/11] changed docker_user to docker_username --- circle.yml | 2 +- fn/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 22f2bf84e..77412ed8e 100644 --- a/circle.yml +++ b/circle.yml @@ -45,5 +45,5 @@ deployment: commands: - git config --global user.email "treeder+circle@gmail.com" - git config --global user.name "CircleCI" - - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS + - docker login -e $DOCKER_EMAIL -u $DOCKER_USERNAME -p $DOCKER_PASS - cd $GO_PROJECT && ./release.sh diff --git a/fn/test.sh b/fn/test.sh index 157d9c47d..b4e74d60f 100755 --- a/fn/test.sh +++ b/fn/test.sh @@ -8,7 +8,7 @@ $fn --version rm -rf tmp mkdir tmp cd tmp -$fn init --runtime go $DOCKER_USER/fn-test-go +$fn init --runtime go $DOCKER_USERNAME/fn-test-go $fn test docker rm --force functions || true # just in case From 1adb800ce1e92d5c6ab5926a7e93fbf11b968341 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Tue, 25 Jul 2017 09:14:35 -0700 Subject: [PATCH 04/11] Changed port and testing to see that build will fail on fn commands. --- fn/test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fn/test.sh b/fn/test.sh index b4e74d60f..869e9c989 100755 --- a/fn/test.sh +++ b/fn/test.sh @@ -8,17 +8,20 @@ $fn --version rm -rf tmp mkdir tmp cd tmp -$fn init --runtime go $DOCKER_USERNAME/fn-test-go +funcname="tn-test-go" +$fn init --runtime go $DOCKER_USERNAME/$funcname $fn test +someport=50080 docker rm --force functions || true # just in case -docker run --name functions -d -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 funcy/functions +docker run --name functions -d -v /var/run/docker.sock:/var/run/docker.sock -p $someport:8080 funcy/functions sleep 10 +export API_URL="http://localhost:$someport" $fn apps l $fn apps create myapp $fn deploy myapp -$fn call myapp /fn-test-go3 +$fn call myapp $DOCKER_USERNAME/$funcname docker rm --force functions From 59b8f767236a457196c93a4ece72fedd402da6d5 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Tue, 25 Jul 2017 09:33:17 -0700 Subject: [PATCH 05/11] Added docker:dind as a gitlab service. --- .gitlab-ci.yml | 9 ++++++--- fn/Makefile | 1 - fn/test.sh | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 06503083e..474ae56e5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,7 @@ -image: funcy/go-dind:latest +image: docker:latest + +services: + - docker:dind cache: key: "$CI_COMMIT_REF_NAME" @@ -18,13 +21,13 @@ before_script: build_job: stage: build script: - - go build -o functions-alpine + - make docker-build build_job_fn: stage: build script: - cd fn - - go build -o fn-alpine + - make build formatting: stage: build diff --git a/fn/Makefile b/fn/Makefile index 53c6ce053..db63d651d 100644 --- a/fn/Makefile +++ b/fn/Makefile @@ -16,7 +16,6 @@ dep-up: glide up -v test: - go test $(go list ./... | grep -v /vendor/ | grep -v /tests) ./test.sh test-integration: diff --git a/fn/test.sh b/fn/test.sh index 869e9c989..671bc7837 100755 --- a/fn/test.sh +++ b/fn/test.sh @@ -4,11 +4,13 @@ make build export fn="$(pwd)/fn" $fn --version +go test $(go list ./... | grep -v /vendor/ | grep -v /tests) + # This tests all the quickstart commands on the cli on a live server rm -rf tmp mkdir tmp cd tmp -funcname="tn-test-go" +funcname="fn-test-go" $fn init --runtime go $DOCKER_USERNAME/$funcname $fn test @@ -20,8 +22,9 @@ sleep 10 export API_URL="http://localhost:$someport" $fn apps l $fn apps create myapp +$fn apps l $fn deploy myapp -$fn call myapp $DOCKER_USERNAME/$funcname +$fn call myapp $funcname docker rm --force functions From 1bda8c515a58f0a3c312ea958899bb94ce6f646a Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Tue, 25 Jul 2017 09:51:55 -0700 Subject: [PATCH 06/11] debugging... --- .gitlab-ci.yml | 5 +---- fn/test.sh | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 474ae56e5..2d4a3ae8d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,4 @@ -image: docker:latest - -services: - - docker:dind +image: funcy/go-dind:latest cache: key: "$CI_COMMIT_REF_NAME" diff --git a/fn/test.sh b/fn/test.sh index 671bc7837..480aa1671 100755 --- a/fn/test.sh +++ b/fn/test.sh @@ -17,8 +17,9 @@ $fn test someport=50080 docker rm --force functions || true # just in case docker run --name functions -d -v /var/run/docker.sock:/var/run/docker.sock -p $someport:8080 funcy/functions - sleep 10 +docker logs functions + export API_URL="http://localhost:$someport" $fn apps l $fn apps create myapp From 921a323645e56e61179df0986830f5daa9f3b3b3 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Tue, 25 Jul 2017 09:54:52 -0700 Subject: [PATCH 07/11] Debugging --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d4a3ae8d..15141eb83 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,7 @@ before_script: build_job: stage: build script: - - make docker-build + - make build build_job_fn: stage: build From f1fefe432e0a3ab0c4b58c99d9d6698bf8cbab5d Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Mon, 31 Jul 2017 16:43:48 -0700 Subject: [PATCH 08/11] rebased on master --- cli/Makefile | 2 +- cli/main.go | 11 +++- {fn => cli}/test.sh | 0 fn/.gitignore | 6 -- fn/Makefile | 28 -------- fn/main.go | 152 -------------------------------------------- 6 files changed, 9 insertions(+), 190 deletions(-) rename {fn => cli}/test.sh (100%) delete mode 100644 fn/.gitignore delete mode 100644 fn/Makefile delete mode 100644 fn/main.go diff --git a/cli/Makefile b/cli/Makefile index 40440f1db..981383638 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -16,7 +16,7 @@ dep-up: glide up -v test: - go test $(go list ./... | grep -v /vendor/ | grep -v /tests) + ./test.sh test-integration: cd tests/ && go test -v ./...; cd .. diff --git a/cli/main.go b/cli/main.go index 3d97eadfd..396e94feb 100644 --- a/cli/main.go +++ b/cli/main.go @@ -36,8 +36,8 @@ func newFn() *cli.App { app.Name = "fn" app.Version = Version app.Authors = []cli.Author{{Name: "Oracle Corporation"}} - app.Description = "Oracle Functions command line tools" - app.UsageText = `Check the manual at https://github.com/fnproject/fn/blob/master/fn/README.md` + app.Description = "Fn command line tool" + app.UsageText = `Check the docs at https://github.com/fnproject/fn/blob/master/fn/README.md` cli.AppHelpTemplate = `{{.Name}} {{.Version}}{{if .Description}} @@ -127,7 +127,12 @@ func prepareCmdArgsValidation(cmds []cli.Command) { func main() { app := newFn() - app.Run(os.Args) + err := app.Run(os.Args) + if err != nil { + // TODO: this doesn't seem to get called even when an error returns from a command, but maybe urfave is doing a non zero exit anyways? nope: https://github.com/urfave/cli/issues/610 + fmt.Printf("Error occurred: %v, exiting...\n", err) + os.Exit(1) + } } func resetBasePath(c *functions.Configuration) error { diff --git a/fn/test.sh b/cli/test.sh similarity index 100% rename from fn/test.sh rename to cli/test.sh diff --git a/fn/.gitignore b/fn/.gitignore deleted file mode 100644 index f4e62805c..000000000 --- a/fn/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/fn.exe -/fn_linux -/fn_mac -/fn -/fn_alpine -/tmp diff --git a/fn/Makefile b/fn/Makefile deleted file mode 100644 index db63d651d..000000000 --- a/fn/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -all: vendor build - ./fn - -build: - go build -o fn - -docker: vendor - GOOS=linux go build -o fn - docker build -t treeder/fn . - docker push treeder/fn - -dep: - glide install -v - -dep-up: - glide up -v - -test: - ./test.sh - -test-integration: - cd tests/ && go test -v ./...; cd .. - -release: - GOOS=linux go build -o fn_linux - GOOS=darwin go build -o fn_mac - GOOS=windows go build -o fn.exe - docker run --rm -v ${PWD}:/go/src/gitlab-odx.oracle.com/odx/functions/fn -w /go/src/gitlab-odx.oracle.com/odx/functions/fn funcy/go:dev go build -o fn_alpine diff --git a/fn/main.go b/fn/main.go deleted file mode 100644 index 6d5919e05..000000000 --- a/fn/main.go +++ /dev/null @@ -1,152 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "net/url" - "os" - "strings" - - functions "github.com/funcy/functions_go" - "github.com/urfave/cli" -) - -var aliases = map[string]cli.Command{ - "build": build(), - "bump": bump(), - "deploy": deploy(), - "push": push(), - "run": run(), - "call": call(), - "calls": calls(), -} - -func aliasesFn() []cli.Command { - cmds := []cli.Command{} - for alias, cmd := range aliases { - cmd.Name = alias - cmd.Hidden = true - cmds = append(cmds, cmd) - } - return cmds -} - -func newFn() *cli.App { - app := cli.NewApp() - app.Name = "fn" - app.Version = Version - app.Authors = []cli.Author{{Name: "Oracle Corporation"}} - app.Description = "Oracle Functions command line tools" - app.UsageText = `Check the manual at https://gitlab-odx.oracle.com/odx/functions/blob/master/fn/README.md` - - cli.AppHelpTemplate = `{{.Name}} {{.Version}}{{if .Description}} - -{{.Description}}{{end}} - -USAGE: - {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} - -ENVIRONMENT VARIABLES: - API_URL - Oracle Functions remote API address{{if .VisibleCommands}} - -COMMANDS:{{range .VisibleCategories}}{{if .Name}} - {{.Name}}:{{end}}{{range .VisibleCommands}} - {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} - -ALIASES: - build (images build) - bump (images bump) - deploy (images deploy) - run (images run) - call (routes call) - push (images push) - -GLOBAL OPTIONS: - {{range $index, $option := .VisibleFlags}}{{if $index}} - {{end}}{{$option}}{{end}}{{end}} -` - - app.CommandNotFound = func(c *cli.Context, cmd string) { - fmt.Fprintf(os.Stderr, "command not found: %v\n", cmd) - } - app.Commands = []cli.Command{ - startCmd(), - updateCmd(), - initFn(), - apps(), - routes(), - images(), - lambda(), - version(), - calls(), - testfn(), - } - app.Commands = append(app.Commands, aliasesFn()...) - - prepareCmdArgsValidation(app.Commands) - - return app -} - -func parseArgs(c *cli.Context) ([]string, []string) { - args := strings.Split(c.Command.ArgsUsage, " ") - var reqArgs []string - var optArgs []string - for _, arg := range args { - if strings.HasPrefix(arg, "[") { - optArgs = append(optArgs, arg) - } else if strings.Trim(arg, " ") != "" { - reqArgs = append(reqArgs, arg) - } - } - return reqArgs, optArgs -} - -func prepareCmdArgsValidation(cmds []cli.Command) { - // TODO: refactor fn to use urfave/cli.v2 - // v1 doesn't let us validate args before the cmd.Action - - for i, cmd := range cmds { - prepareCmdArgsValidation(cmd.Subcommands) - if cmd.Action == nil { - continue - } - action := cmd.Action - cmd.Action = func(c *cli.Context) error { - reqArgs, _ := parseArgs(c) - if c.NArg() < len(reqArgs) { - var help bytes.Buffer - cli.HelpPrinter(&help, cli.CommandHelpTemplate, c.Command) - return fmt.Errorf("ERROR: Missing required arguments: %s\n\n%s", strings.Join(reqArgs[c.NArg():], " "), help.String()) - } - return cli.HandleAction(action, c) - } - cmds[i] = cmd - } -} - -func main() { - app := newFn() - err := app.Run(os.Args) - if err != nil { - // TODO: this doesn't seem to get called even when an error returns from a command, but maybe urfave is doing a non zero exit anyways - fmt.Printf("Error occurred: %v, exiting...\n", err) - os.Exit(1) - } -} - -func resetBasePath(c *functions.Configuration) error { - apiURL := os.Getenv("API_URL") - if apiURL == "" { - apiURL = "http://localhost:8080" - } - - u, err := url.Parse(apiURL) - if err != nil { - return err - } - u.Path = "/v1" - c.BasePath = u.String() - - return nil -} From fdfc11bd14309989749aa852bce4bac633ebc664 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Mon, 31 Jul 2017 17:42:12 -0700 Subject: [PATCH 09/11] Updated env var name --- cli/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/test.sh b/cli/test.sh index 480aa1671..5291f4e2d 100755 --- a/cli/test.sh +++ b/cli/test.sh @@ -11,7 +11,7 @@ rm -rf tmp mkdir tmp cd tmp funcname="fn-test-go" -$fn init --runtime go $DOCKER_USERNAME/$funcname +$fn init --runtime go $DOCKER_USER/$funcname $fn test someport=50080 From 8f81ff7b56b19ddb636f97a59a3ba357e2d97b98 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Thu, 3 Aug 2017 08:09:44 -0700 Subject: [PATCH 10/11] Updated circle --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 77412ed8e..22f2bf84e 100644 --- a/circle.yml +++ b/circle.yml @@ -45,5 +45,5 @@ deployment: commands: - git config --global user.email "treeder+circle@gmail.com" - git config --global user.name "CircleCI" - - docker login -e $DOCKER_EMAIL -u $DOCKER_USERNAME -p $DOCKER_PASS + - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS - cd $GO_PROJECT && ./release.sh From 95dc8bc4ed2443b88c4727fcf7b99a1d27ee2601 Mon Sep 17 00:00:00 2001 From: Travis Reeder Date: Thu, 3 Aug 2017 10:12:29 -0700 Subject: [PATCH 11/11] docker login earlier --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 409f872a4..30a3261ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,6 +29,8 @@ jobs: sudo service docker stop curl -fsSL https://get.docker.com/ | sudo sh - run: docker version + # login here for tests + - run: docker login -u $DOCKER_USER -p $DOCKER_PASS - run: ./test.sh - deploy: command: | @@ -36,6 +38,5 @@ jobs: git config --global user.email "ci@fnproject.com" git config --global user.name "CI" git branch --set-upstream-to=origin/${CIRCLE_BRANCH} ${CIRCLE_BRANCH} - docker login -u $DOCKER_USER -p $DOCKER_PASS ./release.sh fi