From 36ca4e6484e8af178a98ad1b48bf028018bb6482 Mon Sep 17 00:00:00 2001 From: Matt Suhay Date: Sun, 28 Nov 2021 16:15:25 -0600 Subject: [PATCH] Finished testing --- .gitignore | 3 +-- Makefile | 10 +++++++++- docker-compose.yml | 8 ++++---- orders.yml | 4 ++++ sandwiches/gowich/Makefile | 4 ++++ sandwiches/gowich/gowich.go | 12 ++---------- .../b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml | 1 - tenants/myFunctions/hello.go | 5 +++++ tenants/myFunctions/orders.yml | 4 ++++ 9 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 orders.yml create mode 100644 sandwiches/gowich/Makefile create mode 100644 tenants/myFunctions/hello.go create mode 100644 tenants/myFunctions/orders.yml diff --git a/.gitignore b/.gitignore index f78b491..cfab572 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,4 @@ sandwich-shop .env .node1.env .key -shop/shop -gowich +sandwiches/gowich/gowich diff --git a/Makefile b/Makefile index 4f96af1..b1e3446 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: shop + gqlgen: go run github.com/99designs/gqlgen @@ -7,6 +9,12 @@ generate: dev: MODE=DEV CompileDaemon -directory=./ -color=true -command="./sandwich-shop" -build: +all: go build cd sandwiches/gowich; go build + +shop: + go build + +gowich: + cd sandwiches/gowich; go build \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 37514b5..aed3e37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,11 +8,9 @@ services: volumes: - .:/code working_dir: /code - command: "./sandwich-shop" + command: ["sh", "-c", "make shop && ./sandwich-shop"] environment: - MODE=DEV - links: - - "gowich" gowich: image: golang:1.17 @@ -21,4 +19,6 @@ services: volumes: - .:/code working_dir: /code/sandwiches/gowich - command: "./gowich --env /code/.node1.env --port 4007" + command: ["sh", "-c", "make gowich && ./gowich --env /code/.node1.env --port 4007"] + depends_on: + - shop diff --git a/orders.yml b/orders.yml new file mode 100644 index 0000000..e5888c5 --- /dev/null +++ b/orders.yml @@ -0,0 +1,4 @@ +--- +hello: + runtime: go1_17 + path: hello.go \ No newline at end of file diff --git a/sandwiches/gowich/Makefile b/sandwiches/gowich/Makefile new file mode 100644 index 0000000..fad395f --- /dev/null +++ b/sandwiches/gowich/Makefile @@ -0,0 +1,4 @@ +.PHONY: gowich + +gowich: + go build \ No newline at end of file diff --git a/sandwiches/gowich/gowich.go b/sandwiches/gowich/gowich.go index 384b798..b48c2ab 100644 --- a/sandwiches/gowich/gowich.go +++ b/sandwiches/gowich/gowich.go @@ -118,9 +118,6 @@ func main() { order := chi.URLParam(r, "order") out, err := placeOrder(order, claims, body, header) - log.Println(out) - log.Println(err) - if err != nil { log.Println(err.Error()) http.Error(w, http.StatusText(500), 500) @@ -155,13 +152,13 @@ func placeOrder(order string, claims *order, body string, header string) (string name := os.Getenv(runtime) if strings.HasPrefix(runtime, "GO") { - cmd = exec.Command(name, "run", "/code/tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/make_sandwich.go", body, header) + cmd = exec.Command(name, "run", order, body, header) } else { cmd = exec.Command(name, order, body, header) } } - if len(claims.Env) > 0 { + if claims.Env != "[]" && len(claims.Env) > 0 { env := []string{} json.Unmarshal([]byte(claims.Env), &env) cmd.Env = env @@ -174,9 +171,6 @@ func placeOrder(order string, claims *order, body string, header string) (string cmd.Dir = tenants + "/" + claims.Tenant - log.Println(os.Getwd()) - log.Println(cmd) - // cmd.SysProcAttr = &syscall.SysProcAttr{} // uid, uerr := strconv.ParseUint(os.Getenv("UID"), 10, 32) @@ -196,7 +190,5 @@ func placeOrder(order string, claims *order, body string, header string) (string // hold := &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)} out, err := cmd.Output() - log.Println(out) - log.Println(err) return strings.TrimSpace(string(out)), err } diff --git a/tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml b/tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml index db8b9dc..3493e0b 100644 --- a/tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml +++ b/tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml @@ -6,4 +6,3 @@ getSandwich: # order name makeSandwich: # order name runtime: go1_17 # sandwich type to make path: make_sandwich.go # path where function lives - env: [] # any variables to include diff --git a/tenants/myFunctions/hello.go b/tenants/myFunctions/hello.go new file mode 100644 index 0000000..2428bcd --- /dev/null +++ b/tenants/myFunctions/hello.go @@ -0,0 +1,5 @@ +package main +import "fmt" +func main() { +fmt.Printf("%s", "Hello!") +} \ No newline at end of file diff --git a/tenants/myFunctions/orders.yml b/tenants/myFunctions/orders.yml new file mode 100644 index 0000000..42c484b --- /dev/null +++ b/tenants/myFunctions/orders.yml @@ -0,0 +1,4 @@ +--- +hello: + runtime: go1_17 + path: hello.go