scr

module
v0.0.0-...-da21aa5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2022 License: MIT

README

* SCR - A Simple Code Runner
  [[https://travis-ci.org/keller0/yxi.io][https://travis-ci.org/keller0/scr.svg?branch=master]]

  Written in [[https://golang.org/][GO]].
  Using [[https://gin-gonic.github.io/gin/][gin]] web framework.
  Using [[https://www.docker.com/][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 [[https://hub.docker.com/][Docker Hub]], you can read the Makefile to finger it out.

** restAPI
*** API URLs
|--------+----------------------+-------------------------------------------------|
| Method | Path                 | Description                                     |
|--------+----------------------+-------------------------------------------------|
| Get    | /v1                  | all languages and versions                      |
| Get    | /v1/language         | all version of one language                     |
| POST   | /v1/language         | run code use default version of one language    |
| POST   | /v1/language/version | run code use a specific version of one language |

*** post response
|------------------+---------------------------+------------------------------------------------------------------------|
| Http status code | Description               | example data                                                           |
|------------------+---------------------------+------------------------------------------------------------------------|
|              200 | OK                        | {"userResult":{"stdout":"","stderr":"","exiterror":""},"taskError":""} |
|              400 | language is not supported | "java++ is not support"                                                |
|                  | version  is not supported | "java openjdk-100 is not support"                                      |
|                  | request data not valid    | "json: cannot unmarshal..."                                            |
|              500 | Internal Server Error     | "xxxx"                                                                 |

*** request examples
**** get version info of C
#+BEGIN_SRC SHELL
curl -X GET   http://localhost:8080/v1/c

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

**** run a C program
#+BEGIN_SRC
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": ""
}
#+END_SRC

****  Support

This project has been supported by [[https://www.jetbrains.com/][JetBrains]] with their free licenses.

[[https://www.jetbrains.com/][docs/imgs/jetbrains.svg]]




Directories

Path Synopsis
cmd
ric
internal
env

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL