Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create dockerfile #36

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions hmruntime/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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

# 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/*
mattjohnsonpint marked this conversation as resolved.
Show resolved Hide resolved

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