Skip to content

Commit

Permalink
create dockerfile (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmingtarja authored Jan 3, 2024
1 parent 09788e2 commit 004d9ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions hmruntime/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:alpine as builder
LABEL maintainer="Hypermode <hello@hypermode.com>"

# build hmruntime binary
WORKDIR /src
COPY go.mod go.sum ./
COPY *.go ./
RUN go build .

FROM ubuntu:20.04

COPY --from=builder /src/hmruntime /usr/bin/hmruntime
CMD ["hmruntime"]
3 changes: 3 additions & 0 deletions hmruntime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_PATH>:/plugins hmruntime:latest hmruntime --dgraph=http://host.docker.internal:8080`.

## Notes

Expand Down
4 changes: 2 additions & 2 deletions hmruntime/dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions hmruntime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 004d9ab

Please sign in to comment.