Judge0 API is an API for code compilation and execution. Complete and detailed API documentation is available on https://api.judge0.com.
- Project Organization
- Quick Development Setup
- Quick Production Setup
- About Docker Images
- Adding New Compiler or Interpreter
- HTTPS In Production
- Important Notes
Judge0 API is a Rails 5 application organized in two major components:
- Rails API
- accepts requests and creates background jobs for Worker.
- Worker
- accepts new jobs and process them as they arrive. Worker has only one job - IsolateJob, that job runs untrusted programs in sandboxed environment.
Setting up your development environment is easy thanks to Docker and Docker Compose. So please install those before continuing.
Because we are running our development environent in Docker you don't need to have Ruby, Rails, PostgreSQL, Redis, etc. installed on your computer. You just need to:
- Pull judge0/api:0.1.0 image:
$ docker pull judge0/api:0.1.0
- Run development shell (it will take a while only first time):
$ ./scripts/dev-shell
- Create, migrate and seed the database:
$ rails db:create db:migrate db:seed
scripts/dev-shell
script will open you new development shell always in the same container, and if container doesn't exist it will create one for you.
You need to run Rails API and Worker in order to have Judge0 API fully operational:
- Open new development shell and in there run Rails API server:
$ rails s -b 0.0.0.0
- Open new development shell again and in there run Worker process:
$ rails resque:work QUEUE=*
- Open http://localhost:3000 in your browser.
This is minimal setup for development environment, now you can open your favorite editor in your host and start developing Judge0 API.
To host your own Judge0 API you need to install Docker and Docker Compose on your server and after you are done proceed with the following:
-
Copy docker-compose.prod.yml on your server and save it as
docker-compose.yml
$ wget https://raw.githubusercontent.com/judge0/api/master/docker-compose.prod.yml -O docker-compose.yml
-
Copy judge0-api.conf to your server
$ wget https://raw.githubusercontent.com/judge0/api/master/judge0-api.conf
-
In
judge0-api.conf
change following variables:RAILS_ENV
andALLOW_ORIGIN
. -
Run database:
$ docker-compose up -d db
-
Run all other services:
$ docker-compose up -d
-
Open
http://<IP OF YOUR SERVER>:3000
in your browser.
This project has two Dockerfiles:
- builds
judge0/api:latest
image
- build
judge0/api:dev
image
judge0/api:latest
is built FROM judge0/api-base:latest
image which contains installed compilers and sandbox environment. This image represents production image of Judge0 API.
judge0/api:dev
is your local development image built FROM judge0/api:latest
. It is not pushed to Docker Hub. That is why you first need to pull judge0/api:latest
before building your development environment.
To add new compiler or interpreter you first need to install it into Judge0 API Base image. Instructions on how to do that can be found in documentation for Judge0 API Base.
After you have added your favorite compiler/interpreter to Judge0 API Base image you need to define how this compiler/interpreter is used.
This is done in db/seeds.rb
file.
You have four attributes:
- name - name of your language you are supporting, include also compiler name and version
- source_file - in what file should user's source code be saved before it is compiled
- compile_cmd - how this file is compiled, interpreted languages won't have this attribute
- run_cmd - how should we run this compiled or interpreted language
We already provided enough examples for most common languages, be sure to check that out.
To use HTTPS in production you we are going to use https://letsencrypt.org/.
You need to have your own domain for this to work. Just use docker-compose.prod.https.yml insted of docker-compose.prod.yml and change VIRTUAL_HOST
, LETSENCRYPT_HOST
and LETSENCRYPT_EMAIL
variables.
Everything else you need to do is described in Quick Production Setup section.
Judge0 API is simple to use and develop only if you are comfortable with using Docker and Docker Compose.
Docker and Docker Compose allow us to get rid of all dependencies, and concentrate on what is important - features, functionality and reliability.
Please before working with Judge0 project, make yourself comfortable with Docker and Docker Compose, because we are using it extensively.
We will add extensive documentation in the future about how and why we are using Docker and Docker Compose here, but this documentation won't substitute your knowledge of this technologies.
Feel free to ask us any questions in Issues directly. :)