Skip to content

Commit

Permalink
Finished testing
Browse files Browse the repository at this point in the history
  • Loading branch information
suhay committed Nov 28, 2021
1 parent c735aaa commit 36ca4e6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ sandwich-shop
.env
.node1.env
.key
shop/shop
gowich
sandwiches/gowich/gowich
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.PHONY: shop

gqlgen:
go run github.com/99designs/gqlgen

Expand All @@ -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
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions orders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
hello:
runtime: go1_17
path: hello.go
4 changes: 4 additions & 0 deletions sandwiches/gowich/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: gowich

gowich:
go build
12 changes: 2 additions & 10 deletions sandwiches/gowich/gowich.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
1 change: 0 additions & 1 deletion tenants/b78682b3-36c8-4759-b8d1-5e62f029a1bc/orders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tenants/myFunctions/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main
import "fmt"
func main() {
fmt.Printf("%s", "Hello!")
}
4 changes: 4 additions & 0 deletions tenants/myFunctions/orders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
hello:
runtime: go1_17
path: hello.go

0 comments on commit 36ca4e6

Please sign in to comment.