glot-run

December 26, 2020 ยท View on GitHub

THIS REPO IS DEPRECATED AND HAS BEEN REPLACED BY docker-run and glot-run 2

Overview

glot-run provides a http api for running code inside docker containers. The api is described here.

Run

The download above is a standard erlang release that includes a start script. To start glot-run in the foreground type: glot/bin/glot foreground.

Environment variables

glot-run takes it's configuration from environment variables. All vars needs to be set, no default values are provided.

Variable nameAllowed valuesExampleDescription
API_ENVIRONMENTdevelopment | productionproductionDevelopment mode will enable auto compiling of changed files
API_HTTP_LISTEN_IP<ipv4 address>0.0.0.0Listen ip
API_HTTP_LISTEN_PORT1-655358090Listen port
DATA_PATH<filepath>/home/app/data/Path to save data files (users, languages)
LOG_PATH<filepath>/home/app/log/Path to save logs
BASE_URL<url>https://run.glot.ioBase url to where the api is hosted
ADMIN_TOKEN<string>some-secretAdmin token used to access the /admin endpoints
DOCKER_API_URL<url>http://10.0.0.2:2375Url to docker api (see docker configuration section below)
DOCKER_RUN_TIMEOUT<seconds>15Maximum number of seconds a container is allowed to run
MAX_OUTPUT_SIZE<bytes>100000Maximum number of bytes allowed from the output of a run

Api users

An api token is required to run code. Users can be created with the /admin/users endpoint. See the api docs for more details.

Languages

Languages can be added with the /admin/languages endpoint. A language has a name, version and the name of a docker image that will be used when running code for the given language/version. See the api docs for more details.

Docker images

When a run request is posted to glot-run it will create a new temporary container from the image that handles the given language/version. The container is required to listen for a json payload on stdin and must write the run result to stdout as a json object containing the properties: stdout, stderr and error. An application that does this is glot-code-runner. Example images can be found here.

Container payload

The payload {"files": [{"name": "main.py", "content": "print(42)"}]} posted to /languages/python/latest will result in this payload being sent to the container: {"language": "python", "files": [{"name": "main.py", "content": "print(42)"}]}. A successful run should yield this response from the container: {"stdout": "42\n", "stderr": "", "error": ""}.

Docker configuration

See docker_server_config.md