Skip to content

Run C++/Java/Python code and get the output similar to online judges but exposed as a service. The code runs in a sandbox environment created using docker. A separate docker container is spawned for each execution.

License

Notifications You must be signed in to change notification settings

thephilomaths/code-runner-as-a-service

Repository files navigation

Code Runner as a Service

Setup

  • With docker

  1. Follow the instructions here to install docker.
  2. Then install docker compose by following this.
  3. Clone this respository and go to the root directory of this repo.
  4. Create a network using docker network create code_runner_net.
  5. Build the docker images using docker-compose build.
  6. cd to the runner directory and again run docker-compose build to build the runner images.
  7. Install docker-sync using gem install docker-sync. Make sure that the gem is in your PATH.
  8. Inside the repos' root directory run docker-sync-stack start. If you get an error then stop the containers and restart using the same command.
  • Without docker

  1. Inside the repos' root directory create a new python environment using python3 -m venv env and activate it by running source env/bin/activate.
  2. Install all the dependencies using pip3 install -r code_runner/requirements/requirements.txt. If you get an error in building psycopg2 then you must be missing necessary packages for building it.
  3. Install rabbitmq by following this link.
  4. Setup rabbitmq user by running chmod +x shell_scripts/init_rabbitmq.sh && sh shell_scripts/init_rabbitmq.sh.
  5. Install postgreSQL and configure the database credentials. After that create a database named code_runner.
  6. Modify the .env.development.local and change all hosts to localhost and change the passwords.
  7. Start the flask development server by running python3 wsgi.py.
  8. Open another terminal and navigate to the repos' root and start celery worker by running celery -A tasks worker --logLevel=DEBUG.
  9. You can now test it by visting http://localhost:5000.

Demo

I have created a public workspace on postman. You can test it from there and it can be used as a reference for API schema. Here's the link

About

Run C++/Java/Python code and get the output similar to online judges but exposed as a service. The code runs in a sandbox environment created using docker. A separate docker container is spawned for each execution.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published