Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

keller0/scr

Repository files navigation

SCR - A Simple Code Runner

https://travis-ci.org/keller0/scr.svg?branch=master

Written in GO. Using gin web framework. Using docker to run code in containers.

How it works

  1. When SCR receive a post request, it will start a container and put the payload to container’s stdin then wait till this container stop or exit with error.
  2. While SCR is waiting, a program(ric) inside the container will take the payload and run those code, ric will put those code’s result to container’s stdout(include stdout stderr and exit status), if ric got error it will put error to container’s stderr and exit with non-zero value.
  3. Finally SCR get error or container’s stdout and stderr, then send response to client.

build it

  • build them in docker or use local go environment.
  • run `make` to build images and start the api container, or you can pull containers from Docker Hub, you can read the Makefile to finger it out.

restAPI

API URLs

MethodPathDescription
Get/v1all languages and versions
Get/v1/languageall version of one language
POST/v1/languagerun code use default version of one language
POST/v1/language/versionrun code use a specific version of one language

post response

Http status codeDescriptionexample data
200OK{“userResult”:{“stdout”:”“,”stderr”:”“,”exiterror”:”“},”taskError”:”“}
400language is not supported“java++ is not support”
version is not supported“java openjdk-100 is not support”
request data not valid“json: cannot unmarshal…”
500Internal Server Error“xxxx”

request examples

get version info of C

curl -X GET   http://localhost:8080/v1/c

[
    {
        "name": "c",
        "versions": [
            {
                "version": "gcc10",
                "url": "/v1/c/gcc10"
            }
        ]
    }
]

run a C program

curl -X POST   http://localhost:8090/v1/c   -H 'Content-Type: application/json'   -d '{
   "files" : [
      {
         "content" : "#include<stdio.h>\n\nint main()\n{\n    printf(\"Hello, World!\\n\");\n}",
         "name" : "main.c"
      }
   ],
   "stdin":"",
   "argument":{
   "compile":
   ["gcc", "-Wall"]

   }
}
'

{
    "userResult": {
        "stdout": "Hello, World!\n",
        "stderr": "",
        "exitError": ""
    },
    "taskError": ""
}

Support

This project has been supported by JetBrains with their free licenses.

docs/imgs/jetbrains.svg