From 85af935988c10839dcf363755b5b73f18cff605e Mon Sep 17 00:00:00 2001 From: Kevin Mingtarja Date: Wed, 20 Dec 2023 02:16:20 +0800 Subject: [PATCH 1/2] create dockerfile --- hmruntime/Dockerfile | 25 +++++++++++++++++++++++++ hmruntime/README.md | 3 +++ hmruntime/dgraph.go | 4 ++-- hmruntime/main.go | 3 +++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 hmruntime/Dockerfile diff --git a/hmruntime/Dockerfile b/hmruntime/Dockerfile new file mode 100644 index 00000000..3d4eec2f --- /dev/null +++ b/hmruntime/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:alpine as builder +LABEL maintainer="Hypermode " + +# build hmruntime binary +WORKDIR /src +COPY go.mod go.sum ./ +COPY *.go ./ +RUN go build . + +FROM ubuntu:20.04 + +# only update, don't run upgrade +# use cache busting to avoid old versions +# remove /var/lib/apt/lists/* to reduce image size. +# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + iputils-ping \ + jq \ + less \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /src/hmruntime /usr/bin/hmruntime +CMD ["hmruntime"] diff --git a/hmruntime/README.md b/hmruntime/README.md index a2d95a92..95e5a82f 100644 --- a/hmruntime/README.md +++ b/hmruntime/README.md @@ -14,10 +14,13 @@ The following must be installed on your development workstation or build server: To build the Hypermode runtime server: `go build` +To build the docker image: `docker build -t hmruntime .` + ## Running - To run the compiled program, invoke the `hmruntime` binary. - To run from code (while developing), use `go run .` instead. +- To run using docker containers, use `docker run -p 8686:8686 -v :/plugins hmruntime:latest hmruntime --dgraph=http://host.docker.internal:8080`. ## Notes diff --git a/hmruntime/dgraph.go b/hmruntime/dgraph.go index ff11a716..c394a378 100644 --- a/hmruntime/dgraph.go +++ b/hmruntime/dgraph.go @@ -17,7 +17,7 @@ import ( func executeDQL(ctx context.Context, stmt string, isMutation bool) ([]byte, error) { reqBody := strings.NewReader(stmt) - host := "http://localhost:8080" // TODO: make this configurable + host := *dgraphUrl var endpoint, contentType string if isMutation { endpoint = "/mutate?commitNow=true" @@ -47,7 +47,7 @@ func executeDQL(ctx context.Context, stmt string, isMutation bool) ([]byte, erro func executeGQL(ctx context.Context, stmt string) ([]byte, error) { reqBody := strings.NewReader(stmt) - resp, err := http.Post("http://localhost:8080/graphql", "application/graphql", reqBody) + resp, err := http.Post(fmt.Sprintf("%s/graphql", *dgraphUrl), "application/graphql", reqBody) if err != nil { return nil, fmt.Errorf("error posting GraphQL statement: %v", err) } diff --git a/hmruntime/main.go b/hmruntime/main.go index 81c768cc..8fdcd1b4 100644 --- a/hmruntime/main.go +++ b/hmruntime/main.go @@ -31,11 +31,14 @@ var compiledModules = make(map[string]wazero.CompiledModule) // map that holds the function info for each resolver var functionsMap = make(map[string]functionInfo) +var dgraphUrl *string + func main() { ctx := context.Background() // Parse command-line flags var port = flag.Int("port", 8686, "The HTTP port to listen on.") + dgraphUrl = flag.String("dgraph", "http://localhost:8080", "The Dgraph url to connect to.") flag.Parse() // Initialize the WebAssembly runtime From c406cefc025d75706444f9d6cc78e3fd31b26fda Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Wed, 3 Jan 2024 10:46:39 -0800 Subject: [PATCH 2/2] Remove apt-get --- hmruntime/Dockerfile | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hmruntime/Dockerfile b/hmruntime/Dockerfile index 3d4eec2f..25cfd35d 100644 --- a/hmruntime/Dockerfile +++ b/hmruntime/Dockerfile @@ -9,17 +9,5 @@ RUN go build . FROM ubuntu:20.04 -# only update, don't run upgrade -# use cache busting to avoid old versions -# remove /var/lib/apt/lists/* to reduce image size. -# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - iputils-ping \ - jq \ - less \ - && rm -rf /var/lib/apt/lists/* - COPY --from=builder /src/hmruntime /usr/bin/hmruntime CMD ["hmruntime"]