diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1bf7d03 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/vscode/devcontainers/go:1.17-bullseye + +# add more runtime dependencies here +ARG dependencies="python3 g++" +RUN apt-get update -y \ +&& apt-get install -y ${dependencies} \ +&& go install github.com/spf13/cobra/cobra@v1.3.0 + +EXPOSE 8080 +ENTRYPOINT ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4c98464 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "build": { + "dockerfile": "Dockerfile" + }, + "extensions": [ + "golang.go" + ], + "forwardPorts": [ + 8080 + ], +} \ No newline at end of file diff --git a/Makefile b/Makefile index f9cabf7..9e956c7 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ dkr-build-server: docker build -t ${SERVER_NAME}:${VERSION} -f docker/server/Dockerfile . dkr-build-dev: - docker build -t ${DEV_NAME}:${VERSION} -f docker/runtime-dev/Dockerfile . + docker build -t ${DEV_NAME}:${VERSION} -f .devcontainer/Dockerfile . dkr-server: dkr-build-server docker run -d -p 8080:8080 -e DEBUG=1 --name ${SERVER_NAME} ${SERVER_NAME}:${VERSION} diff --git a/docker/runtime-dev/Dockerfile b/docker/runtime-dev/Dockerfile deleted file mode 100644 index bf57c21..0000000 --- a/docker/runtime-dev/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM golang:1.17.7-buster as builder -WORKDIR /runner -COPY . . -RUN go build -v -o /runner/process /runner/engine/process/ \ - && go build -v -o /runner/runner-server /runner/server/ - -# TODO: use slimmer docker image like ubuntu:20.04 -FROM golang:1.17.7-buster - -# create non-root user, assign UID != 0 -RUN useradd -u 1111 -ms /bin/bash runner - -# define user to start up as -USER runner - -WORKDIR /home/runner -COPY --from=builder /runner/process ./ -COPY --from=builder /runner/runner-server ./ -ENTRYPOINT ["/bin/bash"] diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index de1babd..3bd89fd 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17.6-alpine3.15 as builder +FROM golang:1.17.7-alpine3.15 as builder WORKDIR /runner COPY . . RUN go build -v -o /runner/process /runner/engine/process/ \ diff --git a/readme.md b/readme.md index 021b168..e09ed80 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,7 @@ [![Unit Tests](https://github.com/camerondurham/runner/workflows/Unit%20Test/badge.svg?branch=main)](https://github.com/camerondurham/runner/actions?query=workflow%3A%22Unit+Test%22) [![Go Lint](https://github.com/camerondurham/runner/workflows/Go%20Lint/badge.svg?branch=main)](https://github.com/camerondurham/runner/actions?query=workflow%3A%22Go+Lint%22) +[![Go Version](https://img.shields.io/github/go-mod/go-version/camerondurham/runner)](https://img.shields.io/github/go-mod/go-version/camerondurham/runner) ## Intro @@ -24,7 +25,6 @@ loop Check Server->>Server: validate request end -Note right of Server: server logic not implemented yet Server-->>CodeRunner: submit code runner request loop Transform @@ -35,13 +35,21 @@ end CodeRunner-->>Runtime: run user code request -Note right of Runtime: resource limiting logic not implemented yet loop Limit Runtime->>Runtime: make timeout context - Runtime->>Runtime: set resource limits - Runtime->>Runtime: execute user code + Runtime->>Runtime: attach to stdout, stderr of command end +Runtime->>Process: execute processor binary + +Note right of Process: runtime creates a new process to avoid any resource limits affecting the runner server +loop Process + Process->>Process: set resource limits + Process->>Process: set non-root uid and gid for user code + Process->>Process: execute user code +end + +Process-->>Runtime: exits with error code or 0 meaning no error Runtime-->>CodeRunner: return stdout, stderr, runtime errors loop Cleanup @@ -83,6 +91,8 @@ add your personal favs: for running and debugging Go (see [vscode-go debugging docs](https://github.com/golang/vscode-go/blob/master/docs/debugging.md)) 1. `eamodio.gitlens` git lens (pro tip, enable editor heat map in upper right corner) +1. `ms-vscode-remote.remote-containers` + develop in containers with all dependencies pre-installed 1. `ms-vscode-remote.remote-wsl` for Windows WSL users 1. `yzhang.markdown-all-in-one` @@ -93,6 +103,27 @@ Docker: We will likely end up using Docker and include instructions here. For now, you can install [Docker Desktop](https://www.docker.com/get-started) if you like. +### Using Dev Containers with VSCode (recommended) + +To use a pre-built development container, you can use the VSCode and the dev container provided in `.devcontainer/devcontainer.json`. +This approach will use a Docker container with Go, cobra, python3, and g++ pre-installed and ready to use. + +Here is a waay to long video with ~5 mins showing setup and total 12 mins +demoing using the container: [runner devcontainer setup video](https://youtu.be/f9qBHyzxIlo) + +Steps: + +1. Verify that you have [Docker](https://www.docker.com/get-started) running +1. Open VSCode and install the **Remote - Containers** extension: `ms-vscode-remote.remote-containers` +1. Run the dev container + 1. Open the Command Palette (cmd + shift + P on macOS, `F1` or ctrl + shift + p on Windows/Linux) + 1. Run `Remote-Containers: Open Folder in Container` + 1. Select the `runner` repository folder +1. Wait for the dev container to start up and open the VSCode Terminal as needed to run commands! + +Also see [Remote-Containers: open an existing folder in a container](https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container). + + ## Development This repository is primarily written in Go and the Makefile has a helper @@ -150,6 +181,8 @@ make install-hooks CLI stands for command line interface. +> Note: this step is **not** needed if you are using the [dev container](#dev-container-recommended) since `cobra` is pre-installed in the container. + #### Installing the `cobra` CLI to help with codegen Install cobra dependencies: (required to generate new CLI commands)