Skip to content

Commit

Permalink
Add devcontainer and instructions closes #42 (#50)
Browse files Browse the repository at this point in the history
* add devcontainer environment

* organize README

* Add video link
  • Loading branch information
camerondurham authored Mar 7, 2022
1 parent cf45dcf commit fcf3c58
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build": {
"dockerfile": "Dockerfile"
},
"extensions": [
"golang.go"
],
"forwardPorts": [
8080
],
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
19 changes: 0 additions & 19 deletions docker/runtime-dev/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/ \
Expand Down
41 changes: 37 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fcf3c58

Please sign in to comment.