Create a .env file with the following:
VERSION=0.0.3
APP_NAME=thefl45h/code-racer
This is necessary for building the docker container and using the Makefile
-
PORT
(optional): port to serve requests. Defaults to 8000 -
RUNNERS_PATH
(required): Path to runners script. This should be an absolute path to therunners
directory in the repo. This will be mounted in each executor -
MNTFS
(required): Path to mounted filesystem. Code racer will create directories and files for code execution. This should be an absolute path. This will be mounted in each executor. Recommend using an absolute path to themntfs
folder in this repo. -
NOSOCKET
(optional): Path tonosocket
binary. This should be an absolute path. If this env variable is not set, setDISABLE_NETWORKING
to1
. -
PULL_IMAGES
(optional):true/false
. Attempt to pull images or not. May be useful of executor images are already available locally. -
DISABLE_NETWORKING
(optional):1/0
. If1
running tasks will not be able to access the internet and make network calls.0
running tasks/process will have access to the internet.
Create an .env.development
with the above environment variables. Refer to .env.sample
Create an .devcontainer/.env
with the environment variables in .devcontainer/.env.sample
We strongly recommend docker/docker-compose for a smooth development process.
This project includes a (devcontainer)[https://code.visualstudio.com/docs/devcontainers/containers].
In the dev container, you can use the air
command to start up the server with hot reloading.
Create an .env.production
with the above environment variables. Refer to .env.sample
Use the root docker-compose.yml
file to create a production ready docker image
docker-compose build
docker-compose up
nosocket
is a custom binary that uses libseccomp
to block socket calls.
This is a security measure to prevent tasks submitted from accessing the internet.
/api/v1/swagger
POST https://code-racer-api.codewithflash.com/api/v1/execute
GET https://code-racer-api.codewithflash.com/api/v1/runtimes
Runtimes endpoint
GET /api/v1/runtimes
: Endpoint to list available runtimes
Response
[
{
"language": "python3"
},
{
"language": "node"
}
]
Execute endpoint
POST /api/v1/execute
. Endpoint to execute code
-
language
(required): language to use for execution. Refer to/api/v1/runtimes
for available languages -
entrypoint
(required): the file path to start execution from. This path must be present infiles
-
files
(required): An array of files containing code to be used for execution. -
file.name
(required): filename -
file.content
(required): content of file
{
"language": "node",
"entrypoint": "main.js",
"files": [
{
"name": "main.js",
"content": "console.log('Code Racer')"
}
]
}
{
"stderr": "",
"stdout": "Code Racer\n",
"executionTime": "438.757875ms",
"preparationTime": "102.106667ms"
}
python
, node
, go
, php
, java
, ruby
More to come