diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..407ef1931cd66df3a09535b240385a41e4728586 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +bin/telemetry filter=lfs diff=lfs merge=lfs -text diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..d423413c4943dc7ce369fa7ad41ff4dd685ca864 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,1328 @@ +This is the Changelog for Judge0 CE. The Changelog for Judge0 Extra CE can be found [here](https://github.com/judge0/judge0/blob/extra/CHANGELOG.md). Learn more about their difference [here](https://github.com/judge0/judge0#flavors). + +# v1.13.1 (2024-04-18) +Security researcher [Daniel Cooper](https://www.linkedin.com/in/daniel-cooper4) (@stacksparrow4) found three critical vulnerabilities in Judge0 versions `<= 1.13.0`, which this release fixes. Thank you, Daniel, for your contribution. + +## Security Fixes +This release fixes the following security vulnerabilities: +- [CVE-2024-28185](https://github.com/judge0/judge0/security/advisories/GHSA-h9g2-45c8-89cf) +- [CVE-2024-28189](https://github.com/judge0/judge0/security/advisories/GHSA-3xpw-36v7-2cmg) +- [CVE-2024-29021](https://github.com/judge0/judge0/security/advisories/GHSA-q7vg-26pg-v5hr) + +## Deployment Procedure +Judge0 is collecting telemetry data to help improve the product and understand its use in various production environments. Read more about telemetry [here](https://github.com/judge0/judge0/blob/v1.13.1/TELEMETRY.md). + +#### System Requirements +Please note that Judge0 has only been tested on **Linux** and might not work on other systems; thus, we do not provide support for it. + +We recommend using Ubuntu 22.04, on which you need to do the following update of GRUB: +1. Use `sudo` to open file `/etc/default/grub` +2. Add `systemd.unified_cgroup_hierarchy=0` in the value of `GRUB_CMDLINE_LINUX` variable. +4. Apply the changes: `sudo update-grub` +5. Restart your server: `sudo reboot` + +Additionally, make sure you have [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose) installed. + +#### Deployment Steps +1. Download and extract the release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.13.1/judge0-v1.13.1.zip +unzip judge0-v1.13.1.zip +``` + +2. Visit [this website](https://www.random.org/passwords/?num=1&len=32&format=plain&rnd=new) to generate a random password. +3. Use the generated password to update the variable `REDIS_PASSWORD` in the `judge0.conf` file. +4. Visit again [this website](https://www.random.org/passwords/?num=1&len=32&format=plain&rnd=new) to generate another random password. +5. Use the generated password to update the variable `POSTGRES_PASSWORD` in the `judge0.conf` file. +6. Run all services and wait a few seconds until everything is initialized: +``` +cd judge0-v1.13.1 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` +7. Your instance of Judge0 CE v1.13.1 is now up and running; visit docs at `http://:2358/docs`. + + +# v1.13.0 (2021-03-10) +Huge thanks to [**Filtered**](https://www.filtered.ai) for sponsoring this release. + +## New Features +- Added support for `enable_network` configuration flag. With the new `ALLOW_ENABLE_NETWORK` configuration variable, usage of this flag can be permitted or denied. Furthermore, with the new `ENABLE_NETWORK` configuration variable the default value of this flag can be set for every submission. + - Commits: [@62a00520](https://github.com/judge0/judge0/commit/62a00520692c2b7a8bf0f54528aee8fbbf864f36) +- Added `USE_DOCS_AS_HOMEPAGE` configuration variable, which allows you to show or hide Judge0 homepage. **Now, by default, Judge0 homepage is empty** and does not show the API documentation. However, you can still access the API documentation via `/docs`. + - Issues: [#257](https://github.com/judge0/judge0/issues/257) + +## Bug Fixes +- Fixed the bug where the wrong number of workers would be reported via `/workers`. + - Issues: [#256](https://github.com/judge0/judge0/issues/256) + +## Security Fixes +- **HIGH** Fixed a security bug where certain submission configuration settings would allow the user to run a program that would run infinetly long. With this fix `wall_time_limit` **must** be at least 1 second. + - Commits: [@fce8d97a](https://github.com/judge0/judge0/commit/fce8d97ae765e87c4584115fcb73bd288d64d815) + +## Other Changes +- Allow setting the `max_file_size` and `stack_limit` to 0 kB. + - Issues: [#242](https://github.com/judge0/judge0/issues/242) + - Commits: [@bf7c1284](https://github.com/judge0/judge0/commit/bf7c1284fe756d348154546ad8a6280ce3af5eb2) [@5a4b79ab](https://github.com/judge0/judge0/commit/5a4b79abd19c20b7b26ef70cf862da25f5fd8008) +- Allow setting the `cpu_time_limit` and `cpu_extra_time` to 0 seconds. + - Commits: [@fce8d97a](https://github.com/judge0/judge0/commit/fce8d97ae765e87c4584115fcb73bd288d64d815) +- Updated to a port 2358 as a new **default port for Judge0** as a online code execution service. + - Issues: [#205](https://github.com/judge0/judge0/issues/205) + - Commits: [@ea9c7c97](https://github.com/judge0/judge0/commit/ea9c7c975e0697d66ada910ec7806d3c28ad4a03) +- Updated the default number of Judge0 Workers, those that acutally run the user's code, to the 2*[`nproc`](https://linux.die.net/man/1/nproc). This has been shown as a good choice for general purpose use-case. + - Commits: [@113d9c74](https://github.com/judge0/judge0/commit/113d9c74b4659cf6707e748eb6e04701ce67d3f0) +- Updated the default number of Rails threads to `nproc` and Rails processes to 2. This has been shown as a good choice for general purpose use-case. + - Commits: [@113d9c74](https://github.com/judge0/judge0/commit/113d9c74b4659cf6707e748eb6e04701ce67d3f0) +- Updated Let's Encrypt Docker image for deployment with HTTPS. + - Commits: [@86b7f8e8](https://github.com/judge0/judge0/commit/86b7f8e8d0154ab5044db91c537872ea8deb7343) +- Updated Nginx proxy Docker image that is used in development setup and deployment with HTTPS. + - Commits: [@83f5b175](https://github.com/judge0/judge0/commit/83f5b175d0925fe21374e9c70d7fbb4e6941fa9c) +- Fixed documentation typos. Thank you @balababa. + - Pull Requests: [#245](https://github.com/judge0/judge0/pull/245) +- Updated base image to `judge0/compilers:1.4.0` which uses updated Isolate to [@ad39cc4d](https://github.com/judge0/isolate/commit/ad39cc4d0fbb577fb545910095c9da5ef8fc9a1a). + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/judge0/blob/v1.13.0/TELEMETRY.md). + +Please note that Judge0 has only been tested on **Linux** and **macOS**, and might not work on Windows, thus we do not provide support for it. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract the release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.13.0/judge0-v1.13.0.zip +unzip judge0-v1.13.0.zip +``` + +3. Run all services and wait a few seconds until everything is initialized: +``` +cd judge0-v1.13.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 CE v1.13.0 is now available at `http://:2358`. + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract the release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.13.0/judge0-v1.13.0-https.zip +unzip judge0-v1.13.0-https.zip +``` + +3. Change directory to `judge0-v1.13.0-https`: +``` +cd judge0-v1.13.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait a few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 CE v1.13.0 is now available at `https://`. + + +# v1.12.0 (2020-10-18) +## New Features +- Added support for invalidating statistics cache using the `invalidate_cache` query parameter. + - Commits: [@561c2a30](https://github.com/judge0/judge0/commit/561c2a309d98680801628fc2d79ea17e885e1d66) +- Added rake task `judge0:run_in_queue` to manually run submissions that might have stuck in the `In Queue` state. + - Commits: [@c3b87d23](https://github.com/judge0/judge0/commit/c3b87d232a8e922b5ae04f5afdb12fc49b2ec003) +- Added support for specifying `CALLBACKS_MAX_TRIES` and `CALLBACKS_TIMEOUT`. This is a global configuration that applies to all submissions that have defined webhooks (HTTP callbacks). + - Commits: [@c4bb76ec](https://github.com/judge0/judge0/commit/c4bb76ec866bce6b07bd733391291e720f40ef96) +- Added support for submission caching to reduce the number of unnecessary database hits. Cache duration can be controlled with the `SUBMISSION_CACHE_DURATION` variable which is currently set to 1 second by default. Submissions are only cached for `GET /submissions/` route. Cache files are written to the server's file system and are automatically cleared every day at midnight. This is the first step toward more serious submission caching in the future. + - Commits: [@7a33c61c](https://github.com/judge0/judge0/commit/7a33c61c8dcbcdbf31fd4d93ef76cc2f1f5e154b) [@0b344920](https://github.com/judge0/judge0/commit/0b344920bd70bd2bf4b2a53fc78b6b145c298cbc) + +## Improvements +- Update PostgreSQL to 13.0 and Redis to 6.0. + - Commits: [@05330f11](https://github.com/judge0/judge0/commit/05330f112b26850a18c59a380991f8b401eae224) [@be300efa](https://github.com/judge0/judge0/commit/be300efa4bec7653303bb76681f91588550c25ef) +- Reschedule failed jobs after 0.1 seconds with 100 attempts. + - Commits: [@f7265cf8](https://github.com/judge0/judge0/commit/f7265cf8d53ef5319a9e96e1bf7bee8649b09762) [@e003c888](https://github.com/judge0/judge0/commit/e003c888e64ea4f4a83e1acce8d355b666276aa2) +- Send only submission ID to the worker and not the whole serialized submission. + - Commits: [@f7265cf8](https://github.com/judge0/judge0/commit/f7265cf8d53ef5319a9e96e1bf7bee8649b09762) [@4222c090](https://github.com/judge0/judge0/commit/4222c090689deb1a356cf6c2588b81b9904124f1) +- Automatically restart Judge0 server without the need for Docker restart policies. Use the `RESTART_MAX_TRIES` variable to specify the maximum number of restart tries. + - Commits: [@65756516](https://github.com/judge0/judge0/commit/65756516b331265ec5a6742372ecc57ecbb8ca71) [@c0fd97e2](https://github.com/judge0/judge0/commit/c0fd97e2359172f7fc8bf7195089ab7c19845728) + +## Bug Fixes +- Fixed a bug in the `is_project` method of submission model where an exception was raised and not handled properly due to unknown language. + - Commits: [@6426ac61](https://github.com/judge0/judge0/commit/6426ac61ea6723fcf6b93b72024ec39e3dc4b7f2) + +## Other Changes +- Use Docker volumes for storing Postgres and Redis data instead of mounting directories. This is now the new recommended setting. + - Commits: [@600f5aaa](https://github.com/judge0/judge0/commit/600f5aaa3facfef38dd2cd5df25ac248734ace97) +- Added Resque Web to the development stack. + - Commits: [@3762a635](https://github.com/judge0/judge0/commit/3762a6355b8911d8d8e13d91869edeef9bec0a4f) +- Changed binding ports for Nginx and documentation server in the development stack. Nginx is now bound to port 80, and the development server to port 3001. + - Commits: [@3762a635](https://github.com/judge0/judge0/commit/3762a6355b8911d8d8e13d91869edeef9bec0a4f) +- Removed port bindings of Postgres and Redis in the development stack. + - Commits: [@3762a635](https://github.com/judge0/judge0/commit/3762a6355b8911d8d8e13d91869edeef9bec0a4f) +- Added PgBouncer to the development stack for testing and experimenting. + - Commits: [@24b3227a](https://github.com/judge0/judge0/commit/24b3227a0a47dcca89041e1c08106d08a413dcf3) +- Changed recommended values for `POSTGRES_DB` and `POSTGRES_USER`. Both are now `judge0`. + - Commits: [@745f4455](https://github.com/judge0/judge0/commit/745f4455937d15f2f6093539e9ab96c40bc506da) + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/judge0/blob/v1.12.0/TELEMETRY.md). + +Please note that Judge0 has only been tested on **Linux** and **macOS**, and might not work on Windows, thus we do not provide support for it. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.12.0/judge0-v1.12.0.zip +unzip judge0-v1.12.0.zip +``` + +3. Run all services and wait a few seconds until everything is initialized: +``` +cd judge0-v1.12.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 v1.12.0 is now available at `http://`. + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.12.0/judge0-v1.12.0-https.zip +unzip judge0-v1.12.0-https.zip +``` + +3. Change directory to `judge0-v1.12.0-https`: +``` +cd judge0-v1.12.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait a few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 v1.12.0 is now available at `https://`. + + +# v1.11.0 (2020-09-09) +## New Features +- Added queue size into response of `/workers`. + - Issues: [#210](https://github.com/judge0/judge0/issues/210) + - Commits: [@7ee1b10c](https://github.com/judge0/judge0/commit/7ee1b10c79576e745140f02d49446d57a208bcca) + +## Improvements +- Set configuration defaults even if `judge0.conf` is not present. Thank you @vvalchev. + - Issues: [#206](https://github.com/judge0/judge0/issues/206) + - Commits: [@8c42f7be](https://github.com/judge0/judge0/commit/8c42f7befcdf8d70fa8cb4e3ba549c828c38164d) + +## Other Changes +- Updated documentation with some better explanation on the use of `base64_encoded` query parameter. Thank you @mejibyte. + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/judge0/blob/v1.11.0/TELEMETRY.md). + +Please note that Judge0 has only been tested on **Linux** and might not work on Windows or macOS, thus we do not provide support for these systems. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.11.0/judge0-v1.11.0.zip +unzip judge0-v1.11.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-v1.11.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 v1.11.0 is now available at `http://`. + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/judge0/releases/download/v1.11.0/judge0-v1.11.0-https.zip +unzip judge0-v1.11.0-https.zip +``` + +3. Change directory to `judge0-v1.11.0-https`: +``` +cd judge0-v1.11.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 v1.11.0 is now available at `https://`. + + +# v1.10.0 (2020-07-27) +## New Features +- Added support for multi-file programs in the terms of adding a new special language called **Multi-file program**. In total there are now **47 active languages**. + +|ID|Name|Note| +|---|---|---| +|89|Multi-file program|| + +Multi-file programs allow you specify your own compilation and execution scripts that Judge0 will use. + +To use multi-file program feature you need to choose a language called *Multi-file program* whoose ID is **89**. Moreover, you need to send all program files with `additional_files` attribute. With multi-file programs attribute `source_code` cannot be used, i.e. all files should be sent with `additional_files` attribute. + +For the Judge0 to know how to compile and execute your multi-file program you need to provide two special files that should be available in the root of the `.zip` archive that you are sending with `additional_files` attribute. These files should be named `compile` and `run`, and are expected to be Bash scripts that know how to compile and execute your multi-file program. If your multi-file program does not need compilation step, then you don't need to provide `compile` script. Take a look at [this example](https://github.com/judge0/examples/tree/master/cpp-project-01) to learn how to use this feature to compile and run multi-file C++ project that uses CMake. + +## Other Changes +- Updated gems. + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/api/blob/v1.10.0/TELEMETRY.md). + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.10.0/judge0-v1.10.0-https.zip +unzip judge0-v1.10.0-https.zip +``` + +3. Change directory to `judge0-v1.10.0-https`: +``` +cd judge0-v1.10.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 v1.10.0 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.10.0/judge0-v1.10.0.zip +unzip judge0-v1.10.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-v1.10.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 v1.10.0 is now available at `http://`. + + +# v1.9.0 (2020-06-10) +Huge thanks to [**Filtered**](https://www.filtered.ai) for sponsoring this release. + +## New Features +- Added support for configuration variable `RAILS_SERVER_PROCESSES` which allows to create multiple processes for handling requests. + +## Other Changes +- Updated gems. + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/api/blob/v1.9.0/TELEMETRY.md). + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.9.0/judge0-v1.9.0-https.zip +unzip judge0-v1.9.0-https.zip +``` + +3. Change directory to `judge0-v1.9.0-https`: +``` +cd judge0-v1.9.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 v1.9.0 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.9.0/judge0-v1.9.0.zip +unzip judge0-v1.9.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-v1.9.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 v1.9.0 is now available at `http://`. + + +# v1.8.0 (2020-05-28) +Huge thanks to [**Filtered**](https://www.filtered.ai) for sponsoring this release. + +## New Features +- Added **4 new languages**, and in total there are now **46 active languages**. + +|ID|Name|Note| +|---|---|---| +|85|Perl (5.28.1)|Sponsored by [Filtered](https://www.filtered.ai).| +|86|Clojure (1.10.1)|Sponsored by [Filtered](https://www.filtered.ai).| +|87|F# (.NET Core SDK 3.1.202)|Sponsored by [Filtered](https://www.filtered.ai).| +|88|Groovy (3.0.3)|Sponsored by [Filtered](https://www.filtered.ai).| + +## Bug Fixes +- Fixed `/statistics` route caching. + - Issues: [#184](https://github.com/judge0/api/issues/184) + - Commits: [@83c5cfc6](https://github.com/judge0/api/commit/83c5cfc6b4ae95fa8bdef0bba2eee98829207dd0) + +## Other Changes +- Updated gems. + - Commits: [@0c766273](https://github.com/judge0/api/commit/0c766273d7cb8009695a3aa1903719c8474a233d) [@700e6582](https://github.com/judge0/api/commit/700e65829910ee860ddfa43254847f564c0d5623) +- Increased default `CPU_TIME_LIMIT` to 5, `CPU_EXTRA_TIME` to 1, `MAX_CPU_EXTRA_TIME` to 5 and `WALL_TIME_LIMIT` to 10 seconds. + - Commits: [@77961ab9](https://github.com/judge0/api/commit/77961ab9f6b1015d5bdb5150e29d8de06478f38c) +- Changed `HOME` environment variable value for sandbox to `/tmp`. + - Commits: [@77961ab9](https://github.com/judge0/api/commit/77961ab9f6b1015d5bdb5150e29d8de06478f38c) +- Updated *isolate* to [@9be3ff6f](https://github.com/judge0/isolate/commit/9be3ff6ff0670763e564912a6662730e55b69536). + +## Deployment Procedure +Judge0 API is collecting telemetry data to help understand how to improve the product and to better understand how the Judge0 API is used in various production environments. Read more about telemetry [here](https://github.com/judge0/api/blob/v1.8.0/TELEMETRY.md). + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.8.0/judge0-api-v1.8.0-https.zip +unzip judge0-api-v1.8.0-https.zip +``` + +3. Change directory to `judge0-api-v1.8.0-https`: +``` +cd judge0-api-v1.8.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 API v1.8.0 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.8.0/judge0-api-v1.8.0.zip +unzip judge0-api-v1.8.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.8.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 API v1.8.0 is now available at `http://`. + + +# v1.7.1 (2020-05-06) +## Bug Fixes +- Compile Swift before executing since default file size limit of 1MB for execution is not enough for Swift to run successfully. Compilation has a file size limit of 4MB by default which seems to be enough for Swift to compile. Thanks @OliverwengFiltered. + - Issues: [#154](https://github.com/judge0/api/issues/154) + - Commits: [@371e2463](https://github.com/judge0/api/commit/371e246312a41242033d916f1f4fea3db80015b7) +- Fixed environment loading for Telemetry Client. + - Commits: [@bd16119c](https://github.com/judge0/api/commit/bd16119ccde52798b5d354afdd5e008df6d5b940) + +## Other Changes +- Set `VIRTUAL_HOST` environment variable in Dockerfile to value `3000`. +- Updated Telemetry Client to version `c62fa63d`. +- Added separated Docker Compose files for server and workers. +- Renamed service `worker` to `workers` and `api` to `server`. + +## Deployment Procedure +Judge0 API is collecting telemetry data to help understand how to improve the product and to better understand how the Judge0 API is used in various production environments. Read more about telemetry [here](https://github.com/judge0/api/blob/v1.7.1/TELEMETRY.md). + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.7.1/judge0-api-v1.7.1-https.zip +unzip judge0-api-v1.7.1-https.zip +``` + +3. Change directory to `judge0-api-v1.7.1-https`: +``` +cd judge0-api-v1.7.1-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 API v1.7.1 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.7.1/judge0-api-v1.7.1.zip +unzip judge0-api-v1.7.1.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.7.1 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 API v1.7.1 is now available at `http://`. + + +# v1.7.0 (2020-05-05) +Huge thanks to sponsors of this release: [**Filtered**](https://www.filtered.ai) and [**Evalart**](https://evalart.com). + +## New Features +- Added **10 new languages**, and in total there are now **42 active languages**. + +|ID|Name|Note| +|---|---|---| +|75|C (Clang 7.0.1)|| +|76|C++ (Clang 7.0.1)|| +|77|COBOL (GnuCOBOL 2.2)|Sponsored by [Evalart](https://evalart.com).| +|78|Kotlin (1.3.70)|Sponsored by [Filtered](https://www.filtered.ai).| +|79|Objective-C (Clang 7.0.1)|Sponsored by [Filtered](https://www.filtered.ai) and [Evalart](https://evalart.com).| +|80|R (4.0.0)|Sponsored by [Filtered](https://www.filtered.ai).| +|81|Scala (2.13.2)|Sponsored by [Filtered](https://www.filtered.ai).| +|82|SQL (SQLite 3.27.2)|Sponsored by [Filtered](https://www.filtered.ai). (*)| +|83|Swift (5.2.3)|Sponsored by [Filtered](https://www.filtered.ai) and [Evalart](https://evalart.com).| +|84|Visual Basic.Net (vbnc 0.0.0.5943)|Sponsored by [Filtered](https://www.filtered.ai).| + +(*) Watch [this asciicast](https://asciinema.org/a/326975) to learn how to use this language. + +## Other Changes +- Increased default `MAX_MEMORY_LIMIT` to 512000. + - Commits: [@3dcbfc96](https://github.com/judge0/api/commit/3dcbfc9605a0f81680afd890a239ef2b60739186) +- Set compile CPU time limit to `MAX_CPU_TIME_LIMIT`. + - Commits: [@3dcbfc96](https://github.com/judge0/api/commit/3dcbfc9605a0f81680afd890a239ef2b60739186) +- Set compile wall time limit to `MAX_WALL_TIME_LIMIT`. + - Commits: [@3dcbfc96](https://github.com/judge0/api/commit/3dcbfc9605a0f81680afd890a239ef2b60739186) +- Redirect input from `/dev/null` when compiling. Thank you @gollux for your [help](https://github.com/ioi/isolate/issues/90). + - Commits: [@42b89a7c](https://github.com/judge0/api/commit/42b89a7cdb333253460023fa7bcbf1640329d48b) + +## Deployment Procedure +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.7.0/judge0-api-v1.7.0-https.zip +unzip judge0-api-v1.7.0-https.zip +``` + +3. Change directory to `judge0-api-v1.7.0-https`: +``` +cd judge0-api-v1.7.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 API v1.7.0 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.7.0/judge0-api-v1.7.0.zip +unzip judge0-api-v1.7.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.7.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 API v1.7.0 is now available at `http://`. + + +# v1.6.0 (2020-05-01) +## New Features +- Added support for automatically redirecting stderr to stdout of the running program with the configuration flag `redirect_stderr_to_stdout`. Added configuration variable `REDIRECT_STDERR_TO_STDOUT` that can be used for setting default behaviour for every submission. + - Commits: [@8e6617aa](https://github.com/judge0/api/commit/8e6617aae2d4dd9106ab610738dcc5e59633b2f4) +- Added configuration variable `DISALLOW_ORIGIN` that can be used for disabling CORS only for specific origins. + - Commits: [@f61b5496](https://github.com/judge0/api/commit/f61b54965f12a9ccb0d19d3449bc818b12881127) [@a927c9db](https://github.com/judge0/api/commit/a927c9db0f47aa8bd3d2b7dd1774a829a0cbc6f7) +- Added configuration variables `ALLOW_IP` and `DISALLOW_IP` that can be used for allowing/disallowing only specific IP addresses that can use instance of Judge0 API. + - Commits: [@4fd0f34b](https://github.com/judge0/api/commit/4fd0f34b8f08fe808dd6b19ca96bac1e15b2a6f3) +- Added support for built in maintenance mode that can be enabled with configuration variables `MAINTENANCE_MODE` and `MAINTENANCE_MESSAGE`. In maintenance mode clients cannot create or delete submissions i.e. they cannot create new database changes. + - Commits: [@201221e2](https://github.com/judge0/api/commit/201221e22bbe64e960306b2dcf22cc6941892e3f) +- Added support for universal field `*` which returns all attributes of a submission. + - Commits: [@521cc2e2](https://github.com/judge0/api/commit/521cc2e2e94f1b469c084680020953e76af6e2b9) +- Added route `GET /statistics` which returns some basic and useful information about Judge0 API instance. Statistic report is cached for 10 minutes. + - Commits: [@a24db632](https://github.com/judge0/api/commit/a24db6326b793e093a64dea877c26402c585c680) [@621c50f1](https://github.com/judge0/api/commit/621c50f1f8056e716ff073a404556e51ab3a34c3) [@eead8067](https://github.com/judge0/api/commit/eead806786fac79e13cee9fca0fe7196f116680b) +- Added basic support for callbacks which are called with HTTP verb `PUT`. + - Pull Requests: [#98](https://github.com/judge0/api/pull/98) + - Issues: [#33](https://github.com/judge0/api/issues/33) + - Commits: [@41e846b1](https://github.com/judge0/api/commit/41e846b156bc7c071b9d2827271d87cfaee584f7) +- Added support for presetting custom additional files in a sandbox. + - Issues: [#32](https://github.com/judge0/api/issues/32) [#88](https://github.com/judge0/api/issues/88) + - Commits: [@7829db87](https://github.com/judge0/api/commit/7829db878895acdb3adfa063df03204c87cd1589) [@6d1f4293](https://github.com/judge0/api/commit/6d1f4293000a479a0cae0e9c4dc905652297199b) [@6573c52f](https://github.com/judge0/api/commit/6573c52faccee55e467457ab54742dd189a48a4b) +- Added routes `GET /submissions/batch` and `POST /submissions/batch` batch create and show or +submissions. + - Issues: [#34](https://github.com/judge0/api/issues/34) + - Commits: [@6420156b](https://github.com/judge0/api/commit/6420156b0ad6526bed3d638be3e824c996cd33cd) [@87859b58](https://github.com/judge0/api/commit/87859b58e4c348249237f2a7881c1c26dcb5d785) [@595c7e11](https://github.com/judge0/api/commit/595c7e11d6ede28d6bef7b98c2675f29e1ae2a9a) [@04c900c9](https://github.com/judge0/api/commit/04c900c9d9c325720ed5c807b46272a500c22a97) [@cb676d6c](https://github.com/judge0/api/commit/cb676d6c7fe3a6e9144a9246329c6223e48c6511) + +## Improvements +- Use Redis queue with name that corresponds with the current Judge0 API version. This allows multiple instances of different versions of Judge0 API to use the same Redis instance. + - Commits: [@dd6b62d7](https://github.com/judge0/api/commit/dd6b62d73c6ab0ef028711258e2edb141c1ba81a) +- Refactored submission field checking. + - Commits: [@9acefdbc](https://github.com/judge0/api/commit/9acefdbc7959ff88770ea186d12a085158bce521) +- Refactored setting up of default values. + - Commits: [@a14ae5d5](https://github.com/judge0/api/commit/a14ae5d540db75a0ade3a4dbfc12e6120d0c1ee2) + +## Bug Fixes +- Fixed a bug that ignored custom setting of configuration variables `enable_per_process_and_thread_time_limit` and `enable_per_process_and_thread_memory_limit`. + - Commits: [@a6f693a0](https://github.com/judge0/api/commit/a6f693a0ced221a28a3f4b4815e9d3baf8c2c4c0) +- Fixed a bug where cgroups flags for isolate were chosen in the wrong conditions. + - Commits: [@4116b9cb](https://github.com/judge0/api/commit/4116b9cb988816cad81f6b5c3265da01a8cec120) +- Fixed a bug that caused `Internal Error` because sandbox cleanup failed. + - Pull Requests: [#126](https://github.com/judge0/api/pull/126) + - Issues: [#123](https://github.com/judge0/api/issues/123) [#143](https://github.com/judge0/api/issues/143) + - Commits: [@514aec53](https://github.com/judge0/api/commit/514aec53dca8f1fb9f8f153add05c14d263d6624) +- Fixed a bug where low `memory_limit` would cause `Internal Error`. Minimum required value for `memory_limit` is now 2048. + - Commits: [@655ccf27](https://github.com/judge0/api/commit/655ccf277aad2c11371ca223c5386380c0bfc4ba) + +## Security Fixes +- Fixed a bug that allowed creation of an arbitrary size of the compile output. + - Commits: [@5fc7b823](https://github.com/judge0/api/commit/5fc7b823a7bccecb148c57615da0be9d52f1585a) + +## Other Changes +- Do not implicitly force wide open CORS settings when in development mode. I.e. variable `ALLOW_ORIGIN` can now also be used in development mode. + - Commits: [@a3a24c5c](https://github.com/judge0/api/commit/a3a24c5c6fab31ab845905b7120146b18bfe7dbb) +- Removed output of configuration settings when server or worker starts. + - Commits: [@7061de7a](https://github.com/judge0/api/commit/7061de7a69ffb07b335e44f7120619558a6cf79d) +- Updated all the gems except Rails to the latest versions. + - Commits: [@230c7a77](https://github.com/judge0/api/commit/230c7a777edf96d6d8848618c15c239134d1f29b) [@69a9fe11](https://github.com/judge0/api/commit/69a9fe1193fb437e103a56b9691196e3687e5e7e) [@095588e6](https://github.com/judge0/api/commit/095588e6642211a123e5091227271de27fc700d5) +- Changed default value of `enable_per_process_and_thread_memory_limit` to `false`. + - Commits: [@4116b9cb](https://github.com/judge0/api/commit/4116b9cb988816cad81f6b5c3265da01a8cec120) +- Don't show total number of workers in `/workers` that is determined with configuration variable `COUNT` because that number is not relevant. + - Commits: [@99939b89](https://github.com/judge0/api/commit/99939b89a58d21fc7c6a43fcec90550f75681e39) +- Changed the default port to `80` in Docker Compose file. + - Commits: [@6ab67d6b](https://github.com/judge0/api/commit/6ab67d6b1e723ce1e959dd17c899605c340bc6ed) +- Limited the log size to 100 MB in Docker Compose file. + - Commits: [@435c7d79](https://github.com/judge0/api/commit/435c7d792babfda8564dd432d31d4edc5a694ab9) +- Added logging to `run-workers` script. + - Commits: [@381265a2](https://github.com/judge0/api/commit/381265a295c130c54d540641ba071a18447d8223) +- Updated dummy client default values. +- Added Docker Compose file for HTTPS support. +- Refactored all development and production scripts from `scripts` directory. +- Refactored `judge0-api.conf` file. + +## Deployment Procedure +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.6.0/judge0-api-v1.6.0-https.zip +unzip judge0-api-v1.6.0-https.zip +``` + +3. Change directory to `judge0-api-v1.6.0-https`: +``` +cd judge0-api-v1.6.0-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait few seconds until everything is initialized: +``` +docker-compose up -d db redis nginx letsencrypt +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 API v1.6.0 is now available at `https://`. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.6.0/judge0-api-v1.6.0.zip +unzip judge0-api-v1.6.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.6.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 API v1.6.0 is now available at `http://`. + + +# v1.5.0 (2020-01-01) +## New Features +- Added **30 new languages**, archived 42 languages and kept active 2 languages from the last release. In total, there are now **32 active languages** that can be used and all are updated to their latest versions as of the date of this release. Archived languages cannot be used anymore. Following table shows a status of every language that API supports. + - Issues: [#51](https://github.com/judge0/api/issues/51) [#90](https://github.com/judge0/api/issues/90) [#106](https://github.com/judge0/api/issues/106) [#131](https://github.com/judge0/api/issues/131) + - Commits: [@f86a546c](https://github.com/judge0/api/commit/f86a546cb9c90eeaedf08862d2a2a2a76293a87f) + +|ID|Name|Status| +|---|---|---| +|1|Bash (4.4)|archived| +|2|Bash (4.0)|archived| +|3|Basic (fbc 1.05.0)|archived| +|4|C (gcc 7.2.0)|archived| +|5|C (gcc 6.4.0)|archived| +|6|C (gcc 6.3.0)|archived| +|7|C (gcc 5.4.0)|archived| +|8|C (gcc 4.9.4)|archived| +|9|C (gcc 4.8.5)|archived| +|10|C++ (g++ 7.2.0)|archived| +|11|C++ (g++ 6.4.0)|archived| +|12|C++ (g++ 6.3.0)|archived| +|13|C++ (g++ 5.4.0)|archived| +|14|C++ (g++ 4.9.4)|archived| +|15|C++ (g++ 4.8.5)|archived| +|16|C# (mono 5.4.0.167)|archived| +|17|C# (mono 5.2.0.224)|archived| +|18|Clojure (1.8.0)|archived| +|19|Crystal (0.23.1)|archived| +|20|Elixir (1.5.1)|archived| +|21|Erlang (OTP 20.0)|archived| +|22|Go (1.9)|archived| +|23|Haskell (ghc 8.2.1)|archived| +|24|Haskell (ghc 8.0.2)|archived| +|25|Insect (5.0.0)|archived| +|26|Java (OpenJDK 9 with Eclipse OpenJ9)|archived| +|27|Java (OpenJDK 8)|archived| +|28|Java (OpenJDK 7)|archived| +|29|JavaScript (nodejs 8.5.0)|archived| +|30|JavaScript (nodejs 7.10.1)|archived| +|31|OCaml (4.05.0)|archived| +|32|Octave (4.2.0)|archived| +|33|Pascal (fpc 3.0.0)|archived| +|34|Python (3.6.0)|archived| +|35|Python (3.5.3)|archived| +|36|Python (2.7.9)|archived| +|37|Python (2.6.9)|archived| +|38|Ruby (2.4.0)|archived| +|39|Ruby (2.3.3)|archived| +|40|Ruby (2.2.6)|archived| +|41|Ruby (2.1.9)|archived| +|42|Rust (1.20.0)|archived| +|43|Plain Text|Renamed from `Text (plain text)`.| +|44|Executable|Not changed.| +|45|Assembly (NASM 2.14.02)|**NEW**| +|46|Bash (5.0.0)|**NEW**| +|47|Basic (FBC 1.07.1)|**NEW**| +|48|C (GCC 7.4.0)|**NEW**| +|49|C (GCC 8.3.0)|**NEW**| +|50|C (GCC 9.2.0)|**NEW**| +|51|C# (Mono 6.6.0.161)|**NEW**| +|52|C++ (GCC 7.4.0)|**NEW**| +|53|C++ (GCC 8.3.0)|**NEW**| +|54|C++ (GCC 9.2.0)|**NEW**| +|55|Common Lisp (SBCL 2.0.0)|**NEW**| +|56|D (DMD 2.089.1)|**NEW**| +|57|Elixir (1.9.4)|**NEW**| +|58|Erlang (OTP 22.2)|**NEW**| +|59|Fortran (GFortran 9.2.0)|**NEW**| +|60|Go (1.13.5)|**NEW**| +|61|Haskell (GHC 8.8.1)|**NEW**| +|62|Java (OpenJDK 13.0.1)|**NEW**| +|63|JavaScript (Node.js 12.14.0)|**NEW**| +|64|Lua (5.3.5)|**NEW**| +|65|OCaml (4.09.0)|**NEW**| +|66|Octave (5.1.0)|**NEW**| +|67|Pascal (FPC 3.0.4)|**NEW**| +|68|PHP (7.4.1)|**NEW**| +|69|Prolog (GNU Prolog 1.4.5)|**NEW**| +|70|Python (2.7.17)|**NEW**| +|71|Python (3.8.1)|**NEW**| +|72|Ruby (2.7.0)|**NEW**| +|73|Rust (1.40.0)|**NEW**| +|74|TypeScript (3.7.4)|**NEW**| + +- Added route `GET /languages/:id` for getting all attributes of specified language. + - Commits: [@2a31e963](https://github.com/judge0/api/commit/2a31e96326651b90b59403d811ae48445fa4202e) +- Added route `GET /languages/all` for getting a list of all languages (archived and active). + - Commits: [@2a31e963](https://github.com/judge0/api/commit/2a31e96326651b90b59403d811ae48445fa4202e) +- Added route `DELETE /submissions/:token` for deleting specified submission. Only authorized requests (users) are allowed to delete a submission. + - Commits: [@3365e3c8](https://github.com/judge0/api/commit/3365e3c8da28bd273dbd7a21417e75fe393d83ee) +- Added configuration variable `ENABLE_SUBMISSION_DELETE` with default value set to `false`. By default you cannot delete a submission as long as this variable is set to `false`. When set to `true` then only authorized requests (users) can delete specific submission. + - Commits: [@79e1de95](https://github.com/judge0/api/commit/79e1de95a4a6d2e022af557b96056b009a90be5e) +- Added info routes `GET /about`, `GET /version`, `GET /license` and `GET /isolate`. Last route `GET /isolate` returns result from [`isolate --version`](https://github.com/ioi/isolate) command. + - Commits: [@9f5202a5](https://github.com/judge0/api/commit/9f5202a501f8cc2375be68908c6fbd0249ac3dd1) + +## Improvements +- Updated base image to `judge0/api-base:1.0.0` which uses [Debian "buster"](https://www.debian.org/releases/buster/) and has installed Ruby 2.7.0. + - Issues: [#113](https://github.com/judge0/api/issues/113) + - Commits: [@f86a546c](https://github.com/judge0/api/commit/f86a546cb9c90eeaedf08862d2a2a2a76293a87f) +- Improved handling of an server error when one or more submission attributes cannot be serialized to JSON without Base64 encoding. User now gets an error with instructions to use `base64_encoded=true` query parameter. + - Issues: [#107](https://github.com/judge0/api/issues/107) [#129](https://github.com/judge0/api/issues/129) [#130](https://github.com/judge0/api/issues/130) + - Commits: [@cdcaa512](https://github.com/judge0/api/commit/cdcaa5122f96c90c0a9fcd16273a808c0ff06d4e) + +## Bug Fixes +- Fixed example in configuration for using `ALLOW_ORIGIN` variable with multiple origins. + - Commits: [@21d0202a](https://github.com/judge0/api/commit/21d0202ae16aa2e92853d146ba8fedb0c6bb6ab2) +- Fixed a bug where value of `MAX_MAX_PROCESSES_AND_OR_THREADS` was used as default value for `max_processes_and_or_threads` attribute of submission, whereas `MAX_PROCESSES_AND_OR_THREADS` should be used. + - Commits: [@563f8ea2](https://github.com/judge0/api/commit/563f8ea264dad9396b4e7743cef187c785cbee67) + +## Other Changes +- Increased maximum allowed `compiler_options` and `command_line_arguments` length to 512 characters. + - Issues: [#122](https://github.com/judge0/api/issues/122) + - Commits: [@3d4df3bf](https://github.com/judge0/api/commit/3d4df3bfe661ddff9ee7e6c015fa4403baf8be85) +- Increased default value of `MAX_PROCESSES_AND_OR_THREADS` to 60. + - Commits: [@563f8ea2](https://github.com/judge0/api/commit/563f8ea264dad9396b4e7743cef187c785cbee67) +- Increased default value of `MAX_MAX_PROCESSES_AND_OR_THREADS` to 120. + - Commits: [@563f8ea2](https://github.com/judge0/api/commit/563f8ea264dad9396b4e7743cef187c785cbee67) +- Changed default value of `RAILS_ENV` to `production`. + - Commits: [@be55ca65](https://github.com/judge0/api/commit/be55ca656b524c5e99e75bd6d6207c4a078f5689) +- Changed default value of `INTERVAL` to 0.1. + - Commits: [@be55ca65](https://github.com/judge0/api/commit/be55ca656b524c5e99e75bd6d6207c4a078f5689) +- Updated year in LICENSE. + - Commits: [@679fb2ba](https://github.com/judge0/api/commit/679fb2bad981a22dcaebdd63baff506678b36939) +- Added environment variables `JUDGE0_{HOMEPAGE,SOURCE_CODE,MAINTAINER,VERSION}`. Isolate sandbox inherits these variables and they are now available for use in user code. + - Commits: [@9f5202a5](https://github.com/judge0/api/commit/9f5202a501f8cc2375be68908c6fbd0249ac3dd1) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.5.0/judge0-api-v1.5.0.zip +unzip judge0-api-v1.5.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.5.0 +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 API v1.5.0 is now available at `http://:3000`. + + +# v1.4.0 (2019-10-31) +## New Features +- Added support for `compiler_options` and `command_line_arguments`. +- Added configuration variables `ENABLE_COMPILER_OPTIONS`, `ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS` and `ENABLE_COMMAND_LINE_ARGUMENTS` for controlling usage of compiler options and command line arguments. + +## Security Improvements +- Run compilation process for compiled languages inside sandbox and use values of *limit configuration variables* for controlling sandbox resources. +- Move application location from `/usr/src/api` to `/api` to prevent untrusted code from reading it. + - Commits: [@0f1b07fe](https://github.com/judge0/api/commit/0f1b07fe0f75141ec82431ef28ad939d73e418a3) + +## Other Changes +- Don't link math library for C language by default. You now need to send `-lm` in `compiler_options`. + - Commits: [@619a3bbe](https://github.com/judge0/api/commit/619a3bbed204b22c71e012f0de0faabf6f846d70) + + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.4.0/judge0-api-v1.4.0.zip +unzip judge0-api-v1.4.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.4.0 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.4.0 is now available at `http://:3000`. + + +# v1.3.1 (2019-09-16) +## Improvements +- Improved handling exec format error by introducing new status **Exec Format Error**. + - Commits: [@93a60115](https://github.com/judge0/api/commit/93a601159187d67d1ca52e8c06ebecd8318ed6c3) + +## Bug Fixes +- Fixed bug where execution of Go code with no `main` package would induce `execve("./main"): No such file or directory` because Go compiler wouldn't create `main` binary. + - Commits: [@93a60115](https://github.com/judge0/api/commit/93a601159187d67d1ca52e8c06ebecd8318ed6c3) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.3.1/judge0-api-v1.3.1.zip +unzip judge0-api-v1.3.1.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.3.1 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.3.1 is now available at `http://:3000`. + + +# v1.3.0 (2019-09-15) +## New Features +- Added `MAX_QUEUE_SIZE` variable that defines a maximum submission queue size. If there is a new submission request and the queue is full, then that submission will be rejected. + - Commits: [@a2bcdecb](https://github.com/judge0/api/commit/a2bcdecbb99dbd8d3875e2f95bdf71f12e34f495) + +## Improvements +- Improved worker shutdown procedure. Workers are now gracefully shutdown on `docker stop`. + - Commits: [@2ae0cd31](https://github.com/judge0/api/commit/2ae0cd31153dca4218638096d390ee6f84896236) + +## Bug Fixes +- Fixed a bug where authentication token was auto converted to integer. + - Issues: [#101](https://github.com/judge0/api/issues/101) + - Commits: [@b92c4970](https://github.com/judge0/api/commit/b92c49705c687e955f91dc6638015f14bbcad97c) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.3.0/judge0-api-v1.3.0.zip +unzip judge0-api-v1.3.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.3.0 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.3.0 is now available at `http://:3000`. + + +# v1.2.2 (2019-09-07) +## Securty Fixes +- Fixed a bug that allowed anybody to read `judge0-api.conf` file. This bug was introduced in version [v1.2.1](https://github.com/judge0/api/releases/tag/v1.2.1) when config was mounted into container. With this fix, config is still mounted into container but not in `/usr/src/api` folder but rather in `/`. Root folder is not binded in isolate sandbox, whereas `/usr/src/api` is. + - Commits: [@121c8f9d](https://github.com/judge0/api/commit/121c8f9de8d89b45c5fec69266d625b375e3181e) + +## Other Changes +- Don't allow execution of scripts in `/usr/src/api` folder. + - Commits: [@121c8f9d](https://github.com/judge0/api/commit/121c8f9de8d89b45c5fec69266d625b375e3181e) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.2.2/judge0-api-v1.2.2.zip +unzip judge0-api-v1.2.2.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.2.2 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.2.2 is now available at `http://:3000`. + + +# v1.2.1 (2019-08-24) +## Improvements +- Improved config loading. Config can now be changed and reload just with `docker-compose restart` command. + - Commits: [@06fc37f1](https://github.com/judge0/api/commit/06fc37f16571840e87c41658807da20a08358926) + +## Bug Fixes +- Fixed bug in `run-worker` script that didn't consider `COUNT` config variable. + - Issues: [#91](https://github.com/judge0/api/issues/91) + - Commits: [@06fc37f1](https://github.com/judge0/api/commit/06fc37f16571840e87c41658807da20a08358926) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.2.1/judge0-api-v1.2.1.zip +unzip judge0-api-v1.2.1.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.2.1 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.2.1 is now available at `http://:3000`. + + +# v1.2.0-nim0.20.0 (2019-06-26) +This image contains only [The Nim Programming Language](https://nim-lang.org). Free public instance of this image is available on https://nim.api.judge0.com. + +This image was build for the purpose of creating dedicated web playground for this language, and in the future I will add and deploy every new release of it. In the [`nim`](https://github.com/judge0/api-base/tree/nim) branch of Judge0 API Base I will follow and install new releases of Nim, and in the [`nim`](https://github.com/judge0/api/tree/nim) branch of Judge0 API I will maintain a Judge0 API that only has Nim available. + +Free playground for the Nim programming language that uses Judge0 API is available at https://nim.ide.judge0.com. + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.2.0-nim0.20.0/judge0-api-v1.2.0-nim0.20.0.zip +unzip judge0-api-v1.2.0-nim0.20.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.2.0-nim0.20.0 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.2.0-nim0.20.0 is now available at `http://:3000`. + + +# v1.2.0-vlang0.1.3 (2019-06-26) +This image contains only [The V Programming Language](https://vlang.io), specifically only V compiler built from commit [@b00a47be](https://github.com/vlang/v/commit/b00a47be66e868b087146feb7999fd72f2af3da0). Free public instance of this image is available on https://vlang.api.judge0.com. + +This image was build for the purpose of creating dedicated web playground for this new programming language, and in the future I will add and deploy every new release of it. In the [`vlang`](https://github.com/judge0/api-base/tree/vlang) branch of Judge0 API Base I will follow and install new releases of V, and in the [`vlang`](https://github.com/judge0/api/tree/vlang) branch of Judge0 API I will maintain a Judge0 API that only has V available. + +Free playground for the V programming language that uses Judge0 API is available at https://vlang.ide.judge0.com. + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.2.0-vlang0.1.3/judge0-api-v1.2.0-vlang0.1.3.zip +unzip judge0-api-v1.2.0-vlang0.1.3.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.2.0-vlang0.1.3 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.2.0-vlang0.1.3 is now available at `http://:3000`. + + +# v1.2.0 (2019-06-17) +## New Features +- Added new language **Executable** that allows executing custom executable files. + - Commits: [@0ab08351](https://github.com/judge0/api/commit/0ab08351f59ae75d9626b6941be3728b48e835db) +- Added new configuration variables: `REDIS_PASSWORD`, `REDIS_PORT` and `POSTGRES_PORT`. + - Commits: [@962d7d1d](https://github.com/judge0/api/commit/962d7d1dcff051357de492f2d31e996405b1d125) + +## Improvements +- Improved `run-server` and `run-worker` scripts. + - Commits: [@e1b3564b](https://github.com/judge0/api/commit/e1b3564b5f262c610c42a45879e313eca93e720f) + +## Bug Fixes +- Fixed `/etc/apt/sources.list` that prevented package update. + - Issues: [#84](https://github.com/judge0/api/issues/84) + - Commits: [@7fdca3cf](https://github.com/judge0/api/commit/7fdca3cfa5f3bddefbe2ae1e12a18ba18a7e5f63) +- Fixed cleanup bug that didn't remove sandbox files if `tmp` directory was not empty. + - Commits: [@50ee4dbf](https://github.com/judge0/api/commit/50ee4dbf841bc9d0ce195380aaa1c5ee957ee2b7) +- Fixed another UTF-8 problem with Python that @nguyenvanquan7826 reported. + - Issues: [#69](https://github.com/judge0/api/issues/69) + - Commits: [@64635c98](https://github.com/judge0/api/commit/64635c98f7c0475e33b9b4629a6da8bc20fff60a) + +## Other Changes +- Updated some gems that had security issues. + - Pull Requests: [#77](https://github.com/judge0/api/pull/77) [#78](https://github.com/judge0/api/pull/78) [#79](https://github.com/judge0/api/pull/79) [#80](https://github.com/judge0/api/pull/80) [#81](https://github.com/judge0/api/pull/81) [#82](https://github.com/judge0/api/pull/82) + - Commits: [@e1b3564b](https://github.com/judge0/api/commit/e1b3564b5f262c610c42a45879e313eca93e720f) +- Prepared Isolate Job for accepting custom compile flags. + - Commits: [@4f2dde1f](https://github.com/judge0/api/commit/4f2dde1f79e32545da219de5cea7c5aaf25869cb) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.2.0/judge0-api-v1.2.0.zip +unzip judge0-api-v1.2.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.2.0 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.2.0 is now available at `http://:3000`. + + +# v1.1.5-python3.6.8 (2019-03-08) +On @guvenim [request](https://github.com/judge0/api/issues/67) I have built an Judge0 API image that contains just Python 3.6.8. This release also shows what changes are necessary in [api-base](https://github.com/judge0/api-base/commit/bfde9426e4a3d44098dab2a2d082e02de2bc5be5) and [api](https://github.com/judge0/api/commit/9f9f5cd0577a724d66be934c11d2e57b2b3fc705) when you only want to use languages that you need. + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.5-python3.6.8/judge0-api-v1.1.5-python3.6.8.zip +unzip judge0-api-v1.1.5-python3.6.8.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.5-python3.6.8 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.5-python3.6.8 is now available at `http://:3000`. + + +# v1.1.5 (2019-02-17) +## Bug Fixes +- Fixed problem with assigning compile output to submission when rerunning submission. + - Commits: [@c3cd0232](https://github.com/judge0/api/commit/c3cd023258a4ec48949d4ee2310bc39a2f40cac9) + +## Other Changes +- Remove unwanted newlines from compile output. + - Commits: [@c3cd0232](https://github.com/judge0/api/commit/c3cd023258a4ec48949d4ee2310bc39a2f40cac9) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.5/judge0-api-v1.1.5.zip +unzip judge0-api-v1.1.5.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.5 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.5 is now available at `http://:3000`. + + +# v1.1.4 (2019-02-17) +## Bug Fixes +- Fixed problem with assigning compile output to submission when compile output is not empty. + - Commits: [@22403707](https://github.com/judge0/api/commit/224037078325dfe02f5fbf191a55513582ca84b5) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.4/judge0-api-v1.1.4.zip +unzip judge0-api-v1.1.4.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.4 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.4 is now available at `http://:3000`. + + +# v1.1.3 (2019-02-15) +## Improvements +- Improved cleanup of sandbox by deleting stdin, stdout, stderr and meta file before running isolate cleanup. + - Commits: [@1dcfaf98](https://github.com/judge0/api/commit/1dcfaf98536fc55fe200c57de10540de64936654) + +## Bug Fixes +- Fixed problem with compile output that contained invalid byte sequence in UTF-8. + - Commits: [@37d46b14](https://github.com/judge0/api/commit/37d46b140c75aaafeca35ffc36e53746e0905387) +- Fixed problem with submissions not changing their post-run attributes after rerun if compile error occured. + - Commits: [@37d46b14](https://github.com/judge0/api/commit/37d46b140c75aaafeca35ffc36e53746e0905387) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.3/judge0-api-v1.1.3.zip +unzip judge0-api-v1.1.3.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.3 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.3 is now available at `http://:3000`. + + +# v1.1.2 (2019-02-15) +## Improvements +- Improved reading from stdin and writing to stdout, stderr and meta. They are now not available in sandbox. + - Commits: [@1f135c1a](https://github.com/judge0/api/commit/1f135c1a53f5039b52de5e9c78764c80a7ed3945) [@350ff3a4](https://github.com/judge0/api/commit/350ff3a4705b6d83ef4f1188de52586cbb87e693) + +## Bug Fixes +- Fixed writing of source code and stdin to disc, they are now written as binary files to avoid UTF-8 problems. + - Commits: [@519efbea](https://github.com/judge0/api/commit/519efbea1548f9dab5a95032af2cfa88fc319c65) +- Fixed problem with stripping output that contained invalid byte sequence in UTF-8. + - Commits: [@4c994c67](https://github.com/judge0/api/commit/4c994c67630d6679a636a656ba0041ba6a680219) + +## Other Changes +- Use `judge0/api-base:0.3.0` as base image which uses [isolate@18554e83](https://github.com/ioi/isolate/commit/18554e83793508acd1032d0cf4229a332c43085e). + - Commits: [@350ff3a4](https://github.com/judge0/api/commit/350ff3a4705b6d83ef4f1188de52586cbb87e693) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.2/judge0-api-v1.1.2.zip +unzip judge0-api-v1.1.2.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.2 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.2 is now available at `http://:3000`. + + +# v1.1.1 (2019-02-13) +## Bug Fixes +- Fixed a problem when `strip` method was called on a `nil` class when expected output was `nil`. + - Commits: [@b25153e9](https://github.com/judge0/api/commit/b25153e9450569c995e8f3afe036fed4ad58726c) + +## Other Changes +- Don't let worker update submission's `finished_at` attribute if it already exists. This allows Judge0 API administrators to manually rerun submissions from command line and preserve initial timestamps if some unexpected error occured. + - Commits: [@b25153e9](https://github.com/judge0/api/commit/b25153e9450569c995e8f3afe036fed4ad58726c) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.1/judge0-api-v1.1.1.zip +unzip judge0-api-v1.1.1.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.1 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.1.1 is now available at `http://:3000`. + + +# v1.1.0 (2019-02-10) +## New Features +- Added `-lm` compile flag to link with math library when compiling C source code. + - Pull Requests: [#60](https://github.com/judge0/api/pull/60) +- Added fixed time limit of 10 seconds for compilation. + - Issues: [#63](https://github.com/judge0/api/issues/63) [#64](https://github.com/judge0/api/issues/64) + - Commits: [@2f05ce2c](https://github.com/judge0/api/commit/2f05ce2c9305fccaeb0c08e23d645736593d787e) + +## Improvements +- Improved procedure of seeding database with languages. Seeding is now idempotent. + - Commits: [@72cff961](https://github.com/judge0/api/commit/72cff9616db20bed128a38111e3c28dbfc75696e) + +## Bux Fixes +- Fixed versions of Postgres and Redis in Docker Compose files. + - Issues: [#20](https://github.com/judge0/api/issues/20) [#38](https://github.com/judge0/api/issues/38) [#40](https://github.com/judge0/api/issues/40) [#45](https://github.com/judge0/api/issues/45) [#47](https://github.com/judge0/api/issues/47) [#56](https://github.com/judge0/api/issues/56) [#57](https://github.com/judge0/api/issues/57) + - Commits: [@80a61629](https://github.com/judge0/api/commit/80a61629129af75e1d8a4bb167b349ab34cabfd3) [@90ec40cf](https://github.com/judge0/api/commit/90ec40cf5b4dc2ca6aa4c3af59326d431530cf80) +- Fixed problem with workers stopping when they lost connection with Postgres or Redis. + - Commits: [@eee340b6](https://github.com/judge0/api/commit/eee340b650aeacc7971ce5e73652a7bfa9e243af) +- Fixed problem of storing submission's stdout and stderr that contained invalid byte sequence in UTF-8. + - Commits: [@ff63c1bc](https://github.com/judge0/api/commit/ff63c1bc498a62101d4c074f5aa7b7a971550164) + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.1.0/judge0-api-v1.1.0.zip +unzip judge0-api-v1.1.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.1.0 +docker-compose up -d +sleep 10s +``` + + +# v1.0.0 (2017-10-01) +This is the first production ready release of Judge0 API. + +## Deployment Procedure +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract release archive: +``` +wget https://github.com/judge0/api/releases/download/v1.0.0/judge0-api-v1.0.0.zip +unzip judge0-api-v1.0.0.zip +``` + +3. Run all services and wait few seconds until everything is initialized: +``` +cd judge0-api-v1.0.0 +docker-compose up -d +sleep 10s +``` + +4. Your instance of Judge0 API v1.0.0 is now available at `http://:3000`. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000000000000000000000000000000000..bbeaaeab7751b166152dc7d58b7c450deb0742cb --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at hermanz.dosilovic@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..4d596e8ccf3c871a53b97f17ad161129128d4528 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM judge0/compilers:1.4.0 AS production + +ENV JUDGE0_HOMEPAGE "https://judge0.com" +LABEL homepage=$JUDGE0_HOMEPAGE + +ENV JUDGE0_SOURCE_CODE "https://github.com/judge0/judge0" +LABEL source_code=$JUDGE0_SOURCE_CODE + +ENV JUDGE0_MAINTAINER "Herman Zvonimir Došilović " +LABEL maintainer=$JUDGE0_MAINTAINER + +ENV PATH "/usr/local/ruby-2.7.0/bin:/opt/.gem/bin:$PATH" +ENV GEM_HOME "/opt/.gem/" + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + cron \ + libpq-dev \ + sudo && \ + rm -rf /var/lib/apt/lists/* && \ + echo "gem: --no-document" > /root/.gemrc && \ + gem install bundler:2.1.4 && \ + npm install -g --unsafe-perm aglio@2.3.0 + +EXPOSE 2358 + +WORKDIR /api + +COPY Gemfile* ./ +RUN RAILS_ENV=production bundle + +COPY cron /etc/cron.d +RUN cat /etc/cron.d/* | crontab - + +COPY . . + +ENTRYPOINT ["/api/docker-entrypoint.sh"] +CMD ["/api/scripts/server"] + +RUN useradd -u 1000 -m -r judge0 && \ + echo "judge0 ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers && \ + chown judge0: /api/tmp/ + +USER judge0 + +ENV JUDGE0_VERSION "1.13.1" +LABEL version=$JUDGE0_VERSION + + +FROM production AS development + +CMD ["sleep", "infinity"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000000000000000000000000000000000..86c9b5db669c44b2dd875b899878e02b5e21c856 --- /dev/null +++ b/Gemfile @@ -0,0 +1,21 @@ +source 'https://rubygems.org' + +gem 'rails', '~> 6.1' +gem 'pg', '~> 1.2' + +gem 'active_model_serializers', '~> 0.10' +gem 'enumerations', '~> 2.3' +gem 'httparty', '~> 0.21' +gem 'pry-byebug', '~> 3.9' +gem 'pry-rails', '~> 0.3' +gem 'puma', '~> 5.6' +gem 'rack-cors', '~> 1.1' +gem 'redis', '< 4.6' +gem 'resque', '~> 2.6' +gem 'resque-scheduler', '~> 4.10' +gem 'will_paginate', '~> 3.2' + +group :development do + gem 'annotate', '~> 3.0' + gem 'listen', '~> 3.2' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000000000000000000000000000000000..4498ddb5650174d5a40e6e93698b9306b2e48af0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,244 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.1.7.7) + actionpack (= 6.1.7.7) + activesupport (= 6.1.7.7) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.7.7) + actionpack (= 6.1.7.7) + activejob (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) + mail (>= 2.7.1) + actionmailer (6.1.7.7) + actionpack (= 6.1.7.7) + actionview (= 6.1.7.7) + activejob (= 6.1.7.7) + activesupport (= 6.1.7.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.1.7.7) + actionview (= 6.1.7.7) + activesupport (= 6.1.7.7) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7.7) + actionpack (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) + nokogiri (>= 1.8.5) + actionview (6.1.7.7) + activesupport (= 6.1.7.7) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_model_serializers (0.10.13) + actionpack (>= 4.1, < 7.1) + activemodel (>= 4.1, < 7.1) + case_transform (>= 0.2) + jsonapi-renderer (>= 0.1.1.beta1, < 0.3) + activejob (6.1.7.7) + activesupport (= 6.1.7.7) + globalid (>= 0.3.6) + activemodel (6.1.7.7) + activesupport (= 6.1.7.7) + activerecord (6.1.7.7) + activemodel (= 6.1.7.7) + activesupport (= 6.1.7.7) + activestorage (6.1.7.7) + actionpack (= 6.1.7.7) + activejob (= 6.1.7.7) + activerecord (= 6.1.7.7) + activesupport (= 6.1.7.7) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) + builder (3.2.4) + byebug (11.1.3) + case_transform (0.2) + activesupport + coderay (1.1.3) + concurrent-ruby (1.2.3) + crass (1.0.6) + date (3.3.4) + enumerations (2.5.3) + activerecord + activesupport + i18n + erubi (1.12.0) + et-orbi (1.2.7) + tzinfo + ffi (1.15.5) + fugit (1.9.0) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) + httparty (0.21.0) + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + jsonapi-renderer (0.2.2) + listen (3.7.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.5) + mini_portile2 (2.8.5) + minitest (5.22.2) + mono_logger (1.1.2) + multi_json (1.15.0) + multi_xml (0.6.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) + net-imap (0.3.7) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.14.5) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + pg (1.3.5) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + puma (5.6.8) + nio4r (~> 2.0) + raabro (1.4.0) + racc (1.7.3) + rack (2.2.8.1) + rack-cors (1.1.1) + rack (>= 2.0.0) + rack-protection (3.1.0) + rack (~> 2.2, >= 2.2.4) + rack-test (2.1.0) + rack (>= 1.3) + rails (6.1.7.7) + actioncable (= 6.1.7.7) + actionmailbox (= 6.1.7.7) + actionmailer (= 6.1.7.7) + actionpack (= 6.1.7.7) + actiontext (= 6.1.7.7) + actionview (= 6.1.7.7) + activejob (= 6.1.7.7) + activemodel (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) + bundler (>= 1.15.0) + railties (= 6.1.7.7) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.1.7.7) + actionpack (= 6.1.7.7) + activesupport (= 6.1.7.7) + method_source + rake (>= 12.2) + thor (~> 1.0) + rake (13.1.0) + rb-fsevent (0.11.1) + rb-inotify (0.10.1) + ffi (~> 1.0) + redis (4.5.1) + redis-namespace (1.11.0) + redis (>= 4) + resque (2.6.0) + mono_logger (~> 1.0) + multi_json (~> 1.0) + redis-namespace (~> 1.6) + sinatra (>= 0.9.2) + resque-scheduler (4.10.2) + mono_logger (~> 1.0) + redis (>= 3.3) + resque (>= 1.27) + rufus-scheduler (~> 3.2, != 3.3) + ruby2_keywords (0.0.5) + rufus-scheduler (3.9.1) + fugit (~> 1.1, >= 1.1.6) + sinatra (3.1.0) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.1.0) + tilt (~> 2.0) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + thor (1.3.1) + tilt (2.3.0) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + will_paginate (3.3.1) + zeitwerk (2.6.13) + +PLATFORMS + ruby + +DEPENDENCIES + active_model_serializers (~> 0.10) + annotate (~> 3.0) + enumerations (~> 2.3) + httparty (~> 0.21) + listen (~> 3.2) + pg (~> 1.2) + pry-byebug (~> 3.9) + pry-rails (~> 0.3) + puma (~> 5.6) + rack-cors (~> 1.1) + rails (~> 6.1) + redis (< 4.6) + resque (~> 2.6) + resque-scheduler (~> 4.10) + will_paginate (~> 3.2) + +BUNDLED WITH + 2.1.4 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..1034b36f09ce69a358817015eaa91dbff744ef26 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The GNU General Public License is a free, copyleft license for +software and other kinds of works. + +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + +Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + +Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + +0. Definitions. + +"This License" refers to version 3 of the GNU General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based +on the Program. + +To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +1. Source Code. + +The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + +A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + +The Corresponding Source for a work in source code form is that +same work. + +2. Basic Permissions. + +All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + +When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + +a) The work must carry prominent notices stating that you modified +it, and giving a relevant date. + +b) The work must carry prominent notices stating that it is +released under this License and any conditions added under section +7. This requirement modifies the requirement in section 4 to +"keep intact all notices". + +c) You must license the entire work, as a whole, under this +License to anyone who comes into possession of a copy. This +License will therefore apply, along with any applicable section 7 +additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no +permission to license the work in any other way, but it does not +invalidate such permission if you have separately received it. + +d) If the work has interactive user interfaces, each must display +Appropriate Legal Notices; however, if the Program has interactive +interfaces that do not display Appropriate Legal Notices, your +work need not make them do so. + +A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + +a) Convey the object code in, or embodied in, a physical product +(including a physical distribution medium), accompanied by the +Corresponding Source fixed on a durable physical medium +customarily used for software interchange. + +b) Convey the object code in, or embodied in, a physical product +(including a physical distribution medium), accompanied by a +written offer, valid for at least three years and valid for as +long as you offer spare parts or customer support for that product +model, to give anyone who possesses the object code either (1) a +copy of the Corresponding Source for all the software in the +product that is covered by this License, on a durable physical +medium customarily used for software interchange, for a price no +more than your reasonable cost of physically performing this +conveying of source, or (2) access to copy the +Corresponding Source from a network server at no charge. + +c) Convey individual copies of the object code with a copy of the +written offer to provide the Corresponding Source. This +alternative is allowed only occasionally and noncommercially, and +only if you received the object code with such an offer, in accord +with subsection 6b. + +d) Convey the object code by offering access from a designated +place (gratis or for a charge), and offer equivalent access to the +Corresponding Source in the same way through the same place at no +further charge. You need not require recipients to copy the +Corresponding Source along with the object code. If the place to +copy the object code is a network server, the Corresponding Source +may be on a different server (operated by you or a third party) +that supports equivalent copying facilities, provided you maintain +clear directions next to the object code saying where to find the +Corresponding Source. Regardless of what server hosts the +Corresponding Source, you remain obligated to ensure that it is +available for as long as needed to satisfy these requirements. + +e) Convey the object code using peer-to-peer transmission, provided +you inform other peers where the object code and Corresponding +Source of the work are being offered to the general public at no +charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + +If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + +The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + +7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + +a) Disclaiming warranty or limiting liability differently from the +terms of sections 15 and 16 of this License; or + +b) Requiring preservation of specified reasonable legal notices or +author attributions in that material or in the Appropriate Legal +Notices displayed by works containing it; or + +c) Prohibiting misrepresentation of the origin of that material, or +requiring that modified versions of such material be marked in +reasonable ways as different from the original version; or + +d) Limiting the use for publicity purposes of names of licensors or +authors of the material; or + +e) Declining to grant rights under trademark law for use of some +trade names, trademarks, or service marks; or + +f) Requiring indemnification of licensors and authors of that +material by anyone who conveys the material (or modified versions of +it) with contractual assumptions of liability to the recipient, for +any liability that these contractual assumptions directly impose on +those licensors and authors. + +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + +However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + +If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + +A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + +Judge0 is a robust and scalable open-source online code execution system. +Copyright (C) 2016-2020 Herman Zvonimir Došilović + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + +Judge0 Copyright (C) 2016-2020 Herman Zvonimir Došilović +This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + +You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + +The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/PRIVACY_POLICY.md b/PRIVACY_POLICY.md new file mode 100644 index 0000000000000000000000000000000000000000..1d7d69635f02f7cd37575274d7f651b08e917ab8 --- /dev/null +++ b/PRIVACY_POLICY.md @@ -0,0 +1,9 @@ +# Privacy Policy +This document is for those who consume Judge0 and not for those who deploy Judge0 to their own infrastructure. + +If you deploy Judge0 to your own infrastructure then you should read about [telemetry](TELEMETRY.md). + +## Collected Data +Judge0 does **not** store any personal information. + +For every submission Judge0 stores the data that has been well documented [here](https://api.judge0.com/#submissions-submission). \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000000000000000000000000000000000..f9a6598546e8f674675fc07ef5560546ad29c85b --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +require_relative 'config/application' +require 'resque/tasks' +require 'resque/scheduler/tasks' + +task 'resque:setup' => :environment + +Rails.application.load_tasks diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000000000000000000000000000000000..7822e0268192f25d1febf08b7fa293aae54d3990 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,16 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ---------------- | ------------------ | +| >= 1.13.0 | :white_check_mark: | +| >= 1.13.0-extra | :white_check_mark: | +| < 1.13.0 | :x: | +| < 1.13.0-extra | :x: | + +## Reporting a Vulnerability + +Please report vulnerability via GitHub or email at security@judge0.com. + +Your reports will be reviewed ASAP, and an update will also be released ASAP. diff --git a/SPONSORSHIP.md b/SPONSORSHIP.md new file mode 100644 index 0000000000000000000000000000000000000000..3bf69a0ded341a6df412f8e22d375f56960fa6ac --- /dev/null +++ b/SPONSORSHIP.md @@ -0,0 +1,85 @@ +# Sponsorship +Thank you for considering supporting this project and thus [me](https://github.com/hermanzdosilovic) and my work. There are many ways you can support this project and you might have different motivation or reason to do so. Whatever your reason or motivation is, thank you! + +Every donation is valuable and helps me keep this project free and open-source for everybody. + +## Common Support +You can support this project by becoming a [Patron](https://www.patreon.com/hermanzdosilovic) or by donating via [PayPal](https://www.patreon.com/hermanzdosilovic) or [Revolut](https://pay.revolut.com/profile/hermancy5). + +This is the simplest yet very welcome and significant way for you to express your appreciation and support the project with your monthly or one-time donation. + +Thank you! + +## Development Sponsorship +You can directly sponsor the development of the features, bug fixes or anything that is important to you, your organization or company. For the sake of simplicity in the following text I will just reffer to "features", but remember that it can be anything that you want to see in the project. + +Sponsored features are put on the top of the [priority list](https://github.com/judge0/judge0/projects) for one of the next releases and push the development forward by reducing the release cycles. + +### Sponsorship Protocol +The protocol for development sponsorship is described below. Described protocol is based on two assumptions: +1. You trust me. I will do the work in the agreed deadline. +2. I trust you. You will donate agreed amount after the work is done. + +Moreover, with the following protocol I want to keep everything transparent as possible and in the spirit of the open-source values. + +#### 1. Issue Creation +Create a new or choose an existing issue on the [Issues](https://github.com/judge0/judge0/issues) page. It can be anything from feature request, bug fix or documentation update. It can be anything that you would like to see in one of the next releases as soon as possible. + +#### 2. Declare Sponsorship +Add a comment that you, your organization or company is willing to sponsor the development of this feature: + +``` +This feature will be sponsored by [me|ORGANIZATION NAME](URL). +``` + +It is important to note who is sponsoring the feature because the name of the sponsor (with the given URL) will be written in the release notes. + +If you, however, want to stay anonymous then comment: +``` +This feature will be anonymously sponsored. +``` + +Even though the feature is anonymously sponsored it will be noted as such in the release notes. + +#### 3. (Optional) Specify Your Deadline +If you have a deadline you want me to meet, please specify it. It can be anything from 1 day to 1 year. + +#### 4. Review and Validation +I will then review the feature request and iteratate further with you on its specification before we agree on what exactly will be developed. + +This step is important because I want to develop exactly what you are asking for, so we need to be on the same page. + +I have a full right to reject and close the issue at any point if it does not match my vision of the direction in which the project should go. + +#### 5. Deadline and Offer +I will then tell you in what release this feature can be included and when it can be released. I will also specify the donation amount required for this feature to be developed and released by specified deadline. + +Note that even one sponsored feature can make me do a new release. + +#### 6. Accept or Reject +You can then accept or reject my donation request: +``` +I [accept|reject] your donation request and deadline. +``` + +Note that if you reject my donation request it doesn't mean that the issue won't be resolved. It just means that it won't be put on the priority list for the next release. It will be treated as any other issue (non sponsored). + +If you accept my donation request I will add a label `sponsored` on the issue and forward it for the next stage on [Projects](https://github.com/judge0/judge0/projects) page. + +#### 7. Development and Testing +In the development and testing phase I will sometimes send you links to where you can try the new feature. + +For some issues this might not be necessary. + +#### 8. Release +After the development the issue will be closed and the feature will be released in the specified release cycle within agreed deadline. + +After the release I expect you to send the agreed donation amount via [PayPal](https://www.patreon.com/hermanzdosilovic) or [Revolut](https://pay.revolut.com/profile/hermancy5). You can also do this after sixth step. + +### Notes +1. Sponsored features **must** stay open-source. +2. One feature can be sponsored by many sponsors. +3. One sponsor can sponsor many features. + +## Other Types of Sponsorships +If you have any other suggestions on how you would like to collaborate or support this project, please send me an [email](https://github.com/hermanzdosilovic) or schedule a [meeting](https://judge0.appointlet.com) with me. \ No newline at end of file diff --git a/TELEMETRY.md b/TELEMETRY.md new file mode 100644 index 0000000000000000000000000000000000000000..7507da52c478b62983ff759d85ce0083a581dec4 --- /dev/null +++ b/TELEMETRY.md @@ -0,0 +1,36 @@ +# Telemetry +This document is for those who deploy Judge0 to their own infrastructure and not for those who consume Judge0. + +If you just consume Judge0 then you should read the [privacy policy](PRIVACY_POLICY.md). + +## Introduction +Since version v1.6.0 Judge0 is collecting telemetry data which is used to help understand how to improve the product and to better understand how Judge0 is used in various production environments. + +Our close-source [telemetry client](bin/telemetry) periodically sends telemetry data to our central telemetry server. + +Telemetry reporting is **enabled** by default. + +This document describes how to disable telemetry reporting and what data is collected. + +## Disabling Telemetry Reporting +To disable telemetry reporting set variable `JUDGE0_TELEMETRY_ENABLE` to `false` in [judge0.conf](judge0.conf). + +## Collected Data +Every deployed instance of Judge0 with enabled telemetry reporting has its own ID that is used to identify the instance. + +### The Data Telemetry Client Sends +Your instance of Judge0 will send the new telemetry report to our central telemetry server every 12 hours. Following data is send in the report: +- the ID of your instance and +- the version of your Judge0 instance + +### The Data Telemetry Server Stores +When the new telemetry report arrives our telemetry server stores the following data: +- all the data that telemetry clients sends and +- timestamp when the report was send + +IP address of your instance is **not** sent or stored. + +Note that only the last report is stored on telemetry server, i.e. the new report overwrites the last report. + +## Other Notes and Information +1. You can disable telemetry reporting at any time but the data from the last report stays stored on the telemetry server. \ No newline at end of file diff --git a/agricius b/agricius new file mode 100644 index 0000000000000000000000000000000000000000..3b56d7aa69ded4a416ea8a0e2b0cef6f9ac958a9 --- /dev/null +++ b/agricius @@ -0,0 +1,128 @@ +#!/bin/bash +# +# Agricius - build tool for Judge0. +# +# Named after Saint Agricius of Trier - protector of carpenters, builders, confectioners, blacksmiths, tailors and butchers. + +_err() { + echo >&2 "Error: $*" +} + +_die() { + _err "$*" + exit 1 +} + +__get_argument() { + if [[ -n "$2" ]] && [[ ${2:0:1} != "-" ]]; then + echo "$2" + else + _err "Argument for $1 is missing." + fi +} + +_positional_params="" +while [[ $# -gt 0 ]]; do + case "$1" in + --cache-from) + _cache="$(__get_argument $1 $2)"; [[ "$_cache" == "" ]] && exit 1 + shift 2 + ;; + -*|--*) + _die "Unknown option $1. +Usage: $0 [--cache-from image] command + +Available commands: + build Build Docker images. + publish Push Docker images to repository. Implies build." + ;; + *) + _positional_params="$_positional_params $1" + shift + ;; + esac +done +eval set -- "$_positional_params" + +if [[ "$_cache" != "" ]]; then + docker pull $_cache + _cache="--cache-from $_cache" +fi + +JUDGE0_DOCKER_REPOSITORY=judge0/judge0 + +JUDGE0_PROJECT_ROOT="$(git rev-parse --show-toplevel)" +JUDGE0_COMMIT="$(git log -1 --format=%h --abbrev=8)" +JUDGE0_BRANCH="$(git rev-parse --abbrev-ref HEAD)" + +JUDGE0_EDITION="$JUDGE0_BRANCH" +if [[ "$JUDGE0_BRANCH" == "master" ]]; then + JUDGE0_EDITION="standard" +fi + +JUDGE0_EDITION_SLUG="-$JUDGE0_EDITION" +if [[ "$JUDGE0_EDITION" == "standard" ]]; then + JUDGE0_EDITION_SLUG="" +fi + +JUDGE0_VERSION_TAG="$(git tag --points-at HEAD)" +JUDGE0_VERSION="${JUDGE0_VERSION_TAG:1}" # Remove the "v" the beginning. +JUDGE0_VERSION="${JUDGE0_VERSION%-*}" # Remove everything else after "-". + +JUDGE0_PRODUCTION_IMAGES="$JUDGE0_DOCKER_REPOSITORY:$JUDGE0_COMMIT$JUDGE0_EDITION_SLUG" +if [[ "$JUDGE0_VERSION" != "" ]]; then + JUDGE0_PRODUCTION_IMAGES="$JUDGE0_PRODUCTION_IMAGES $JUDGE0_DOCKER_REPOSITORY:latest$JUDGE0_EDITION_SLUG" + JUDGE0_PRODUCTION_IMAGES="$JUDGE0_PRODUCTION_IMAGES $JUDGE0_DOCKER_REPOSITORY:$JUDGE0_VERSION$JUDGE0_EDITION_SLUG" +fi + +JUDGE0_DEVELOPMENT_IMAGES="$JUDGE0_DOCKER_REPOSITORY:$JUDGE0_COMMIT-dev$JUDGE0_EDITION_SLUG" +if [[ "$JUDGE0_VERSION" != "" ]]; then + JUDGE0_DEVELOPMENT_IMAGES="$JUDGE0_DEVELOPMENT_IMAGES $JUDGE0_DOCKER_REPOSITORY:latest$JUDGE0_EDITION_SLUG-dev" + JUDGE0_DEVELOPMENT_IMAGES="$JUDGE0_DEVELOPMENT_IMAGES $JUDGE0_DOCKER_REPOSITORY:$JUDGE0_VERSION$JUDGE0_EDITION_SLUG-dev" +fi + +env | grep JUDGE0_ | sort + +pushd "$JUDGE0_PROJECT_ROOT" + +function build_and_tag() { + local _target=$1 + local _images=($2) + local _main_image=${_images[0]} + + set -xe + docker build -t $_main_image $_cache --target $_target . + set +xe + + for (( i=0; i<${#_images[@]}; i++ )) do + docker tag $_main_image ${_images[i]} + done +} +build_and_tag production "$JUDGE0_PRODUCTION_IMAGES" +build_and_tag development "$JUDGE0_DEVELOPMENT_IMAGES" + +_command="$1" +if [[ "$_command" == "publish" ]]; then + if [[ "$JUDGE0_VERSION" == "" ]]; then + _die "Cannot publish untagged version." + fi + _push_images() { + local _images=($1) + for (( i=1; i<${#_images[@]}; i++ )) do + docker push ${_images[i]} + done + } + _push_images "$JUDGE0_PRODUCTION_IMAGES" + _push_images "$JUDGE0_DEVELOPMENT_IMAGES" +fi + +_untag() { + local _images=($1) + for (( i=0; i<${#_images[@]}-1; i++ )) do + docker rmi ${_images[i]} + done +} +_untag "$JUDGE0_PRODUCTION_IMAGES" +_untag "$JUDGE0_DEVELOPMENT_IMAGES" + +popd diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000000000000000000000000000000000..d67269728300b9dac6a4a0db443ece02d7b6c513 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000000000000000000000000000000000..0ff5442f476f98d578f77221b57164cffcf08de0 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..6bdc081d46f0f8e21cc6290e93888fab2e91c9b3 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,13 @@ +class ApplicationController < SessionsController + private + + def pagination_dict(collection) + { + current_page: collection.current_page, + next_page: collection.next_page, + prev_page: collection.previous_page, + total_pages: collection.total_pages, + total_count: collection.total_entries + } + end +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..68188d024ed61a122caaa667a022c3a553482084 --- /dev/null +++ b/app/controllers/health_controller.rb @@ -0,0 +1,27 @@ +class HealthController < ApplicationController + def workers + Resque.workers.first.try(:prune_dead_workers) if params[:prune_dead_workers] == "true" + + queues = Hash.new { |h, k| h[k] = [] } + Resque.workers.each do |worker| + worker.queues.each do |queue| + queues[queue] << worker + end + end + + json = [] + Resque.queues.each do |queue| + workers = queues[queue] + json << { + queue: queue, + size: Resque.size(queue), + available: workers.count, + idle: workers.count { |w| w.idle? }, + working: workers.count { |w| w.working? }, + paused: workers.count { |w| w.paused? } + } + end + + render json: json + end +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..337c57e80484c9c5ab07369167c094196925c5b7 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,11 @@ +class HomeController < ActionController::API + include ActionView::Layouts + + def index + if Config::USE_DOCS_AS_HOMEPAGE + render file: Rails.root.join('public/docs.html') + else + head :ok + end + end +end diff --git a/app/controllers/info_controller.rb b/app/controllers/info_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..d74349868af1b1762a1af23be27bb916cf071fd1 --- /dev/null +++ b/app/controllers/info_controller.rb @@ -0,0 +1,98 @@ +class InfoController < ApplicationController + @@license ||= File.read("LICENSE") + @@isolate ||= `isolate --version` + + def system_info + render json: SystemInfo.sys_info + end + + def config_info + render json: Config.config_info + end + + def about + render json: { + version: ENV["JUDGE0_VERSION"], + homepage: ENV["JUDGE0_HOMEPAGE"], + source_code: ENV["JUDGE0_SOURCE_CODE"], + maintainer: ENV["JUDGE0_MAINTAINER"] + } + end + + def version + render plain: ENV["JUDGE0_VERSION"] + end + + def license + render plain: @@license + end + + def isolate + render plain: @@isolate + end + + def statistics + Rails.cache.delete("statistics") if params[:invalidate_cache] == "true" + @@cache_duration ||= 10.minutes + render json: Rails.cache.fetch("statistics", expires_in: @@cache_duration) { + @@language_name ||= Hash[Language.unscoped.pluck(:id, :name)] + + count_by_language = [] + Submission.unscoped.group(:language_id).count.each do |language_id, count| + count_by_language << { + language: { + id: language_id, + name: @@language_name[language_id] + }, + count: count + } + end + count_by_language = count_by_language.sort_by { |x| x[:count] }.reverse + + count_by_status = [] + Submission.unscoped.group(:status_id).count.each do |status_id, count| + count_by_status << { + status: { + id: status_id, + name: Status.find_by(id: status_id).name # Not a SQL query! + }, + count: count + } + end + count_by_status = count_by_status.sort_by{ |x| x[:count] }.reverse + + now = DateTime.now + today = DateTime.now.beginning_of_day.to_date + last_30_days = Submission.unscoped.group("created_at::DATE").where("created_at::DATE >= ?", today - 30).count + last_30_days[today] ||= 0 + last_30_days_result = {} + (today-30...today).each do |day| + last_30_days_result[day.to_date] = last_30_days[day] || 0 + end + last_30_days_result = last_30_days_result.sort.reverse.to_h + + database_size = ActiveRecord::Base.connection.execute( + "SELECT + pg_size_pretty(pg_database_size('#{ENV['POSTGRES_DB']}')) AS size_pretty, + pg_database_size('#{ENV['POSTGRES_DB']}') AS size_in_bytes + " + ).to_a[0] + + { + created_at: now, + cached_until: now + @@cache_duration, + submissions: { + total: Submission.count, + today: last_30_days[today], + last_30_days: last_30_days_result + }, + languages: count_by_language, + statuses: count_by_status, + database: { + size_pretty: database_size["size_pretty"], + size_in_bytes: database_size["size_in_bytes"] + } + } + } + end +end \ No newline at end of file diff --git a/app/controllers/languages_controller.rb b/app/controllers/languages_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..e35c94f6074527edb3351996174ff597d6e5df8d --- /dev/null +++ b/app/controllers/languages_controller.rb @@ -0,0 +1,13 @@ +class LanguagesController < ApplicationController + def index + render json: Language.all, each_serializer: LanguageSerializer, fields: [:id, :name] + end + + def all + render json: Language.unscoped.order(name: :asc), each_serializer: LanguageSerializer, fields: [:id, :name, :is_archived] + end + + def show + render json: Language.unscoped.find(params[:id]) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..63cfb4dfac43b59784b351e0358d6fc0b1b001d9 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,51 @@ +class SessionsController < ActionController::API + before_action :verify_ip_address + before_action :authenticate_request + before_action :authorize_request, only: [:authorize] + + def authenticate + head :ok + end + + def authorize + head :ok + end + + private + + def verify_ip_address + @@disallowed_ip_addresses ||= ENV['DISALLOW_IP'].to_s.split - ENV['ALLOW_IP'].to_s.split + @@allowed_ip_addresses ||= ENV['ALLOW_IP'].to_s.split - ENV['DISALLOW_IP'].to_s.split + head :forbidden if @@disallowed_ip_addresses.include?(request.remote_ip) + head :forbidden if @@allowed_ip_addresses.present? && !@@allowed_ip_addresses.include?(request.remote_ip) + end + + def authenticate_request + head :unauthorized if safe_compare(Rails.application.secrets.authn_token, Rails.application.secrets.authn_header) + end + + def authorize_request + head :forbidden unless Rails.application.secrets.authz_token.present? + head :forbidden if safe_compare(Rails.application.secrets.authz_token, Rails.application.secrets.authz_header) + end + + def check_maintenance + @@maintenance_message ||= ENV['MAINTENANCE_MESSAGE'] + if Config::MAINTENANCE_MODE + render json: { + error: @@maintenance_message + }, status: :service_unavailable + end + end + + def safe_compare(token, header) + token = token.to_s + header = header.to_s + return false unless token.present? + provided_token = (request.headers[header] || params[header]).to_s + token.split.each do |value| + return false if ActiveSupport::SecurityUtils.secure_compare(value, provided_token) + end + true + end +end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..07ac5436861c084ad5d7ada57f0e8deab00f3e2a --- /dev/null +++ b/app/controllers/statuses_controller.rb @@ -0,0 +1,5 @@ +class StatusesController < ApplicationController + def index + render json: Status.all, each_serializer: StatusSerializer + end +end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..2f42863453b31d2e5932bfce81e1c7b4ee1eaa30 --- /dev/null +++ b/app/controllers/submissions_controller.rb @@ -0,0 +1,236 @@ +class SubmissionsController < ApplicationController + before_action :authorize_request, only: [:index, :destroy] + before_action :check_maintenance, only: [:create, :destroy] + before_action :check_wait, only: [:create] # Wait in batch_create is not allowed + before_action :check_batched_submissions, only: [:batch_create, :batch_show] + before_action :check_queue_size, only: [:create, :batch_create] + before_action :check_requested_fields, except: [:batch_create] # Fields are ignored in batch_create + before_action :set_base64_encoded + + def index + page = params[:page].try(:to_i) || 1 + per_page = params[:per_page].try(:to_i) || Submission.per_page + + if page <= 0 + render json: { error: "invalid page: #{page}" }, status: :bad_request + return + elsif per_page < 0 + render json: { error: "invalid per_page: #{per_page}" }, status: :bad_request + return + end + + submissions = Submission.paginate(page: page, per_page: per_page) + serializable_submissions = ActiveModelSerializers::SerializableResource.new( + submissions, { each_serializer: SubmissionSerializer, base64_encoded: @base64_encoded, fields: @requested_fields } + ) + + render json: { + submissions: serializable_submissions.as_json, + meta: pagination_dict(submissions) + } + rescue Encoding::UndefinedConversionError => e + render json: { + error: "some attributes for one or more submissions cannot be converted to UTF-8, use base64_encoded=true query parameter" + }, status: :bad_request + end + + def destroy + if !Config::ENABLE_SUBMISSION_DELETE + render json: { error: "delete not allowed" }, status: :bad_request + return + end + + submission = Submission.find_by!(token: params[:token]) + if submission.status == Status.queue || submission.status == Status.process + render json: { + error: "submission cannot be deleted because its status is #{submission.status.id} (#{submission.status.name})" + }, status: :bad_request + return + end + + submission.delete + + # Forcing base64_encoded=true because it guarantees user will get requested data after delete. + render json: submission, base64_encoded: true, fields: @requested_fields + end + + def show + token = params[:token] + render json: Rails.cache.fetch("#{token}", expires_in: Config::SUBMISSION_CACHE_DURATION, race_condition_ttl: 0.1*Config::SUBMISSION_CACHE_DURATION) { + Submission.find_by!(token: token) + }, base64_encoded: @base64_encoded, fields: @requested_fields + rescue Encoding::UndefinedConversionError + render_conversion_error(:bad_request) + end + + def batch_show + tokens = (request.headers[:tokens] || params[:tokens]).to_s.strip.split(",") + + if tokens.length > Config::MAX_SUBMISSION_BATCH_SIZE + render json: { + error: "number of submissions in a batch should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}" + }, status: :bad_request + return + elsif tokens.length == 0 + render json: { + error: "there should be at least one submission in a batch" + }, status: :bad_request + return + end + + existing_submissions = Hash[Submission.where(token: tokens).collect{ |s| [s.token, s] }] + + submissions = [] + tokens.each do |token| + if existing_submissions.has_key?(token) + serialized_submission = ActiveModelSerializers::SerializableResource.new( + existing_submissions[token], { serializer: SubmissionSerializer, base64_encoded: @base64_encoded, fields: @requested_fields } + ) + submissions << serialized_submission.as_json + else + submissions << nil + end + end + + render json: { submissions: submissions } + rescue Encoding::UndefinedConversionError => e + render json: { + error: "some attributes for one or more submissions cannot be converted to UTF-8, use base64_encoded=true query parameter" + }, status: :bad_request + end + + def create + submission = Submission.new(submission_params(params)) + + if submission.save + if @wait + begin + IsolateRunner.perform_now(submission) + submission.reload + render json: submission, status: :created, base64_encoded: @base64_encoded, fields: @requested_fields + rescue Encoding::UndefinedConversionError => e + render_conversion_error(:created, submission.token) + end + else + IsolateRunner.perform_later(submission) + render json: submission, status: :created, fields: [:token] + end + else + render json: submission.errors, status: :unprocessable_entity + end + end + + # Batch Create does not support sync (wait=true) mode. + def batch_create + number_of_submissions = params[:submissions].try(:size).to_i + + if number_of_submissions > Config::MAX_SUBMISSION_BATCH_SIZE + render json: { + error: "number of submissions in a batch should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}" + }, status: :bad_request + return + elsif number_of_submissions == 0 + render json: { + error: "there should be at least one submission in a batch" + }, status: :bad_request + return + end + + submissions = params[:submissions].each.collect{ |p| Submission.new(submission_params(p)) } + + response = [] + has_valid_submission = false + + submissions.each do |submission| + if submission.save + IsolateRunner.perform_later(submission) + response << { token: submission.token } + has_valid_submission = true + else + response << submission.errors + end + end + + render json: response, status: has_valid_submission ? :created : :unprocessable_entity + end + + private + + def submission_params(params) + submission_params = params.permit( + :source_code, + :language_id, + :compiler_options, + :command_line_arguments, + :number_of_runs, + :stdin, + :expected_output, + :cpu_time_limit, + :cpu_extra_time, + :wall_time_limit, + :memory_limit, + :stack_limit, + :max_processes_and_or_threads, + :enable_per_process_and_thread_time_limit, + :enable_per_process_and_thread_memory_limit, + :max_file_size, + :redirect_stderr_to_stdout, + :callback_url, + :additional_files, + :enable_network + ) + + submission_params[:additional_files] = Base64Service.decode(submission_params[:additional_files]) + + if @base64_encoded + submission_params[:source_code] = Base64Service.decode(submission_params[:source_code]) + submission_params[:stdin] = Base64Service.decode(submission_params[:stdin]) + submission_params[:expected_output] = Base64Service.decode(submission_params[:expected_output]) + end + + submission_params + end + + def check_wait + @wait = params[:wait] == "true" + if @wait && !Config::ENABLE_WAIT_RESULT + render json: { error: "wait not allowed" }, status: :bad_request + end + end + + def check_batched_submissions + unless Config::ENABLE_BATCHED_SUBMISSIONS + render json: { error: "batched submissions are not allowed" }, status: :bad_request + end + end + + def check_queue_size + number_of_submissions = params[:submissions].try(:size).presence || 1 + if Resque.size(ENV["JUDGE0_VERSION"]) + number_of_submissions > Config::MAX_QUEUE_SIZE + render json: { error: "queue is full" }, status: :service_unavailable + end + end + + def check_requested_fields + fields_service = Fields::Submission.new(params[:fields]) + render json: { error: "invalid fields: [#{fields_service.invalid_fields.join(", ")}]" }, status: :bad_request if fields_service.has_invalid_fields? + @requested_fields = fields_service.requested_fields + end + + def set_base64_encoded + if Config::DISABLE_IMPLICIT_BASE64_ENCODING + @base64_encoded = params[:base64_encoded] == "true" + else + @base64_encoded = params[:base64_encoded] != "false" + end + end + + def render_conversion_error(status, token = nil) + response_json = { + error: "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter", + } + response_json[:token] = token if token + + render json: response_json, status: status + end +end diff --git a/app/enumerations/status.rb b/app/enumerations/status.rb new file mode 100644 index 0000000000000000000000000000000000000000..e7cc458ea33a6c8410bd33c234101afaa0272062 --- /dev/null +++ b/app/enumerations/status.rb @@ -0,0 +1,30 @@ +class Status < Enumerations::Base + values queue: { id: 1, name: 'In Queue' }, + process: { id: 2, name: 'Processing' }, + ac: { id: 3, name: 'Accepted' }, + wa: { id: 4, name: 'Wrong Answer' }, + tle: { id: 5, name: 'Time Limit Exceeded' }, + ce: { id: 6, name: 'Compilation Error' }, + sigsegv: { id: 7, name: 'Runtime Error (SIGSEGV)' }, + sigxfsz: { id: 8, name: 'Runtime Error (SIGXFSZ)' }, + sigfpe: { id: 9, name: 'Runtime Error (SIGFPE)' }, + sigabrt: { id: 10, name: 'Runtime Error (SIGABRT)' }, + nzec: { id: 11, name: 'Runtime Error (NZEC)' }, + other: { id: 12, name: 'Runtime Error (Other)' }, + boxerr: { id: 13, name: 'Internal Error' }, + exeerr: { id: 14, name: 'Exec Format Error' } + + def self.find_runtime_error_by_status_code(status_code) + case status_code.to_i + when 11 then Status.sigsegv + when 25 then Status.sigxfsz + when 8 then Status.sigfpe + when 6 then Status.sigabrt + else Status.other + end + end + + def self.model_name + @@model_name ||= ActiveModel::Name.new(self) + end +end diff --git a/app/helpers/config.rb b/app/helpers/config.rb new file mode 100644 index 0000000000000000000000000000000000000000..edbb7f652fb205033522c63a9152a4452133980a --- /dev/null +++ b/app/helpers/config.rb @@ -0,0 +1,90 @@ +module Config + # For more info read: + # https://github.com/judge0/judge0/blob/master/judge0.conf + + MAINTENANCE_MODE = ENV["MAINTENANCE_MODE"] == "true" + ENABLE_WAIT_RESULT = ENV["ENABLE_WAIT_RESULT"] != "false" + ENABLE_COMPILER_OPTIONS = ENV["ENABLE_COMPILER_OPTIONS"] != "false" + ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS = ENV["ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS"].to_s.strip.split + ENABLE_COMMAND_LINE_ARGUMENTS = ENV["ENABLE_COMMAND_LINE_ARGUMENTS"] != "false" + ENABLE_SUBMISSION_DELETE = ENV["ENABLE_SUBMISSION_DELETE"] == "true" + ENABLE_CALLBACKS = ENV["ENABLE_CALLBACKS"] != "false" + CALLBACKS_MAX_TRIES = (ENV["CALLBACKS_MAX_TRIES"].presence || 3).to_i + CALLBACKS_TIMEOUT = (ENV["CALLBACKS_TIMEOUT"].presence || 5).to_f + ENABLE_ADDITIONAL_FILES = ENV["ENABLE_ADDITIONAL_FILES"] != "false" + MAX_QUEUE_SIZE = (ENV["MAX_QUEUE_SIZE"].presence || 100).to_i + CPU_TIME_LIMIT = (ENV["CPU_TIME_LIMIT"].presence || 5).to_f + MAX_CPU_TIME_LIMIT = (ENV["MAX_CPU_TIME_LIMIT"].presence || 15).to_f + CPU_EXTRA_TIME = (ENV["CPU_EXTRA_TIME"].presence || 1).to_f + MAX_CPU_EXTRA_TIME = (ENV["MAX_CPU_EXTRA_TIME"].presence || 5).to_f + WALL_TIME_LIMIT = (ENV["WALL_TIME_LIMIT"].presence || 10).to_f + MAX_WALL_TIME_LIMIT = (ENV["MAX_WALL_TIME_LIMIT"].presence || 20).to_f + MEMORY_LIMIT = (ENV["MEMORY_LIMIT"].presence || 128000).to_i # in KB + MAX_MEMORY_LIMIT = (ENV["MAX_MEMORY_LIMIT"].presence || 512000).to_i + STACK_LIMIT = (ENV["STACK_LIMIT"].presence || 64000).to_i # in KB + MAX_STACK_LIMIT = (ENV["MAX_STACK_LIMIT"].presence || 128000).to_i + MAX_PROCESSES_AND_OR_THREADS = (ENV["MAX_PROCESSES_AND_OR_THREADS"].presence || 60).to_i + MAX_MAX_PROCESSES_AND_OR_THREADS = (ENV["MAX_MAX_PROCESSES_AND_OR_THREADS"].presence || 120).to_i + ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT = ENV["ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT"] == "true" + ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT = ENV["ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT"] != "false" + ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT = ENV["ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT"] == "true" + ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT = ENV["ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT"] != "false" + MAX_FILE_SIZE = (ENV["MAX_FILE_SIZE"].presence || 1024).to_i + MAX_MAX_FILE_SIZE = (ENV["MAX_MAX_FILE_SIZE"].presence || 4096).to_i + NUMBER_OF_RUNS = (ENV["NUMBER_OF_RUNS"].presence || 1).to_i + MAX_NUMBER_OF_RUNS = (ENV["MAX_NUMBER_OF_RUNS"].presence || 20).to_i + REDIRECT_STDERR_TO_STDOUT = ENV["REDIRECT_STDERR_TO_STDOUT"] == "true" + MAX_EXTRACT_SIZE = (ENV["MAX_EXTRACT_SIZE"].presence || 10240).to_i + ENABLE_BATCHED_SUBMISSIONS = ENV["ENABLE_BATCHED_SUBMISSIONS"] != "false" + MAX_SUBMISSION_BATCH_SIZE = (ENV["MAX_SUBMISSION_BATCH_SIZE"].presence || 20).to_i + SUBMISSION_CACHE_DURATION = (ENV["SUBMISSION_CACHE_DURATION"].presence || 1).to_f + USE_DOCS_AS_HOMEPAGE = ENV["USE_DOCS_AS_HOMEPAGE"] == "true" + ALLOW_ENABLE_NETWORK = ENV["ALLOW_ENABLE_NETWORK"] != "false" + ENABLE_NETWORK = ENV["ENABLE_NETWORK"] == "true" + DISABLE_IMPLICIT_BASE64_ENCODING = ENV["DISABLE_IMPLICIT_BASE64_ENCODING"] == "true" + + def self.config_info + @@default_confg ||= { + "maintenance_mode": MAINTENANCE_MODE, + "enable_wait_result": ENABLE_WAIT_RESULT, + "enable_compiler_options": ENABLE_COMPILER_OPTIONS, + "allowed_languages_for_compile_options": ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS, + "enable_command_line_arguments": ENABLE_COMMAND_LINE_ARGUMENTS, + "enable_submission_delete": ENABLE_SUBMISSION_DELETE, + "enable_callbacks": ENABLE_CALLBACKS, + "callbacks_max_tries": CALLBACKS_MAX_TRIES, + "callbacks_timeout": CALLBACKS_TIMEOUT, + "enable_additional_files": ENABLE_ADDITIONAL_FILES, + "max_queue_size": MAX_QUEUE_SIZE, + "cpu_time_limit": CPU_TIME_LIMIT, + "max_cpu_time_limit": MAX_CPU_TIME_LIMIT, + "cpu_extra_time": CPU_EXTRA_TIME, + "max_cpu_extra_time": MAX_CPU_EXTRA_TIME, + "wall_time_limit": WALL_TIME_LIMIT, + "max_wall_time_limit": MAX_WALL_TIME_LIMIT, + "memory_limit": MEMORY_LIMIT, + "max_memory_limit": MAX_MEMORY_LIMIT, + "stack_limit": STACK_LIMIT, + "max_stack_limit": MAX_STACK_LIMIT, + "max_processes_and_or_threads": MAX_PROCESSES_AND_OR_THREADS, + "max_max_processes_and_or_threads": MAX_MAX_PROCESSES_AND_OR_THREADS, + "enable_per_process_and_thread_time_limit": ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT, + "allow_enable_per_process_and_thread_time_limit": ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT, + "enable_per_process_and_thread_memory_limit": ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT, + "allow_enable_per_process_and_thread_memory_limit": ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT, + "max_file_size": MAX_FILE_SIZE, + "max_max_file_size": MAX_MAX_FILE_SIZE, + "number_of_runs": NUMBER_OF_RUNS, + "max_number_of_runs": MAX_NUMBER_OF_RUNS, + "redirect_stderr_to_stdout": REDIRECT_STDERR_TO_STDOUT, + "max_extract_size": MAX_EXTRACT_SIZE, + "enable_batched_submissions": ENABLE_BATCHED_SUBMISSIONS, + "max_submission_batch_size": MAX_SUBMISSION_BATCH_SIZE, + "submission_cache_duration": SUBMISSION_CACHE_DURATION, + "use_docs_as_homepage": USE_DOCS_AS_HOMEPAGE, + "allow_enable_network": ALLOW_ENABLE_NETWORK, + "enable_network": ENABLE_NETWORK, + "disable_implicit_base64_encoding": DISABLE_IMPLICIT_BASE64_ENCODING + } + end +end diff --git a/app/helpers/isolate_runner.rb b/app/helpers/isolate_runner.rb new file mode 100644 index 0000000000000000000000000000000000000000..c8dcdd0e3a7281b79044c6d1489247628333333d --- /dev/null +++ b/app/helpers/isolate_runner.rb @@ -0,0 +1,39 @@ +module IsolateRunner + MAX_WAIT_TIME_S = 600 + + INITIAL_WAIT_TIME_S = 2 + NEXT_WAIT_TIME_S = 1 + WAIT_TIME_FACTOR_S = 0.5 + + WAITING_STATUSES = [Status.queue.id, Status.process.id, nil] + + def self.perform_now(submission) + IsolateRunner.perform_later(submission) + + submission_id = submission.id + + total_wait_time = 0 + (0..).each do |i| + break if total_wait_time >= MAX_WAIT_TIME_S + + if i == 0 then + wait_time = INITIAL_WAIT_TIME_S + elsif i == 1 then + wait_time = NEXT_WAIT_TIME_S + else + wait_time = WAIT_TIME_FACTOR_S * i + end + + sleep(wait_time) + + total_wait_time += wait_time + + break if !WAITING_STATUSES.include?(Submission.where(id: submission_id).pluck(:status_id).first) + end + end + + def self.perform_later(submission) + submission.update(status: Status.queue, queued_at: DateTime.now, queue_host: ENV["HOSTNAME"]) + IsolateJob.perform_later(submission.id) + end +end diff --git a/app/helpers/nil_value.rb b/app/helpers/nil_value.rb new file mode 100644 index 0000000000000000000000000000000000000000..dd171492678ff837a178218ea874b1fad8cf0074 --- /dev/null +++ b/app/helpers/nil_value.rb @@ -0,0 +1,6 @@ +module NilValue + def self.value_or_default(value, default) + return value unless value == nil + return default + end +end \ No newline at end of file diff --git a/app/helpers/system_info.rb b/app/helpers/system_info.rb new file mode 100644 index 0000000000000000000000000000000000000000..ab7baca73cb21108293ae74b84e865910b72a321 --- /dev/null +++ b/app/helpers/system_info.rb @@ -0,0 +1,13 @@ +module SystemInfo + def self.sys_info + @@sys_info ||= self.cpu_info.merge(self.mem_info) + end + + def self.cpu_info #sorryforthisline + @@cpu_info ||= Hash[`lscpu`.split("\n").collect{|l| l = l.split(":"); [l[0].strip, l[1].strip]}] + end + + def self.mem_info #sorryagain #itjustworks + @@mem_info ||= Hash[`free -h`.split("\n")[1..-1].collect{|l| l = l.split(":"); [l[0].strip, l[1].split(" ")[0].strip]}].without("-/+ buffers/cache") + end +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000000000000000000000000000000000..a009ace51ccf46bab4ac06100a225a1fa1801e65 --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/jobs/isolate_job.rb b/app/jobs/isolate_job.rb new file mode 100644 index 0000000000000000000000000000000000000000..cadad6141bb329d95c7c7c6bb659c2ff109a134f --- /dev/null +++ b/app/jobs/isolate_job.rb @@ -0,0 +1,371 @@ +class IsolateJob < ApplicationJob + retry_on RuntimeError, wait: 0.1.seconds, attempts: 100 + + queue_as ENV["JUDGE0_VERSION"].to_sym + + STDIN_FILE_NAME = "stdin.txt" + STDOUT_FILE_NAME = "stdout.txt" + STDERR_FILE_NAME = "stderr.txt" + METADATA_FILE_NAME = "metadata.txt" + ADDITIONAL_FILES_ARCHIVE_FILE_NAME = "additional_files.zip" + + attr_reader :submission, :cgroups, + :box_id, :workdir, :boxdir, :tmpdir, + :source_file, :stdin_file, :stdout_file, + :stderr_file, :metadata_file, :additional_files_archive_file + + def perform(submission_id) + @submission = Submission.find(submission_id) + submission.update(status: Status.process, started_at: DateTime.now, execution_host: ENV["HOSTNAME"]) + + time = [] + memory = [] + + submission.number_of_runs.times do + initialize_workdir + if compile == :failure + cleanup + return + end + run + verify + + time << submission.time + memory << submission.memory + + cleanup + break if submission.status != Status.ac + end + + submission.time = time.inject(&:+).to_f / time.size + submission.memory = memory.inject(&:+).to_f / memory.size + submission.save + + rescue Exception => e + raise e.message unless submission + submission.update(message: e.message, status: Status.boxerr, finished_at: DateTime.now) + cleanup(raise_exception = false) + ensure + call_callback + end + + private + + def initialize_workdir + @box_id = submission.id%2147483647 + @cgroups = (!submission.enable_per_process_and_thread_time_limit || !submission.enable_per_process_and_thread_memory_limit) ? "--cg" : "" + @workdir = `isolate #{cgroups} -b #{box_id} --init`.chomp + @boxdir = workdir + "/box" + @tmpdir = workdir + "/tmp" + @source_file = boxdir + "/" + submission.language.source_file.to_s + @stdin_file = workdir + "/" + STDIN_FILE_NAME + @stdout_file = workdir + "/" + STDOUT_FILE_NAME + @stderr_file = workdir + "/" + STDERR_FILE_NAME + @metadata_file = workdir + "/" + METADATA_FILE_NAME + @additional_files_archive_file = boxdir + "/" + ADDITIONAL_FILES_ARCHIVE_FILE_NAME + + [stdin_file, stdout_file, stderr_file, metadata_file].each do |f| + initialize_file(f) + end + + File.open(source_file, "wb") { |f| f.write(submission.source_code) } unless submission.is_project + File.open(stdin_file, "wb") { |f| f.write(submission.stdin) } + + extract_archive + end + + def initialize_file(file) + `sudo touch #{file} && sudo chown $(whoami): #{file}` + end + + def extract_archive + return unless submission.additional_files? + + File.open(additional_files_archive_file, "wb") { |f| f.write(submission.additional_files) } + + command = "isolate #{cgroups} \ + -s \ + -b #{box_id} \ + --stderr-to-stdout \ + -t 2 \ + -x 1 \ + -w 4 \ + -k #{Config::MAX_STACK_LIMIT} \ + -p#{Config::MAX_MAX_PROCESSES_AND_OR_THREADS} \ + #{submission.enable_per_process_and_thread_time_limit ? (cgroups.present? ? "--no-cg-timing" : "") : "--cg-timing"} \ + #{submission.enable_per_process_and_thread_memory_limit ? "-m " : "--cg-mem="}#{Config::MAX_MEMORY_LIMIT} \ + -f #{Config::MAX_EXTRACT_SIZE} \ + --run \ + -- /usr/bin/unzip -n -qq #{ADDITIONAL_FILES_ARCHIVE_FILE_NAME} \ + " + + puts "[#{DateTime.now}] Extracting archive for submission #{submission.token} (#{submission.id}):" + puts command.gsub(/\s+/, " ") + puts + + `#{command}` + + File.delete(additional_files_archive_file) + end + + def compile + unless submission.is_project + return :success unless submission.language.compile_cmd + end + + compile_script = boxdir + "/" + "compile.sh" + + acceptable_project_compile_scripts = [compile_script, boxdir + "/" + "compile"] + if submission.is_project + compile_file_exists = false + acceptable_project_compile_scripts.each do |f| + if File.file?(f) + compile_script = f + compile_file_exists = true + break + end + end + + unless compile_file_exists + return :success # If compile script does not exist then this project does not need to be compiled. + end + else + # gsub can be skipped if compile script is used, but is kept for additional security. + compiler_options = submission.compiler_options.to_s.strip.encode("UTF-8", invalid: :replace).gsub(/[$&;<>|`]/, "") + File.open(compile_script, "w") { |f| f.write("#{submission.language.compile_cmd % compiler_options}") } + end + + compile_output_file = workdir + "/" + "compile_output.txt" + initialize_file(compile_output_file) + + command = "isolate #{cgroups} \ + -s \ + -b #{box_id} \ + -M #{metadata_file} \ + --stderr-to-stdout \ + -i /dev/null \ + -t #{Config::MAX_CPU_TIME_LIMIT} \ + -x 0 \ + -w #{Config::MAX_WALL_TIME_LIMIT} \ + -k #{Config::MAX_STACK_LIMIT} \ + -p#{Config::MAX_MAX_PROCESSES_AND_OR_THREADS} \ + #{submission.enable_per_process_and_thread_time_limit ? (cgroups.present? ? "--no-cg-timing" : "") : "--cg-timing"} \ + #{submission.enable_per_process_and_thread_memory_limit ? "-m " : "--cg-mem="}#{Config::MAX_MEMORY_LIMIT} \ + -f #{Config::MAX_MAX_FILE_SIZE} \ + -E HOME=/tmp \ + -E PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" \ + -E LANG -E LANGUAGE -E LC_ALL -E JUDGE0_HOMEPAGE -E JUDGE0_SOURCE_CODE -E JUDGE0_MAINTAINER -E JUDGE0_VERSION \ + -d /etc:noexec \ + --run \ + -- /bin/bash $(basename #{compile_script}) > #{compile_output_file} \ + " + + puts "[#{DateTime.now}] Compiling submission #{submission.token} (#{submission.id}):" + puts command.gsub(/\s+/, " ") + puts + + `#{command}` + process_status = $? + + compile_output = File.read(compile_output_file) + compile_output = nil if compile_output.empty? + submission.compile_output = compile_output + + metadata = get_metadata + + reset_metadata_file + + files_to_remove = [compile_output_file] + files_to_remove << compile_script unless submission.is_project + files_to_remove.each do |f| + `sudo rm -rf #{f}` + end + + return :success if process_status.success? + + if metadata[:status] == "TO" + submission.compile_output = "Compilation time limit exceeded." + end + + submission.finished_at = DateTime.now + submission.time = nil + submission.wall_time = nil + submission.memory = nil + submission.stdout = nil + submission.stderr = nil + submission.exit_code = nil + submission.exit_signal = nil + submission.message = nil + submission.status = Status.ce + submission.save + + return :failure + end + + def run + run_script = boxdir + "/" + "run.sh" + + acceptable_project_run_scripts = [run_script, boxdir + "/" + "run"] + acceptable_project_run_scripts.each do |f| + if File.file?(f) + run_script = f + break + end + end + + unless submission.is_project + # gsub is mandatory! + command_line_arguments = submission.command_line_arguments.to_s.strip.encode("UTF-8", invalid: :replace).gsub(/[$&;<>|`]/, "") + File.open(run_script, "w") { |f| f.write("#{submission.language.run_cmd} #{command_line_arguments}")} + end + + command = "isolate #{cgroups} \ + -s \ + -b #{box_id} \ + -M #{metadata_file} \ + #{submission.redirect_stderr_to_stdout ? "--stderr-to-stdout" : ""} \ + #{submission.enable_network ? "--share-net" : ""} \ + -t #{submission.cpu_time_limit} \ + -x #{submission.cpu_extra_time} \ + -w #{submission.wall_time_limit} \ + -k #{submission.stack_limit} \ + -p#{submission.max_processes_and_or_threads} \ + #{submission.enable_per_process_and_thread_time_limit ? (cgroups.present? ? "--no-cg-timing" : "") : "--cg-timing"} \ + #{submission.enable_per_process_and_thread_memory_limit ? "-m " : "--cg-mem="}#{submission.memory_limit} \ + -f #{submission.max_file_size} \ + -E HOME=/tmp \ + -E PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" \ + -E LANG -E LANGUAGE -E LC_ALL -E JUDGE0_HOMEPAGE -E JUDGE0_SOURCE_CODE -E JUDGE0_MAINTAINER -E JUDGE0_VERSION \ + -d /etc:noexec \ + --run \ + -- /bin/bash $(basename #{run_script}) \ + < #{stdin_file} > #{stdout_file} 2> #{stderr_file} \ + " + + puts "[#{DateTime.now}] Running submission #{submission.token} (#{submission.id}):" + puts command.gsub(/\s+/, " ") + puts + + `#{command}` + + `sudo rm #{run_script}` unless submission.is_project + end + + def verify + submission.finished_at = DateTime.now + + metadata = get_metadata + + program_stdout = File.read(stdout_file) + program_stdout = nil if program_stdout.empty? + + program_stderr = File.read(stderr_file) + program_stderr = nil if program_stderr.empty? + + submission.time = metadata[:time] + submission.wall_time = metadata[:"time-wall"] + submission.memory = (cgroups.present? ? metadata[:"cg-mem"] : metadata[:"max-rss"]) + submission.stdout = program_stdout + submission.stderr = program_stderr + submission.exit_code = metadata[:exitcode].try(:to_i) || 0 + submission.exit_signal = metadata[:exitsig].try(:to_i) + submission.message = metadata[:message] + submission.status = determine_status(metadata[:status], submission.exit_signal) + + # After adding support for compiler_options and command_line_arguments + # status "Exec Format Error" will no longer occur because compile and run + # is done inside a dynamically created bash script, thus isolate doesn't call + # execve directily on submission.language.compile_cmd or submission.langauge.run_cmd. + # Consequence of running compile and run through bash script is that when + # target binary is not found then submission gets status "Runtime Error (NZEC)". + # + # I think this is for now O.K. behaviour, but I will leave this if block + # here until I am 100% sure that "Exec Format Error" can be deprecated. + if submission.status == Status.boxerr && + ( + submission.message.to_s.match(/^execve\(.+\): Exec format error$/) || + submission.message.to_s.match(/^execve\(.+\): No such file or directory$/) || + submission.message.to_s.match(/^execve\(.+\): Permission denied$/) + ) + submission.status = Status.exeerr + end + end + + def cleanup(raise_exception = true) + fix_permissions + `sudo rm -rf #{boxdir}/* #{tmpdir}/*` + [stdin_file, stdout_file, stderr_file, metadata_file].each do |f| + `sudo rm -rf #{f}` + end + `isolate #{cgroups} -b #{box_id} --cleanup` + raise "Cleanup of sandbox #{box_id} failed." if raise_exception && Dir.exists?(workdir) + end + + def reset_metadata_file + `sudo rm -rf #{metadata_file}` + initialize_file(metadata_file) + end + + def fix_permissions + `sudo chown -R $(whoami): #{boxdir}` + end + + def call_callback + return unless submission.callback_url.present? + + serialized_submission = ActiveModelSerializers::SerializableResource.new( + submission, + { + serializer: SubmissionSerializer, + base64_encoded: true, + fields: SubmissionSerializer.default_fields + } + ).to_json + + Config::CALLBACKS_MAX_TRIES.times do + begin + response = HTTParty.put( + submission.callback_url, + body: serialized_submission, + headers: { + "Content-Type" => "application/json" + }, + timeout: Config::CALLBACKS_TIMEOUT + ) + break + rescue Exception => e + end + end + rescue Exception => e + end + + def get_metadata + metadata = File.read(metadata_file).split("\n").collect do |e| + { e.split(":").first.to_sym => e.split(":")[1..-1].join(":") } + end.reduce({}, :merge) + return metadata + end + + def determine_status(status, exit_signal) + if status == "TO" + return Status.tle + elsif status == "SG" + return Status.find_runtime_error_by_status_code(exit_signal) + elsif status == "RE" + return Status.nzec + elsif status == "XX" + return Status.boxerr + elsif submission.expected_output.nil? || strip(submission.expected_output) == strip(submission.stdout) + return Status.ac + else + return Status.wa + end + end + + def strip(text) + return nil unless text + text.split("\n").collect(&:rstrip).join("\n").rstrip + rescue ArgumentError + return text + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..286b2239d139960190594225e0134fe1a5c05370 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000000000000000000000000000000000..10a4cba84df37181f4cf310fd85d8f0aaa5d90ba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/models/language.rb b/app/models/language.rb new file mode 100644 index 0000000000000000000000000000000000000000..ba0c6dd3ba9a06fd57269fa54c07b6abdab4ad4a --- /dev/null +++ b/app/models/language.rb @@ -0,0 +1,21 @@ +# == Schema Information +# +# Table name: languages +# +# id :integer not null, primary key +# name :string +# compile_cmd :string +# run_cmd :string +# source_file :string +# is_archived :boolean default(FALSE) +# + +class Language < ApplicationRecord + validates :name, presence: true + validates :source_file, :run_cmd, presence: true, unless: -> { is_project } + default_scope { where(is_archived: false).order(name: :asc) } + + def is_project + name == "Multi-file program" + end +end diff --git a/app/models/submission.rb b/app/models/submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..3dfec2cf4b2f900c4ff56d9cb5327ee80fe81dec --- /dev/null +++ b/app/models/submission.rb @@ -0,0 +1,261 @@ +# == Schema Information +# +# Table name: submissions +# +# id :integer not null, primary key +# source_code :text +# language_id :integer +# stdin :text +# expected_output :text +# stdout :text +# status_id :integer +# created_at :datetime +# finished_at :datetime +# time :decimal(, ) +# memory :integer +# stderr :text +# token :string +# number_of_runs :integer +# cpu_time_limit :decimal(, ) +# cpu_extra_time :decimal(, ) +# wall_time_limit :decimal(, ) +# memory_limit :integer +# stack_limit :integer +# max_processes_and_or_threads :integer +# enable_per_process_and_thread_time_limit :boolean +# enable_per_process_and_thread_memory_limit :boolean +# max_file_size :integer +# compile_output :text +# exit_code :integer +# exit_signal :integer +# message :text +# wall_time :decimal(, ) +# compiler_options :string +# command_line_arguments :string +# redirect_stderr_to_stdout :boolean +# callback_url :string +# additional_files :binary +# enable_network :boolean +# started_at :datetime +# queued_at :datetime +# updated_at :datetime +# queue_host :string +# execution_host :string +# + +class Submission < ApplicationRecord + validates :source_code, presence: true, unless: -> { is_project } + validates :source_code, absence: true, if: -> { is_project } + validates :additional_files, presence: true, if: -> { is_project } + validates :language_id, presence: true + validates :number_of_runs, + numericality: { greater_than: 0, less_than_or_equal_to: Config::MAX_NUMBER_OF_RUNS } + validates :cpu_time_limit, + numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Config::MAX_CPU_TIME_LIMIT } + validates :cpu_extra_time, + numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Config::MAX_CPU_EXTRA_TIME } + validates :wall_time_limit, + numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: Config::MAX_WALL_TIME_LIMIT } + validates :memory_limit, + numericality: { greater_than_or_equal_to: 2048, less_than_or_equal_to: Config::MAX_MEMORY_LIMIT } + validates :stack_limit, + numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Config::MAX_STACK_LIMIT } + validates :max_processes_and_or_threads, + numericality: { greater_than: 0, less_than_or_equal_to: Config::MAX_MAX_PROCESSES_AND_OR_THREADS } + validates :enable_per_process_and_thread_time_limit, + inclusion: { in: [false], message: "this option cannot be enabled" }, + unless: -> { Config::ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT } + validates :enable_per_process_and_thread_memory_limit, + inclusion: { in: [false], message: "this option cannot be enabled" }, + unless: -> { Config::ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT } + validates :max_file_size, + numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Config::MAX_MAX_FILE_SIZE } + validates :compiler_options, length: { maximum: 512 } + validates :command_line_arguments, length: { maximum: 512 } + validate :language_existence, :compiler_options_allowed, + :command_line_arguments_allowed, :callbacks_allowed, + :additional_files_allowed, :network_allowed + + before_create :generate_token + before_validation :set_defaults + + enumeration :status + + default_scope { order(created_at: :desc) } + + self.per_page = 20 + + def source_code + @decoded_source_code ||= Base64Service.decode(self[:source_code]) + end + + def source_code=(value) + super(value) + self[:source_code] = Base64Service.encode(self[:source_code]) + end + + + def stdin + @decoded_stdin ||= Base64Service.decode(self[:stdin]) + end + + def stdin=(value) + super(value) + self[:stdin] = Base64Service.encode(self[:stdin]) + end + + + def stdout + @decoded_stdout ||= Base64Service.decode(self[:stdout]) + end + + def stdout=(value) + super(value) + self[:stdout] = Base64Service.encode(self[:stdout]) + end + + + def expected_output + @decoded_expected_output ||= Base64Service.decode(self[:expected_output]) + end + + def expected_output=(value) + super(value) + self[:expected_output] = Base64Service.encode(self[:expected_output]) + end + + + def stderr + @decoded_stderr ||= Base64Service.decode(self[:stderr]) + end + + def stderr=(value) + super(value) + self[:stderr] = Base64Service.encode(self[:stderr]) + end + + + def compile_output + @decoded_compile_output ||= Base64Service.decode(self[:compile_output]) + end + + def compile_output=(value) + super(value) + self[:compile_output] = Base64Service.encode(self[:compile_output]) + end + + + def language + @language ||= Language.unscoped.find_by(id: language_id) + end + + + def status + Status.find_by(id: status_id) + end + + def status=(status) + self.status_id = status.id + end + + + def is_project + language.try(:is_project) || false + end + + private + + def language_existence + if not language + errors.add(:language_id, "language with id #{language_id} doesn't exist") + elsif language.is_archived + errors.add(:language_id, "language with id #{language_id} is archived and cannot be used anymore") + end + end + + def compiler_options_allowed + return if compiler_options.blank? + + unless Config::ENABLE_COMPILER_OPTIONS + errors.add(:compiler_options, "setting compiler options is not allowed") + return + end + + if language && language.compile_cmd.nil? + errors.add(:compiler_options, "setting compiler options is only allowed for compiled languages") + return + end + + @@allowed_languages ||= Config::ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS.collect{ |s| s + " " } + if language && @@allowed_languages.present? && !language.name.starts_with?(*@@allowed_languages) + @@allowed_languages_message ||= @@allowed_languages.size > 1 ? @@allowed_languages[0..-2].collect{ |s| s.strip }.join(", ") + " and " + @@allowed_languages[-1].strip : @@allowed_languages[0].strip + errors.add(:compiler_options, "setting compiler options is only allowed for #{@@allowed_languages_message}") + end + end + + def command_line_arguments_allowed + return if command_line_arguments.blank? + + unless Config::ENABLE_COMMAND_LINE_ARGUMENTS + errors.add(:command_line_arguments, "setting command line arguments is not allowed") + end + end + + def callbacks_allowed + return if callback_url.blank? + + unless Config::ENABLE_CALLBACKS + errors.add(:callback_url, "setting callback is not allowed") + end + end + + def additional_files_allowed + return if additional_files.blank? + + unless Config::ENABLE_ADDITIONAL_FILES + errors.add(:additional_files, "setting additional files is not allowed") + end + end + + def network_allowed + return if enable_network.blank? + + unless Config::ALLOW_ENABLE_NETWORK + errors.add(:enable_network, "enabling network is not allowed") + end + end + + def generate_token + begin + self.token = SecureRandom.uuid + end while self.class.exists?(token: token) + end + + def set_defaults + self.status ||= Status.queue + self.number_of_runs ||= Config::NUMBER_OF_RUNS + self.cpu_time_limit ||= Config::CPU_TIME_LIMIT + self.cpu_extra_time ||= Config::CPU_EXTRA_TIME + self.wall_time_limit ||= Config::WALL_TIME_LIMIT + self.memory_limit ||= Config::MEMORY_LIMIT + self.stack_limit ||= Config::STACK_LIMIT + self.max_processes_and_or_threads ||= Config::MAX_PROCESSES_AND_OR_THREADS + self.enable_per_process_and_thread_time_limit = NilValue.value_or_default( + self.enable_per_process_and_thread_time_limit, + Config::ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT + ) + self.enable_per_process_and_thread_memory_limit = NilValue.value_or_default( + self.enable_per_process_and_thread_memory_limit, + Config::ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT + ) + self.max_file_size ||= Config::MAX_FILE_SIZE + self.redirect_stderr_to_stdout = NilValue.value_or_default( + self.redirect_stderr_to_stdout, + Config::REDIRECT_STDERR_TO_STDOUT + ) + self.enable_network = NilValue.value_or_default( + self.enable_network, + Config::ENABLE_NETWORK + ) + end +end diff --git a/app/serializers/language_serializer.rb b/app/serializers/language_serializer.rb new file mode 100644 index 0000000000000000000000000000000000000000..fe6b3676985be9bee87507aa8d798d8c7b2988eb --- /dev/null +++ b/app/serializers/language_serializer.rb @@ -0,0 +1,3 @@ +class LanguageSerializer < ActiveModel::Serializer + attributes :id, :name, :is_archived, :source_file, :compile_cmd, :run_cmd +end diff --git a/app/serializers/status_serializer.rb b/app/serializers/status_serializer.rb new file mode 100644 index 0000000000000000000000000000000000000000..6f65f2cb58851294a0cc4d55ca0dfd4c3c0b0a2a --- /dev/null +++ b/app/serializers/status_serializer.rb @@ -0,0 +1,4 @@ +class StatusSerializer < ActiveModel::Serializer + attribute(:id) { object.id } + attribute(:description) { object.name } +end diff --git a/app/serializers/submission_serializer.rb b/app/serializers/submission_serializer.rb new file mode 100644 index 0000000000000000000000000000000000000000..bf2ef30a371201fbf6023e1dea0f80fc64a8c7a1 --- /dev/null +++ b/app/serializers/submission_serializer.rb @@ -0,0 +1,65 @@ +class SubmissionSerializer < ActiveModel::Serializer + attributes((Submission.column_names + ["status", "language"] - ["id"]).collect(&:to_sym)) + + def self.default_fields + @@default_fields ||= [ + :token, + :time, + :memory, + :stdout, + :stderr, + :compile_output, + :message, + :status + ] + end + + def source_code + object_decoder(:source_code) + end + + def stdin + object_decoder(:stdin) + end + + def expected_output + object_decoder(:expected_output) + end + + def stdout + object_decoder(:stdout) + end + + def stderr + object_decoder(:stderr) + end + + def compile_output + object_decoder(:compile_output) + end + + def message + if instance_options[:base64_encoded] and object.message + return Base64Service.encode(object.message) + end + object.message + end + + def status + { id: object.status_id, description: object.status.name } + end + + def language + ActiveModelSerializers::SerializableResource.new(object.language, { serializer: LanguageSerializer, fields: [:id, :name] }) + end + + def additional_files + Base64Service.encode(object.additional_files) + end + + private + + def object_decoder(method) + instance_options[:base64_encoded] ? object[method] : object.send(method) + end +end diff --git a/app/services/base64_service.rb b/app/services/base64_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..fbdb6a2e50661549eb30914c819f42f2e7df4285 --- /dev/null +++ b/app/services/base64_service.rb @@ -0,0 +1,11 @@ +module Base64Service + def self.encode(text) + return nil unless text + Base64.encode64(text) + end + + def self.decode(text) + return nil unless text + Base64.decode64(text) #.force_encoding("UTF-8").encode + end +end diff --git a/app/services/fields/submission.rb b/app/services/fields/submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..afbc87ec772a5a783129db184fc531776d6e035f --- /dev/null +++ b/app/services/fields/submission.rb @@ -0,0 +1,41 @@ +module Fields + class Submission + UNIVERSAL_FIELD = :* + + attr_reader :requested_fields, :invalid_fields + + def initialize(fields) + @invalid_fields = [] + + fields = fields.to_s.split(",").collect(&:to_sym) + + fields.each do |field| + if field != UNIVERSAL_FIELD && !available_fields.include?(field) + @invalid_fields << field + end + end + + if fields.include?(UNIVERSAL_FIELD) + @requested_fields = available_fields + else + @requested_fields = (fields - @invalid_fields).presence || default_fields + end + end + + def has_invalid_fields? + !@invalid_fields.empty? + end + + def available_fields + serializer._attributes + end + + def default_fields + serializer.default_fields + end + + def serializer + SubmissionSerializer + end + end +end \ No newline at end of file diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..cbd34d2e9dd1176aeddb1efe6e1aeb0e2afd2931 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000000000000000000000000000000000..37f0bddbd746bc24923ce9a8eb0dae1ca3076284 --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle new file mode 100644 index 0000000000000000000000000000000000000000..66e9889e8b4aeea1af13e2396fb70594232a2ae3 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100644 index 0000000000000000000000000000000000000000..5badb2fde0cb72bbb3cba8436721048dfd7e58dd --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100644 index 0000000000000000000000000000000000000000..d87d5f578104597c1d1b951b55942e37f8af1277 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100644 index 0000000000000000000000000000000000000000..e620b4dadb27feebc2043e55bc0d23c104ccac37 --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100644 index 0000000000000000000000000000000000000000..7fe232c3aae5996a1d6ca1f69d10e636630f5c5c --- /dev/null +++ b/bin/spring @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) + Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) } + gem 'spring', match[1] + require 'spring/binstub' + end +end diff --git a/bin/telemetry b/bin/telemetry new file mode 100644 index 0000000000000000000000000000000000000000..70be662650f0b0537b7e559b19f2a960dbcb3dfe --- /dev/null +++ b/bin/telemetry @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35ae04b727c002b3b95ded0fc9f5009e4d8cc64696f5ab7875efebf0a7fd9fbd +size 2499264 diff --git a/bin/update b/bin/update new file mode 100644 index 0000000000000000000000000000000000000000..a8e4462f20340b73db6df04da3a3fa0dd842713f --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000000000000000000000000000000000..b5f29231d4a8fca481f84d5773e376d7bfc28f90 --- /dev/null +++ b/config.ru @@ -0,0 +1,3 @@ +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000000000000000000000000000000000000..bddd4c5af2f9cfcdd81b21fe1cd09080ee851226 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,42 @@ +require_relative 'boot' + +require "rails" +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "action_cable/engine" + +require "rails/test_unit/railtie" + +Bundler.require(*Rails.groups) + +module Judge0API + class Application < Rails::Application + config.api_only = true + config.generators do |g| + g.factory_girl test_framework: :rspec + end + + config.active_job.queue_adapter = :resque + + config.middleware.insert_before 0, Rack::Cors do + origins = [] + + disallowed_origins = (ENV['DISALLOW_ORIGIN'].to_s.split - ENV['ALLOW_ORIGIN'].to_s.split).collect{ |s| s.gsub(".", "\\.") }.join("|") + if disallowed_origins.present? + origins.append(Regexp.new("^(?:(?!#{disallowed_origins}).)*$")) + end + + # ALLOW_ORIGIN and DISALLOW_ORIGIN are mutually exclusive so this doesn't have any effect. + origins += (ENV['ALLOW_ORIGIN'].presence || (origins.present? ? '' : '*')).split + + allow do + origins origins + resource '*', headers: :any, methods: :any + end + end + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000000000000000000000000000000000..5cea2ab21cd92a17e37becefb0ebd76c6ca2b8d5 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000000000000000000000000000000000000..0bbde6f74fe1216e2e76c2cac2e8a5901b2107b0 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000000000000000000000000000000000..4a913550f2e2a4241a00b1f468d328b5778da1ee --- /dev/null +++ b/config/database.yml @@ -0,0 +1,18 @@ +default: &default + adapter: postgresql + encoding: unicode + host: <%= ENV["POSTGRES_HOST"] %> + port: <%= ENV["POSTGRES_PORT"] %> + database: <%= ENV["POSTGRES_DB"] %> + username: <%= ENV["POSTGRES_USER"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> + pool: <%= [1, ENV["RAILS_SERVER_PROCESSES"].to_i * ENV["RAILS_MAX_THREADS"].to_i].max %> + +development: + <<: *default + +test: + <<: *default + +production: + <<: *default diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000000000000000000000000000000000..875ab0f2ea07d04a8dbcd806d21577fd7b3b7a82 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,3 @@ +require_relative 'application' + +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000000000000000000000000000000000000..082a013ab36366f8a220488321eb9de3e94b9105 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,47 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000000000000000000000000000000000..9d25498ada765ef651a3c275fc1e87e101b550c0 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,78 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = true + + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :warn + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "Judge0API_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = [I18n.default_locale] + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000000000000000000000000000000000..30587ef6d5ec30b210adfbc7a496880209fe76b7 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000000000000000000000000000000000..51639b67a00ddba973a92d59ec277f5d97b63ef6 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000000000000000000000000000000000..59385cdf379bd06a8d2326dcd4de6d5cd5d3f5b0 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb new file mode 100644 index 0000000000000000000000000000000000000000..3b1c1b5ed1480e3f72d2cc6e4249d34cebeda9ec --- /dev/null +++ b/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000000000000000000000000000000000..4a994e1e7bb7ce28dcec98bad48b9a891d7dec51 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000000000000000000000000000000000000..ac033bf9dc846101320c96a5ce8aceb8c96ec098 --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000000000000000000000000000000000000..dc1899682b01c3a6d9673faf746e235fb64fc4d2 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 0000000000000000000000000000000000000000..6e81e4259197a10d49145c3439d7300de555da6c --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,15 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 upgrade. +# +# Read the Rails 5.0 release notes for more info on each option. + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = true + +# Require `belongs_to` associations by default. Previous versions had false. +Rails.application.config.active_record.belongs_to_required_by_default = true + +# Configure SSL options to enable HSTS with subdomains. Previous versions had false. +Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb new file mode 100644 index 0000000000000000000000000000000000000000..8415a034671b7595c3ca81b1f13a054fde639497 --- /dev/null +++ b/config/initializers/resque.rb @@ -0,0 +1,10 @@ +Resque.redis = Redis.new( + host: ENV["REDIS_HOST"], + port: ENV["REDIS_PORT"], + password: ENV["REDIS_PASSWORD"], + thread_safe: true +) + +if ENV["RESQUE_NAMESPACE"].present? + Resque.redis.namespace = ENV["RESQUE_NAMESPACE"].to_sym +end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000000000000000000000000000000000..bbfc3961bffef15dabb35fe0de4c409d6efb58c5 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000000000000000000000000000000000000..132319c231ace0795c3fbd3418d332a4b3a77715 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,9 @@ +threads_count = Integer(ENV['RAILS_MAX_THREADS']) +process_count = Integer(ENV['RAILS_SERVER_PROCESSES']) +threads threads_count, threads_count +workers process_count + +port ENV['PORT'] +environment ENV['RAILS_ENV'] + +plugin :tmp_restart \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000000000000000000000000000000000..c9c5bdb36d376a67a0c663ec167ec0eb82705206 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,27 @@ +Rails.application.routes.draw do + root 'home#index' + + resources :submissions, only: [:index, :show, :create, :destroy], param: :token do + post 'batch', to: 'submissions#batch_create', on: :collection + get 'batch', to: 'submissions#batch_show', on: :collection + end + + resources :languages, only: [:index, :show] do + get 'all', to: 'languages#all', on: :collection + end + + resources :statuses, only: [:index] + + get 'system_info', to: 'info#system_info' + get 'config_info', to: 'info#config_info' + get 'isolate', to: 'info#isolate' + get 'about', to: 'info#about' + get 'version', to: 'info#version' + get 'license', to: 'info#license' + get 'statistics', to: 'info#statistics' + + post 'authenticate', to: 'sessions#authenticate' + post 'authorize', to: 'sessions#authorize' + + get 'workers', to: 'health#workers' +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000000000000000000000000000000000000..32c740aa10b74c7c01760a6f77d80ecfea9f9172 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,15 @@ +default: &default + authn_header: <%= ENV["AUTHN_HEADER"] %> + authn_token: <%= ENV["AUTHN_TOKEN"].to_s.strip %> + authz_header: <%= ENV["AUTHZ_HEADER"] %> + authz_token: <%= ENV["AUTHZ_TOKEN"].to_s.strip %> + +development: + <<: *default + secret_key_base: 54663e3c477de43bd117ddbf1798951ba5cf692dbf8327bb21f341048f04ea95344eed6c8763625a39648bfc2583f128b296bcb3a4756ef8160e483664efcb0b + +test: + secret_key_base: 334f81f95f09f01e58b950ff5e5f9cd914cc151c186358d509d44520d4a1fb46c5af2dea39ed06a897c7cfe58b9c93316fa6c81081b7a30f5e43d271ca2aec0d + +production: + <<: *default \ No newline at end of file diff --git a/cron/clear_cache b/cron/clear_cache new file mode 100644 index 0000000000000000000000000000000000000000..ae1aad9958b411829ccc5ec2a59d7c4490a03101 --- /dev/null +++ b/cron/clear_cache @@ -0,0 +1 @@ +0 0 * * * bash -c "source /api/environment && cd /api && rake judge0:clear_cache &> ./log/clear_cache.log" diff --git a/cron/telemetry b/cron/telemetry new file mode 100644 index 0000000000000000000000000000000000000000..33ab0a595a417c3af8a2401f8d4f90ffa06d8080 --- /dev/null +++ b/cron/telemetry @@ -0,0 +1 @@ +0 */12 * * * bash -c "source /api/environment && cd /api && ./bin/telemetry &> ./log/telemetry.log" diff --git a/db/languages/active.rb b/db/languages/active.rb new file mode 100644 index 0000000000000000000000000000000000000000..069a6ac297df3aaa0792f9d10012b57342cb191a --- /dev/null +++ b/db/languages/active.rb @@ -0,0 +1,360 @@ +@languages ||= [] +@languages += +[ + { + id: 43, + name: "Plain Text", + is_archived: false, + source_file: "text.txt", + run_cmd: "/bin/cat text.txt" + }, + { + id: 44, + name: "Executable", + is_archived: false, + source_file: "a.out", + run_cmd: "/bin/chmod +x a.out && ./a.out" + }, + { + id: 45, + name: "Assembly (NASM 2.14.02)", + is_archived: false, + source_file: "main.asm", + compile_cmd: "/usr/local/nasm-2.14.02/bin/nasmld -f elf64 %s main.asm", + run_cmd: "./a.out" + }, + { + id: 46, + name: "Bash (5.0.0)", + is_archived: false, + source_file: "script.sh", + run_cmd: "/usr/local/bash-5.0/bin/bash script.sh" + }, + { + id: 47, + name: "Basic (FBC 1.07.1)", + is_archived: false, + source_file: "main.bas", + compile_cmd: "/usr/local/fbc-1.07.1/bin/fbc %s main.bas", + run_cmd: "./main" + }, + { + id: 48, + name: "C (GCC 7.4.0)", + is_archived: false, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-7.4.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 49, + name: "C (GCC 8.3.0)", + is_archived: false, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-8.3.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 50, + name: "C (GCC 9.2.0)", + is_archived: false, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-9.2.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 51, + name: "C# (Mono 6.6.0.161)", + is_archived: false, + source_file: "Main.cs", + compile_cmd: "/usr/local/mono-6.6.0.161/bin/mcs %s Main.cs", + run_cmd: "/usr/local/mono-6.6.0.161/bin/mono Main.exe" + }, + { + id: 52, + name: "C++ (GCC 7.4.0)", + is_archived: false, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-7.4.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-7.4.0/lib64 ./a.out" + }, + { + id: 53, + name: "C++ (GCC 8.3.0)", + is_archived: false, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-8.3.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-8.3.0/lib64 ./a.out" + }, + { + id: 54, + name: "C++ (GCC 9.2.0)", + is_archived: false, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-9.2.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-9.2.0/lib64 ./a.out" + }, + { + id: 55, + name: "Common Lisp (SBCL 2.0.0)", + is_archived: false, + source_file: "script.lisp", + run_cmd: "SBCL_HOME=/usr/local/sbcl-2.0.0/lib/sbcl /usr/local/sbcl-2.0.0/bin/sbcl --script script.lisp" + }, + { + id: 56, + name: "D (DMD 2.089.1)", + is_archived: false, + source_file: "main.d", + compile_cmd: "/usr/local/d-2.089.1/linux/bin64/dmd %s main.d", + run_cmd: "./main" + }, + { + id: 57, + name: "Elixir (1.9.4)", + is_archived: false, + source_file: "script.exs", + run_cmd: "/usr/local/elixir-1.9.4/bin/elixir script.exs" + }, + { + id: 58, + name: "Erlang (OTP 22.2)", + is_archived: false, + source_file: "main.erl", + run_cmd: "/bin/sed -i '1s/^/\\n/' main.erl && /usr/local/erlang-22.2/bin/escript main.erl" + }, + { + id: 59, + name: "Fortran (GFortran 9.2.0)", + is_archived: false, + source_file: "main.f90", + compile_cmd: "/usr/local/gcc-9.2.0/bin/gfortran %s main.f90", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-9.2.0/lib64 ./a.out" + }, + { + id: 60, + name: "Go (1.13.5)", + is_archived: false, + source_file: "main.go", + compile_cmd: "GOCACHE=/tmp/.cache/go-build /usr/local/go-1.13.5/bin/go build %s main.go", + run_cmd: "./main" + }, + { + id: 61, + name: "Haskell (GHC 8.8.1)", + is_archived: false, + source_file: "main.hs", + compile_cmd: "/usr/local/ghc-8.8.1/bin/ghc %s main.hs", + run_cmd: "./main" + }, + { + id: 62, + name: "Java (OpenJDK 13.0.1)", + is_archived: false, + source_file: "Main.java", + compile_cmd: "/usr/local/openjdk13/bin/javac %s Main.java", + run_cmd: "/usr/local/openjdk13/bin/java Main" + }, + { + id: 63, + name: "JavaScript (Node.js 12.14.0)", + is_archived: false, + source_file: "script.js", + run_cmd: "/usr/local/node-12.14.0/bin/node script.js" + }, + { + id: 64, + name: "Lua (5.3.5)", + is_archived: false, + source_file: "script.lua", + compile_cmd: "/usr/local/lua-5.3.5/luac53 %s script.lua", + run_cmd: "/usr/local/lua-5.3.5/lua53 ./luac.out" + }, + { + id: 65, + name: "OCaml (4.09.0)", + is_archived: false, + source_file: "main.ml", + compile_cmd: "/usr/local/ocaml-4.09.0/bin/ocamlc %s main.ml", + run_cmd: "./a.out" + }, + { + id: 66, + name: "Octave (5.1.0)", + is_archived: false, + source_file: "script.m", + run_cmd: "/usr/local/octave-5.1.0/bin/octave-cli -q --no-gui --no-history script.m" + }, + { + id: 67, + name: "Pascal (FPC 3.0.4)", + is_archived: false, + source_file: "main.pas", + compile_cmd: "/usr/local/fpc-3.0.4/bin/fpc %s main.pas", + run_cmd: "./main" + }, + { + id: 68, + name: "PHP (7.4.1)", + is_archived: false, + source_file: "script.php", + run_cmd: "/usr/local/php-7.4.1/bin/php script.php" + }, + { + id: 69, + name: "Prolog (GNU Prolog 1.4.5)", + is_archived: false, + source_file: "main.pro", + compile_cmd: "PATH=\"/usr/local/gprolog-1.4.5/gprolog-1.4.5/bin:$PATH\" /usr/local/gprolog-1.4.5/gprolog-1.4.5/bin/gplc --no-top-level %s main.pro", + run_cmd: "./main" + }, + { + id: 70, + name: "Python (2.7.17)", + is_archived: false, + source_file: "script.py", + run_cmd: "/usr/local/python-2.7.17/bin/python2 script.py" + }, + { + id: 71, + name: "Python (3.8.1)", + is_archived: false, + source_file: "script.py", + run_cmd: "/usr/local/python-3.8.1/bin/python3 script.py" + }, + { + id: 72, + name: "Ruby (2.7.0)", + is_archived: false, + source_file: "script.rb", + run_cmd: "/usr/local/ruby-2.7.0/bin/ruby script.rb" + }, + { + id: 73, + name: "Rust (1.40.0)", + is_archived: false, + source_file: "main.rs", + compile_cmd: "/usr/local/rust-1.40.0/bin/rustc %s main.rs", + run_cmd: "./main" + }, + { + id: 74, + name: "TypeScript (3.7.4)", + is_archived: false, + source_file: "script.ts", + compile_cmd: "/usr/bin/tsc %s script.ts", + run_cmd: "/usr/local/node-12.14.0/bin/node script.js" + }, + { + id: 75, + name: "C (Clang 7.0.1)", + is_archived: false, + source_file: "main.c", + compile_cmd: "/usr/bin/clang-7 %s main.c", + run_cmd: "./a.out" + }, + { + id: 76, + name: "C++ (Clang 7.0.1)", + is_archived: false, + source_file: "main.cpp", + compile_cmd: "/usr/bin/clang++-7 %s main.cpp", + run_cmd: "./a.out" + }, + { + id: 77, + name: "COBOL (GnuCOBOL 2.2)", + is_archived: false, + source_file: "main.cob", + compile_cmd: "/usr/local/gnucobol-2.2/bin/cobc -free -x %s main.cob", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gnucobol-2.2/lib ./main" + }, + { + id: 78, + name: "Kotlin (1.3.70)", + is_archived: false, + source_file: "Main.kt", + compile_cmd: "/usr/local/kotlin-1.3.70/bin/kotlinc %s Main.kt", + run_cmd: "/usr/local/kotlin-1.3.70/bin/kotlin MainKt" + }, + { + id: 79, + name: "Objective-C (Clang 7.0.1)", + is_archived: false, + source_file: "main.m", + compile_cmd: "/usr/bin/clang-7 `gnustep-config --objc-flags | sed 's/-W[^ ]* //g'` `gnustep-config --base-libs | sed 's/-shared-libgcc//'` -I/usr/lib/gcc/x86_64-linux-gnu/8/include main.m %s", + run_cmd: "./a.out" + }, + { + id: 80, + name: "R (4.0.0)", + is_archived: false, + source_file: "script.r", + run_cmd: "/usr/local/r-4.0.0/bin/Rscript script.r" + }, + { + id: 81, + name: "Scala (2.13.2)", + is_archived: false, + source_file: "Main.scala", + compile_cmd: "/usr/local/scala-2.13.2/bin/scalac %s Main.scala", + run_cmd: "/usr/local/scala-2.13.2/bin/scala Main" + }, + { + id: 82, + name: "SQL (SQLite 3.27.2)", + is_archived: false, + source_file: "script.sql", + run_cmd: "/bin/cat script.sql | /usr/bin/sqlite3 db.sqlite" + }, + { + id: 83, + name: "Swift (5.2.3)", + is_archived: false, + source_file: "Main.swift", + compile_cmd: "/usr/local/swift-5.2.3/bin/swiftc %s Main.swift", + run_cmd: "./Main" + }, + { + id: 84, + name: "Visual Basic.Net (vbnc 0.0.0.5943)", + is_archived: false, + source_file: "Main.vb", + compile_cmd: "/usr/bin/vbnc %s Main.vb", + run_cmd: "/usr/bin/mono Main.exe" + }, + { + id: 85, + name: "Perl (5.28.1)", + is_archived: false, + source_file: "script.pl", + run_cmd: "/usr/bin/perl script.pl" + }, + { + id: 86, + name: "Clojure (1.10.1)", + is_archived: false, + source_file: "main.clj", + run_cmd: "/usr/local/bin/java -jar /usr/local/clojure-1.10.1/clojure.jar main.clj" + }, + { + id: 87, + name: "F# (.NET Core SDK 3.1.202)", + is_archived: false, + source_file: "script.fsx", + run_cmd: "mkdir -p ~/.dotnet && touch ~/.dotnet/3.1.202.dotnetFirstUseSentinel && /usr/local/dotnet-sdk/dotnet fsi script.fsx" + }, + { + id: 88, + name: "Groovy (3.0.3)", + is_archived: false, + source_file: "script.groovy", + compile_cmd: "/usr/local/groovy-3.0.3/bin/groovyc %s script.groovy", + run_cmd: "/usr/local/bin/java -cp \".:/usr/local/groovy-3.0.3/lib/*\" script" + }, + { + id: 89, + name: "Multi-file program", + is_archived: false, + } +] \ No newline at end of file diff --git a/db/languages/archived.rb b/db/languages/archived.rb new file mode 100644 index 0000000000000000000000000000000000000000..baaaf7e2dea65cabd143ab337ec19870655f0bb7 --- /dev/null +++ b/db/languages/archived.rb @@ -0,0 +1,324 @@ +@languages ||= [] +@languages += +[ + { + id: 1, + name: "Bash (4.4)", + is_archived: true, + source_file: "script.sh", + run_cmd: "/usr/local/bash-4.4/bin/bash script.sh" + }, + { + id: 2, + name: "Bash (4.0)", + is_archived: true, + source_file: "script.sh", + run_cmd: "/usr/local/bash-4.0/bin/bash script.sh" + }, + { + id: 3, + name: "Basic (fbc 1.05.0)", + is_archived: true, + source_file: "main.bas", + compile_cmd: "/usr/local/fbc-1.05.0/bin/fbc %s main.bas", + run_cmd: "./main" + }, + { + id: 4, + name: "C (gcc 7.2.0)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-7.2.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 5, + name: "C (gcc 6.4.0)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-6.4.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 6, + name: "C (gcc 6.3.0)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-6.3.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 7, + name: "C (gcc 5.4.0)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-5.4.0/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 8, + name: "C (gcc 4.9.4)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-4.9.4/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + { + id: 9, + name: "C (gcc 4.8.5)", + is_archived: true, + source_file: "main.c", + compile_cmd: "/usr/local/gcc-4.8.5/bin/gcc %s main.c", + run_cmd: "./a.out" + }, + + { + id: 10, + name: "C++ (g++ 7.2.0)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-7.2.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-7.2.0/lib64 ./a.out" + }, + { + id: 11, + name: "C++ (g++ 6.4.0)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-6.4.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-6.4.0/lib64 ./a.out" + }, + { + id: 12, + name: "C++ (g++ 6.3.0)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-6.3.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-6.3.0/lib64 ./a.out" + }, + { + id: 13, + name: "C++ (g++ 5.4.0)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-5.4.0/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-5.4.0/lib64 ./a.out" + }, + { + id: 14, + name: "C++ (g++ 4.9.4)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-4.9.4/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-4.9.4/lib64 ./a.out" + }, + { + id: 15, + name: "C++ (g++ 4.8.5)", + is_archived: true, + source_file: "main.cpp", + compile_cmd: "/usr/local/gcc-4.8.5/bin/g++ %s main.cpp", + run_cmd: "LD_LIBRARY_PATH=/usr/local/gcc-4.8.5/lib64 ./a.out" + }, + { + id: 16, + name: "C# (mono 5.4.0.167)", + is_archived: true, + source_file: "Main.cs", + compile_cmd: "/usr/local/mono-5.4.0.167/bin/mcs %s Main.cs", + run_cmd: "/usr/local/mono-5.4.0.167/bin/mono Main.exe" + }, + { + id: 17, + name: "C# (mono 5.2.0.224)", + is_archived: true, + source_file: "Main.cs", + compile_cmd: "/usr/local/mono-5.2.0.224/bin/mcs %s Main.cs", + run_cmd: "/usr/local/mono-5.2.0.224/bin/mono Main.exe" + }, + { + id: 18, + name: "Clojure (1.8.0)", + is_archived: true, + source_file: "main.clj", + run_cmd: "/usr/bin/java -cp /usr/local/clojure-1.8.0/clojure-1.8.0.jar clojure.main main.clj" + }, + { + id: 19, + name: "Crystal (0.23.1)", + is_archived: true, + source_file: "main.cr", + compile_cmd: "/usr/local/crystal-0.23.1-3/bin/crystal build %s main.cr", + run_cmd: "./main" + }, + { + id: 20, + name: "Elixir (1.5.1)", + is_archived: true, + source_file: "main.exs", + run_cmd: "/usr/local/elixir-1.5.1/bin/elixir main.exs" + }, + { + id: 21, + name: "Erlang (OTP 20.0)", + is_archived: true, + source_file: "main.erl", + run_cmd: "/bin/sed -i \"s/^/\\n/\" main.erl && /usr/local/erlang-20.0/bin/escript main.erl" + }, + { + id: 22, + name: "Go (1.9)", + is_archived: true, + source_file: "main.go", + compile_cmd: "/usr/local/go-1.9/bin/go build %s main.go", + run_cmd: "./main" + }, + { + id: 23, + name: "Haskell (ghc 8.2.1)", + is_archived: true, + source_file: "main.hs", + compile_cmd: "/usr/local/ghc-8.2.1/bin/ghc %s main.hs", + run_cmd: "./main" + }, + { + id: 24, + name: "Haskell (ghc 8.0.2)", + is_archived: true, + source_file: "main.hs", + compile_cmd: "/usr/local/ghc-8.0.2/bin/ghc %s main.hs", + run_cmd: "./main" + }, + { + id: 25, + name: "Insect (5.0.0)", + is_archived: true, + source_file: "main.ins", + run_cmd: "/usr/local/insect-5.0.0/insect main.ins" + }, + { + id: 26, + name: "Java (OpenJDK 9 with Eclipse OpenJ9)", + is_archived: true, + source_file: "Main.java", + compile_cmd: "/usr/local/openjdk9-openj9/bin/javac %s Main.java", + run_cmd: "/usr/local/openjdk9-openj9/bin/java Main" + }, + { + id: 27, + name: "Java (OpenJDK 8)", + is_archived: true, + source_file: "Main.java", + compile_cmd: "/usr/lib/jvm/java-8-openjdk-amd64/bin/javac %s Main.java", + run_cmd: "/usr/lib/jvm/java-8-openjdk-amd64/bin/java Main", + }, + { + id: 28, + name: "Java (OpenJDK 7)", + is_archived: true, + source_file: "Main.java", + compile_cmd: "/usr/lib/jvm/java-7-openjdk-amd64/bin/javac %s Main.java", + run_cmd: "/usr/lib/jvm/java-7-openjdk-amd64/bin/java Main", + }, + { + id: 29, + name: "JavaScript (nodejs 8.5.0)", + is_archived: true, + source_file: "main.js", + run_cmd: "/usr/local/node-8.5.0/bin/node main.js" + }, + { + id: 30, + name: "JavaScript (nodejs 7.10.1)", + is_archived: true, + source_file: "main.js", + run_cmd: "/usr/local/node-7.10.1/bin/node main.js" + }, + { + id: 31, + name: "OCaml (4.05.0)", + is_archived: true, + source_file: "main.ml", + compile_cmd: "/usr/local/ocaml-4.05.0/bin/ocamlc %s main.ml", + run_cmd: "./a.out" + }, + { + id: 32, + name: "Octave (4.2.0)", + is_archived: true, + source_file: "file.m", + run_cmd: "/usr/local/octave-4.2.0/bin/octave-cli -q --no-gui --no-history file.m" + }, + { + id: 33, + name: "Pascal (fpc 3.0.0)", + is_archived: true, + source_file: "main.pas", + compile_cmd: "/usr/local/fpc-3.0.0/bin/fpc %s main.pas", + run_cmd: "./main" + }, + { + id: 34, + name: "Python (3.6.0)", + is_archived: true, + source_file: "main.py", + run_cmd: "/usr/local/python-3.6.0/bin/python3 main.py" + }, + { + id: 35, + name: "Python (3.5.3)", + is_archived: true, + source_file: "main.py", + run_cmd: "/usr/local/python-3.5.3/bin/python3 main.py" + }, + { + id: 36, + name: "Python (2.7.9)", + is_archived: true, + source_file: "main.py", + run_cmd: "/usr/local/python-2.7.9/bin/python main.py" + }, + { + id: 37, + name: "Python (2.6.9)", + is_archived: true, + source_file: "main.py", + run_cmd: "/usr/local/python-2.6.9/bin/python main.py" + }, + { + id: 38, + name: "Ruby (2.4.0)", + is_archived: true, + source_file: "main.rb", + run_cmd: "/usr/local/ruby-2.4.0/bin/ruby main.rb" + }, + { + id: 39, + name: "Ruby (2.3.3)", + is_archived: true, + source_file: "main.rb", + run_cmd: "/usr/local/ruby-2.3.3/bin/ruby main.rb" + }, + { + id: 40, + name: "Ruby (2.2.6)", + is_archived: true, + source_file: "main.rb", + run_cmd: "/usr/local/ruby-2.2.6/bin/ruby main.rb" + }, + { + id: 41, + name: "Ruby (2.1.9)", + is_archived: true, + source_file: "main.rb", + run_cmd: "/usr/local/ruby-2.1.9/bin/ruby main.rb" + }, + { + id: 42, + name: "Rust (1.20.0)", + is_archived: true, + source_file: "main.rs", + compile_cmd: "/usr/local/rust-1.20.0/bin/rustc %s main.rs", + run_cmd: "./main" + } +] \ No newline at end of file diff --git a/db/migrate/20160903140859_create_languages.rb b/db/migrate/20160903140859_create_languages.rb new file mode 100644 index 0000000000000000000000000000000000000000..177d1f70bc9651c235959e09fb87dd881e0df410 --- /dev/null +++ b/db/migrate/20160903140859_create_languages.rb @@ -0,0 +1,9 @@ +class CreateLanguages < ActiveRecord::Migration[5.0] + def change + create_table :languages do |t| + t.string :name + t.string :compile_cmd + t.string :run_cmd + end + end +end diff --git a/db/migrate/20160903211542_create_submissions.rb b/db/migrate/20160903211542_create_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..cde8b1327c17a2fb71d68539e598b28fa71fceab --- /dev/null +++ b/db/migrate/20160903211542_create_submissions.rb @@ -0,0 +1,14 @@ +class CreateSubmissions < ActiveRecord::Migration[5.0] + def change + create_table :submissions do |t| + t.text :source_code + t.integer :language_id + t.text :input + t.text :expected_output + t.text :actual_output + t.integer :status_id + t.datetime :created_at + t.datetime :finished_at + end + end +end diff --git a/db/migrate/20160905015919_add_source_file_to_language.rb b/db/migrate/20160905015919_add_source_file_to_language.rb new file mode 100644 index 0000000000000000000000000000000000000000..2657f84fac8f04c84aad6e1eaed22130c09432a3 --- /dev/null +++ b/db/migrate/20160905015919_add_source_file_to_language.rb @@ -0,0 +1,5 @@ +class AddSourceFileToLanguage < ActiveRecord::Migration[5.0] + def change + add_column :languages, :source_file, :string + end +end diff --git a/db/migrate/20160905030833_add_time_to_submission.rb b/db/migrate/20160905030833_add_time_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..ddd8a81a9cae8fff1e399efe3b68c26db3fe12d1 --- /dev/null +++ b/db/migrate/20160905030833_add_time_to_submission.rb @@ -0,0 +1,5 @@ +class AddTimeToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :time, :decimal + end +end diff --git a/db/migrate/20160907052244_add_memory_to_submission.rb b/db/migrate/20160907052244_add_memory_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..aeec5af5b78886f281eaec7035035648014a6d7e --- /dev/null +++ b/db/migrate/20160907052244_add_memory_to_submission.rb @@ -0,0 +1,5 @@ +class AddMemoryToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :memory, :integer + end +end diff --git a/db/migrate/20170131231840_rename_actual_output_in_submissions_to_stdout.rb b/db/migrate/20170131231840_rename_actual_output_in_submissions_to_stdout.rb new file mode 100644 index 0000000000000000000000000000000000000000..1733c81cd877e88bdf6d611ca62582f9d0bd0940 --- /dev/null +++ b/db/migrate/20170131231840_rename_actual_output_in_submissions_to_stdout.rb @@ -0,0 +1,5 @@ +class RenameActualOutputInSubmissionsToStdout < ActiveRecord::Migration[5.0] + def change + rename_column :submissions, :actual_output, :stdout + end +end diff --git a/db/migrate/20170131233631_add_stderr_to_submissions.rb b/db/migrate/20170131233631_add_stderr_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..3006c70510cfc6aaa59e223516771c53245e0fde --- /dev/null +++ b/db/migrate/20170131233631_add_stderr_to_submissions.rb @@ -0,0 +1,5 @@ +class AddStderrToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :stderr, :text + end +end diff --git a/db/migrate/20170201000546_add_token_to_submission.rb b/db/migrate/20170201000546_add_token_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..4a8f286072da6f43bb1f0d9c3c2b95be5580ee6f --- /dev/null +++ b/db/migrate/20170201000546_add_token_to_submission.rb @@ -0,0 +1,5 @@ +class AddTokenToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :token, :string + end +end diff --git a/db/migrate/20170203021217_add_index_to_submission.rb b/db/migrate/20170203021217_add_index_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..605b2fff6c44aa4ba870dee7a16739b957b9c1a6 --- /dev/null +++ b/db/migrate/20170203021217_add_index_to_submission.rb @@ -0,0 +1,5 @@ +class AddIndexToSubmission < ActiveRecord::Migration[5.0] + def change + add_index :submissions, :token + end +end diff --git a/db/migrate/20170203023903_add_number_of_runs_to_submission.rb b/db/migrate/20170203023903_add_number_of_runs_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..7ed19f84174795025bcd1aeb89d01e922bc98242 --- /dev/null +++ b/db/migrate/20170203023903_add_number_of_runs_to_submission.rb @@ -0,0 +1,5 @@ +class AddNumberOfRunsToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :number_of_runs, :integer + end +end diff --git a/db/migrate/20170203215830_add_configuration_to_submission.rb b/db/migrate/20170203215830_add_configuration_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..15639000bd216d47cce8dd8fc1f260edda169e26 --- /dev/null +++ b/db/migrate/20170203215830_add_configuration_to_submission.rb @@ -0,0 +1,13 @@ +class AddConfigurationToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :cpu_time_limit, :decimal + add_column :submissions, :cpu_extra_time, :decimal + add_column :submissions, :wall_time_limit, :decimal + add_column :submissions, :memory_limit, :integer + add_column :submissions, :stack_limit, :integer + add_column :submissions, :max_processes_and_or_threads, :integer + add_column :submissions, :enable_per_process_and_thread_time_limit, :boolean + add_column :submissions, :enable_per_process_and_thread_memory_limit, :boolean + add_column :submissions, :max_file_size, :integer + end +end diff --git a/db/migrate/20170422122148_change_encode_all_submissions.rb b/db/migrate/20170422122148_change_encode_all_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..837f7543ccc64fd0653ea8fdfeb42b6301cd40f7 --- /dev/null +++ b/db/migrate/20170422122148_change_encode_all_submissions.rb @@ -0,0 +1,12 @@ +class ChangeEncodeAllSubmissions < ActiveRecord::Migration[5.0] + def change + Submission.all.each do |submission| + submission.source_code = submission[:source_code] + submission.input = submission[:input] + submission.stdout = submission[:stdout] + submission.expected_output = submission[:expected_output] + submission.stderr = submission[:stderr] + submission.save + end + end +end diff --git a/db/migrate/20170919210318_add_compile_output_to_submissions.rb b/db/migrate/20170919210318_add_compile_output_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..e171b2a96f1e95de24b73c2d24d436fbd04dea7a --- /dev/null +++ b/db/migrate/20170919210318_add_compile_output_to_submissions.rb @@ -0,0 +1,5 @@ +class AddCompileOutputToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :compile_output, :text + end +end diff --git a/db/migrate/20170919215014_add_exit_code_exit_signal_and_message_to_submissions.rb b/db/migrate/20170919215014_add_exit_code_exit_signal_and_message_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..e212582b8aeedbe475308c2726615822e4b44f4c --- /dev/null +++ b/db/migrate/20170919215014_add_exit_code_exit_signal_and_message_to_submissions.rb @@ -0,0 +1,7 @@ +class AddExitCodeExitSignalAndMessageToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :exit_code, :integer + add_column :submissions, :exit_signal, :integer + add_column :submissions, :message, :text + end +end diff --git a/db/migrate/20170928174721_add_wall_time_to_submissions.rb b/db/migrate/20170928174721_add_wall_time_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..320ea19095ea7a21510bc0351282a5756add7f8d --- /dev/null +++ b/db/migrate/20170928174721_add_wall_time_to_submissions.rb @@ -0,0 +1,5 @@ +class AddWallTimeToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :wall_time, :decimal + end +end diff --git a/db/migrate/20170929175654_rename_input_to_stdin_in_submissions.rb b/db/migrate/20170929175654_rename_input_to_stdin_in_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..1de25035e73385033a05e6f752762509c32e23ea --- /dev/null +++ b/db/migrate/20170929175654_rename_input_to_stdin_in_submissions.rb @@ -0,0 +1,5 @@ +class RenameInputToStdinInSubmissions < ActiveRecord::Migration[5.0] + def change + rename_column :submissions, :input, :stdin + end +end diff --git a/db/migrate/20190921115544_add_compiler_options_to_submission.rb b/db/migrate/20190921115544_add_compiler_options_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..6c9d33fa1d318392d94b5f52acf4bf19f7bbfdf6 --- /dev/null +++ b/db/migrate/20190921115544_add_compiler_options_to_submission.rb @@ -0,0 +1,5 @@ +class AddCompilerOptionsToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :compiler_options, :string + end +end diff --git a/db/migrate/20190921193416_add_command_line_arguments_to_submission.rb b/db/migrate/20190921193416_add_command_line_arguments_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..265ef8a393e134c8111fb1b0beb9127b0bd93022 --- /dev/null +++ b/db/migrate/20190921193416_add_command_line_arguments_to_submission.rb @@ -0,0 +1,5 @@ +class AddCommandLineArgumentsToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :command_line_arguments, :string + end +end diff --git a/db/migrate/20191230001624_add_is_archived_to_languages.rb b/db/migrate/20191230001624_add_is_archived_to_languages.rb new file mode 100644 index 0000000000000000000000000000000000000000..d0fd5455fd3946c396a8f553e288049797713ce5 --- /dev/null +++ b/db/migrate/20191230001624_add_is_archived_to_languages.rb @@ -0,0 +1,5 @@ +class AddIsArchivedToLanguages < ActiveRecord::Migration[5.0] + def change + add_column :languages, :is_archived, :bool, default: false + end +end diff --git a/db/migrate/20200113231131_add_redirect_stderr_to_stdout_to_submission.rb b/db/migrate/20200113231131_add_redirect_stderr_to_stdout_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..c53c7df52f669abe64739ef6fe8f5513f8e010bc --- /dev/null +++ b/db/migrate/20200113231131_add_redirect_stderr_to_stdout_to_submission.rb @@ -0,0 +1,5 @@ +class AddRedirectStderrToStdoutToSubmission < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :redirect_stderr_to_stdout, :boolean + end +end diff --git a/db/migrate/20200114220437_add_callback_url_to_submissions.rb b/db/migrate/20200114220437_add_callback_url_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..233f13e36ce6c7e00986c2236e4ff980c480cfd5 --- /dev/null +++ b/db/migrate/20200114220437_add_callback_url_to_submissions.rb @@ -0,0 +1,5 @@ +class AddCallbackUrlToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :callback_url, :string + end +end diff --git a/db/migrate/20200115205044_add_additional_files_to_submissions.rb b/db/migrate/20200115205044_add_additional_files_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..15e2abed8bd113c88d61942a9e03a5183a7f2648 --- /dev/null +++ b/db/migrate/20200115205044_add_additional_files_to_submissions.rb @@ -0,0 +1,5 @@ +class AddAdditionalFilesToSubmissions < ActiveRecord::Migration[5.0] + def change + add_column :submissions, :additional_files, :binary + end +end diff --git a/db/migrate/20200327224155_create_clients.rb b/db/migrate/20200327224155_create_clients.rb new file mode 100644 index 0000000000000000000000000000000000000000..9eb7281b3ebbd7f73480dfdc54a1bb63207db5c5 --- /dev/null +++ b/db/migrate/20200327224155_create_clients.rb @@ -0,0 +1,6 @@ +class CreateClients < ActiveRecord::Migration[5.0] + def change + create_table :clients, id: :string do |t| + end + end +end diff --git a/db/migrate/20210308152656_add_enable_network_to_submissions.rb b/db/migrate/20210308152656_add_enable_network_to_submissions.rb new file mode 100644 index 0000000000000000000000000000000000000000..afd93a4342d5a9db92c1bc9cbf832a421676c503 --- /dev/null +++ b/db/migrate/20210308152656_add_enable_network_to_submissions.rb @@ -0,0 +1,5 @@ +class AddEnableNetworkToSubmissions < ActiveRecord::Migration[5.2] + def change + add_column :submissions, :enable_network, :boolean + end +end diff --git a/db/migrate/20220528122710_add_started_at_to_submission.rb b/db/migrate/20220528122710_add_started_at_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..b03ae6e1c89e31a5b9192b80830b6ae120049cf9 --- /dev/null +++ b/db/migrate/20220528122710_add_started_at_to_submission.rb @@ -0,0 +1,6 @@ +class AddStartedAtToSubmission < ActiveRecord::Migration[5.2] + def change + add_column :submissions, :started_at, :datetime + add_column :submissions, :queued_at, :datetime + end +end diff --git a/db/migrate/20220528131626_add_updated_at_to_submission.rb b/db/migrate/20220528131626_add_updated_at_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..00df5d99d8a4cdf472e8938c68d264b1dbc7f121 --- /dev/null +++ b/db/migrate/20220528131626_add_updated_at_to_submission.rb @@ -0,0 +1,5 @@ +class AddUpdatedAtToSubmission < ActiveRecord::Migration[5.2] + def change + add_column :submissions, :updated_at, :datetime + end +end diff --git a/db/migrate/20220528155848_add_hosts_to_submission.rb b/db/migrate/20220528155848_add_hosts_to_submission.rb new file mode 100644 index 0000000000000000000000000000000000000000..a639a54828556d2fc5fa61f449fc42528fbb1734 --- /dev/null +++ b/db/migrate/20220528155848_add_hosts_to_submission.rb @@ -0,0 +1,6 @@ +class AddHostsToSubmission < ActiveRecord::Migration[5.2] + def change + add_column :submissions, :queue_host, :string + add_column :submissions, :execution_host, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000000000000000000000000000000000..e91105ab43c3c36d87dd0a7e9150fb94d33ceb47 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,71 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2022_05_28_155848) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "clients", id: :string, force: :cascade do |t| + end + + create_table "languages", id: :serial, force: :cascade do |t| + t.string "name" + t.string "compile_cmd" + t.string "run_cmd" + t.string "source_file" + t.boolean "is_archived", default: false + end + + create_table "submissions", id: :serial, force: :cascade do |t| + t.text "source_code" + t.integer "language_id" + t.text "stdin" + t.text "expected_output" + t.text "stdout" + t.integer "status_id" + t.datetime "created_at" + t.datetime "finished_at" + t.decimal "time" + t.integer "memory" + t.text "stderr" + t.string "token" + t.integer "number_of_runs" + t.decimal "cpu_time_limit" + t.decimal "cpu_extra_time" + t.decimal "wall_time_limit" + t.integer "memory_limit" + t.integer "stack_limit" + t.integer "max_processes_and_or_threads" + t.boolean "enable_per_process_and_thread_time_limit" + t.boolean "enable_per_process_and_thread_memory_limit" + t.integer "max_file_size" + t.text "compile_output" + t.integer "exit_code" + t.integer "exit_signal" + t.text "message" + t.decimal "wall_time" + t.string "compiler_options" + t.string "command_line_arguments" + t.boolean "redirect_stderr_to_stdout" + t.string "callback_url" + t.binary "additional_files" + t.boolean "enable_network" + t.datetime "started_at" + t.datetime "queued_at" + t.datetime "updated_at" + t.string "queue_host" + t.string "execution_host" + t.index ["token"], name: "index_submissions_on_token" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000000000000000000000000000000000..6a6fabd817071eec0014c325f3a5798d40a6d3d5 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,16 @@ +require_relative 'languages/archived' +require_relative 'languages/active' + +ActiveRecord::Base.transaction do + Language.unscoped.delete_all + @languages.each_with_index do |language, index| + Language.create( + id: language[:id], + name: language[:name], + is_archived: language[:is_archived], + source_file: language[:source_file], + compile_cmd: language[:compile_cmd], + run_cmd: language[:run_cmd], + ) + end +end diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000000000000000000000000000000000000..a166dbc6f5ce95b10f7f488deb1013816033ebf0 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,31 @@ +services: + judge0: + image: judge0/judge0:latest-dev + build: + context: . + target: development + volumes: + - .:/api + ports: + - "2358:2358" + - "3001:3001" # For ./scripts/dev/serve-docs + privileged: true + + db: + image: postgres:16.2 + env_file: judge0.conf + volumes: + - data:/var/lib/postgresql/data/ + restart: always + + redis: + image: redis:7.2.4 + command: [ + "bash", "-c", + 'docker-entrypoint.sh --appendonly no --requirepass "$$REDIS_PASSWORD"' + ] + env_file: judge0.conf + restart: always + +volumes: + data: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..a2d9ff2abdd9c7f39a5032ede87e4348bd559e63 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +x-logging: + &default-logging + logging: + driver: json-file + options: + max-size: 100M + +services: + server: + image: judge0/judge0:latest + volumes: + - ./judge0.conf:/judge0.conf:ro + ports: + - "2358:2358" + privileged: true + <<: *default-logging + restart: always + + worker: + image: judge0/judge0:latest + command: ["./scripts/workers"] + volumes: + - ./judge0.conf:/judge0.conf:ro + privileged: true + <<: *default-logging + restart: always + + db: + image: postgres:16.2 + env_file: judge0.conf + volumes: + - data:/var/lib/postgresql/data/ + <<: *default-logging + restart: always + + redis: + image: redis:7.2.4 + command: [ + "bash", "-c", + 'docker-entrypoint.sh --appendonly no --requirepass "$$REDIS_PASSWORD"' + ] + env_file: judge0.conf + <<: *default-logging + restart: always + +volumes: + data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f4e99112e8e0c70eac3d84b8a78e3dc7c5834f8 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo cron +exec "$@" diff --git a/docs/api/_unauthenticated.md b/docs/api/_unauthenticated.md new file mode 100644 index 0000000000000000000000000000000000000000..73a7afbeed04f8c1b32b6ded1f0e41f401bc8d35 --- /dev/null +++ b/docs/api/_unauthenticated.md @@ -0,0 +1,3 @@ ++ Response 401 + Authentication failed. Please read about [authentication](#authentication) process. + + Body \ No newline at end of file diff --git a/docs/api/_unauthorized.md b/docs/api/_unauthorized.md new file mode 100644 index 0000000000000000000000000000000000000000..126c0b9c3b7c0d95fc0e546e691880bb5ebac706 --- /dev/null +++ b/docs/api/_unauthorized.md @@ -0,0 +1,3 @@ ++ Response 403 + Authorization failed. Please read about [authorization](#authorization) process. + + Body \ No newline at end of file diff --git a/docs/api/authentication/authentication.md b/docs/api/authentication/authentication.md new file mode 100644 index 0000000000000000000000000000000000000000..39685437fb0411c95982f86c7eccb680bcf7511d --- /dev/null +++ b/docs/api/authentication/authentication.md @@ -0,0 +1,35 @@ +# Group Authentication +Administrators of Judge0 can configure Judge0 to require you to have an authentication token (a.k.a. API key). +If that is the case with the instance of Judge0 you are using, then you +should provide `X-Auth-Token` header field in **every** API request. + +## Authenticate [/authenticate] +### Authenticate [POST] +Check if your authentication token is valid. + +::: note +

Note

+* `X-Auth-Token` is default header field name, but administrators of Judge0 instance you are using + can change this default field name. +* Contact administrator of Judge0 instance you are using to get your authentication token. +::: + +::: warning +

Security Warning

+* Although you can send authentication token as URI parameter, **always** send authentication token through headers. +::: + ++ Request + + Headers + ``` + X-Auth-Token: f6583e60-b13b-4228-b554-2eb332ca64e7 + ``` + ++ Response 200 +If your authentication token is valid or authentication is disabled. +If authentication is disabled you do not need an authentication token. + + Body + ++ Response 401 +Authentication failed because your authentication token is invalid. + + Body \ No newline at end of file diff --git a/docs/api/authorization/authorization.md b/docs/api/authorization/authorization.md new file mode 100644 index 0000000000000000000000000000000000000000..28a12464db8c0f6cfdc9d0c98425fc15e259576c --- /dev/null +++ b/docs/api/authorization/authorization.md @@ -0,0 +1,37 @@ +# Group Authorization +To issue some API calls you need to be authorized. For example, you need to be authorized to +[list all submissions](#submissions-submission-get-1) on Judge0. + +## Authorize [/authorize{?X-Auth-User}] +### Authorize [POST] +With this API call you can check if your authorization token is valid. If authentication is enabled you should also +authenticate in this API call. + +::: note +

Note

+* `X-Auth-User` is default header field name, but administrators of Judge0 instance you are using + can change this default field name. +* Contact administrator of Judge0 instance you are using to get your authorization token. +::: + +::: warning +

Security Warning

+* Although you can send authorization token as URI parameter, **always** send authorization token through headers. +::: + ++ Request + + Headers + ``` + X-Auth-User: a1133bc6-a0f6-46bf-a2d8-6157418c6fe2 + ``` + + ++ Response 200 +If your authorization token is valid. + + Body + + + ++ Response 403 +Authorization failed because your authorization token is invalid. + + Body \ No newline at end of file diff --git a/docs/api/docs.md b/docs/api/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..1ac7e04709fc7c9632e3dfa08654b799d65e913e --- /dev/null +++ b/docs/api/docs.md @@ -0,0 +1,77 @@ +FORMAT: 1A +HOST: https://ce.judge0.com + +# Judge0 CE - API Docs + + + +## About +[Judge0](https://ce.judge0.com) is a robust, scalable, and [open-source](https://github.com/judge0/judge0) **online code execution system**. You can use it to build a wide range of applications that need online code execution features. Some examples include competitive programming platforms, e-learning platforms, candidate assessment and recruitment platforms, online code editors, online IDEs, and many more. + +In our research paper [Robust and Scalable Online Code Execution System](https://paper.judge0.com), we present Judge0's modern modular architecture that can be easily deployed and scaled. We study its design, comment on the various challenges in building such systems, and compare it with other available online code execution systems and online judge systems. + +To see Judge0 in action, try [Judge0 IDE](https://ide.judge0.com) - our free and open-source online code editor. You can also try using a [dummy client](/dummy-client.html) that can help you explore and test most of the features of Judge0. + +Easily integrate online code editor with code execution (a.k.a. online compiler) to your website with our [**embeddable web widgets**](https://judge0.com/#judge0-widgets). + +## Features +
    +
  • Quick and easy installation
  • +
  • Rich and verbose API documentation
  • +
  • Scalable architecture
  • +
  • Sandboxed compilation and execution
  • +
  • Support for 60+ languages
  • +
  • Compilation and execution of multi-file programs
  • +
  • Support for additional files alongside the user's program
  • +
  • Support for custom user-defined compiler options, command-line arguments, and time and memory limits
  • +
  • Detailed execution results
  • +
  • Webhooks (HTTP callbacks)
  • +
+ +## Get Started +Get started with Judge0 today on [**Sulu**](https://sparkhub.sulu.sh/apis/judge0/judge0-ce/readme) and get [**20K Free Submissions**](https://sparkhub.sulu.sh/auth/signup) to try it when you sign up. + + +You can also get started with the [**FREE Basic Plan**](https://judge0.com/ce) on RapidAPI or [host it yourself](https://github.com/judge0/judge0/blob/master/CHANGELOG.md#deployment-procedure). + +You can find our detailed plans and pricing [here](https://judge0.com/#pricing). + +**Why should you use Judge0 on Sulu or RapidAPI?** + +Our infrastructure allows you to **focus on building your product** and forget about the know-how of maintaining and scaling Judge0. + +**Sulu or RapidAPI plans are not (good) enough for you?** + +Let's talk. [Contact us](mailto:contact@judge0.com). + +## Flavors +Judge0 comes in two flavors: [Judge0 CE](https://judge0.com/ce) and [Judge0 Extra CE](https://judge0.com/extra-ce). They differ mostly in the [supported languages](https://github.com/judge0/judge0#supported-languages). + +You can find the source code for Judge0 CE on the [`master`](https://github.com/judge0/judge0/tree/master) branch, while you can find the source code for Judge0 Extra CE on the [`extra`](https://github.com/judge0/judge0/tree/extra) branch. + +Judge0 Extra CE is also available on [RapidAPI](https://judge0.com/extra-ce). + +## Version +This document describes Judge0 CE [v1.13.0](https://github.com/judge0/judge0/tree/v1.13.0). + +## Date and time formats +[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard is used. + +Example: `2016-09-11T10:19:35Z` + +## License +Judge0 is licensed under the [GNU General Public License v3.0](https://github.com/judge0/judge0/blob/master/LICENSE). + +## Donate +Your are more than welcome to support Judge0 development on [Patreon](https://www.patreon.com/hermanzdosilovic), via [PayPal](https://paypal.me/hermanzdosilovic) or [Revolut](https://pay.revolut.com/profile/hermancy5). Thank you. + +
+ + + + + + + + + diff --git a/docs/api/health_check/health_check.md b/docs/api/health_check/health_check.md new file mode 100644 index 0000000000000000000000000000000000000000..f91ffc5c71d8bd2883d76fba923f76c31742de45 --- /dev/null +++ b/docs/api/health_check/health_check.md @@ -0,0 +1,2 @@ +# Group Health Check + \ No newline at end of file diff --git a/docs/api/health_check/workers.md b/docs/api/health_check/workers.md new file mode 100644 index 0000000000000000000000000000000000000000..92a6c43c8d4d5d2bef0f3c680098ccbeb2c09a5b --- /dev/null +++ b/docs/api/health_check/workers.md @@ -0,0 +1,23 @@ +## Workers [/workers] +### Workers [GET] +For each queue you will get: +- `queue` name +- queue `size`, i.e. number of submissions that are currently waiting to be processed +- `available` number of workers +- how many workers are `idle` +- how many workers are currently `working` +- how many workers are `paused` +- how many jobs `failed` + ++ Response 200 (application/json) + [ + { + "queue": "default", + "size": 0, + "available": 1, + "idle": 1, + "working": 0, + "paused": 0, + "failed": 0 + } + ] \ No newline at end of file diff --git a/docs/api/hostname.html b/docs/api/hostname.html new file mode 100644 index 0000000000000000000000000000000000000000..1141d82c93b101bb416025f325ae8950786c66df --- /dev/null +++ b/docs/api/hostname.html @@ -0,0 +1,2 @@ + diff --git a/docs/api/information/about.md b/docs/api/information/about.md new file mode 100644 index 0000000000000000000000000000000000000000..d7ff57af953c88452274db69da64064fbe5c9635 --- /dev/null +++ b/docs/api/information/about.md @@ -0,0 +1,12 @@ +## About [/about] +## About [GET] +Returns general information. + ++ Response 200 (application/json) + + Body + { + "version": "1.5.0", + "homepage": "https://judge0.com", + "source_code": "https://github.com/judge0/judge0", + "maintainer": "Herman Zvonimir Došilović " + } \ No newline at end of file diff --git a/docs/api/information/information.md b/docs/api/information/information.md new file mode 100644 index 0000000000000000000000000000000000000000..74bb12f351ba7c063d44611db3912fb85b81bfa8 --- /dev/null +++ b/docs/api/information/information.md @@ -0,0 +1,5 @@ +# Group Information + + + + \ No newline at end of file diff --git a/docs/api/information/isolate.md b/docs/api/information/isolate.md new file mode 100644 index 0000000000000000000000000000000000000000..b5b3269dbe7e33bc4ec1f781bc86b47d20ae2a40 --- /dev/null +++ b/docs/api/information/isolate.md @@ -0,0 +1,3 @@ +## Isolate [/isolate] +## Isolate [GET] +Returns result of [`isolate --version`](https://github.com/ioi/isolate). \ No newline at end of file diff --git a/docs/api/information/license.md b/docs/api/information/license.md new file mode 100644 index 0000000000000000000000000000000000000000..d72d5bf596de52122fe7e69ee3c1269449b01e63 --- /dev/null +++ b/docs/api/information/license.md @@ -0,0 +1,3 @@ +## License [/license] +## License [GET] +Returns a license. \ No newline at end of file diff --git a/docs/api/information/version.md b/docs/api/information/version.md new file mode 100644 index 0000000000000000000000000000000000000000..df5898f6ff44eb5eb31f24c3ac45d361193dbfa6 --- /dev/null +++ b/docs/api/information/version.md @@ -0,0 +1,3 @@ +## Version [/version] +## Version [GET] +Returns current version. \ No newline at end of file diff --git a/docs/api/statistics/statistics.md b/docs/api/statistics/statistics.md new file mode 100644 index 0000000000000000000000000000000000000000..2176c098db01d23fe27d33d58ce46faab9ff687e --- /dev/null +++ b/docs/api/statistics/statistics.md @@ -0,0 +1,8 @@ +# Group Statistics +## Statistics [/statistics] +### Statistics [GET] + +Get some statistics from current instance. Result is cached for 10 minutes. + ++ Parameters + + invalidate_cache (optional, boolean, `false`) ... Set to `true` if you want to invalidate current cache and fetch new statistics. diff --git a/docs/api/statuses_and_languages/get_a_language.md b/docs/api/statuses_and_languages/get_a_language.md new file mode 100644 index 0000000000000000000000000000000000000000..7df927fccdf1119a96d55e1f01b311ddc5d296ac --- /dev/null +++ b/docs/api/statuses_and_languages/get_a_language.md @@ -0,0 +1,14 @@ +## Get a Language [GET] ++ Parameters + + id (required, integer, `1`) ... Language ID. + ++ Response 200 (application/json) + + Body + { + "id": 1, + "name": "Bash (4.4)", + "is_archived": true, + "source_file": "script.sh", + "compile_cmd": null, + "run_cmd": "/usr/local/bash-4.4/bin/bash script.sh" + } \ No newline at end of file diff --git a/docs/api/statuses_and_languages/get_active_and_archived_languages.md b/docs/api/statuses_and_languages/get_active_and_archived_languages.md new file mode 100644 index 0000000000000000000000000000000000000000..b561c85801bb66072ae17a8d38eec8a2bef1ef15 --- /dev/null +++ b/docs/api/statuses_and_languages/get_active_and_archived_languages.md @@ -0,0 +1,378 @@ +## Active and Archived Languages [/languages/all] +### Get Active and Archived Languages [GET] +Get active and archived languages. + ++ Response 200 (application/json) + + Body + [ + { + "id": 45, + "name": "Assembly (NASM 2.14.02)", + "is_archived": false + }, + { + "id": 2, + "name": "Bash (4.0)", + "is_archived": true + }, + { + "id": 1, + "name": "Bash (4.4)", + "is_archived": true + }, + { + "id": 46, + "name": "Bash (5.0.0)", + "is_archived": false + }, + { + "id": 3, + "name": "Basic (fbc 1.05.0)", + "is_archived": true + }, + { + "id": 47, + "name": "Basic (FBC 1.07.1)", + "is_archived": false + }, + { + "id": 15, + "name": "C++ (g++ 4.8.5)", + "is_archived": true + }, + { + "id": 14, + "name": "C++ (g++ 4.9.4)", + "is_archived": true + }, + { + "id": 13, + "name": "C++ (g++ 5.4.0)", + "is_archived": true + }, + { + "id": 12, + "name": "C++ (g++ 6.3.0)", + "is_archived": true + }, + { + "id": 11, + "name": "C++ (g++ 6.4.0)", + "is_archived": true + }, + { + "id": 10, + "name": "C++ (g++ 7.2.0)", + "is_archived": true + }, + { + "id": 9, + "name": "C (gcc 4.8.5)", + "is_archived": true + }, + { + "id": 8, + "name": "C (gcc 4.9.4)", + "is_archived": true + }, + { + "id": 7, + "name": "C (gcc 5.4.0)", + "is_archived": true + }, + { + "id": 6, + "name": "C (gcc 6.3.0)", + "is_archived": true + }, + { + "id": 5, + "name": "C (gcc 6.4.0)", + "is_archived": true + }, + { + "id": 4, + "name": "C (gcc 7.2.0)", + "is_archived": true + }, + { + "id": 48, + "name": "C (GCC 7.4.0)", + "is_archived": false + }, + { + "id": 52, + "name": "C++ (GCC 7.4.0)", + "is_archived": false + }, + { + "id": 49, + "name": "C (GCC 8.3.0)", + "is_archived": false + }, + { + "id": 53, + "name": "C++ (GCC 8.3.0)", + "is_archived": false + }, + { + "id": 50, + "name": "C (GCC 9.2.0)", + "is_archived": false + }, + { + "id": 54, + "name": "C++ (GCC 9.2.0)", + "is_archived": false + }, + { + "id": 18, + "name": "Clojure (1.8.0)", + "is_archived": true + }, + { + "id": 17, + "name": "C# (mono 5.2.0.224)", + "is_archived": true + }, + { + "id": 16, + "name": "C# (mono 5.4.0.167)", + "is_archived": true + }, + { + "id": 51, + "name": "C# (Mono 6.6.0.161)", + "is_archived": false + }, + { + "id": 55, + "name": "Common Lisp (SBCL 2.0.0)", + "is_archived": false + }, + { + "id": 19, + "name": "Crystal (0.23.1)", + "is_archived": true + }, + { + "id": 56, + "name": "D (DMD 2.089.1)", + "is_archived": false + }, + { + "id": 20, + "name": "Elixir (1.5.1)", + "is_archived": true + }, + { + "id": 57, + "name": "Elixir (1.9.4)", + "is_archived": false + }, + { + "id": 21, + "name": "Erlang (OTP 20.0)", + "is_archived": true + }, + { + "id": 58, + "name": "Erlang (OTP 22.2)", + "is_archived": false + }, + { + "id": 44, + "name": "Executable", + "is_archived": false + }, + { + "id": 59, + "name": "Fortran (GFortran 9.2.0)", + "is_archived": false + }, + { + "id": 60, + "name": "Go (1.13.5)", + "is_archived": false + }, + { + "id": 22, + "name": "Go (1.9)", + "is_archived": true + }, + { + "id": 24, + "name": "Haskell (ghc 8.0.2)", + "is_archived": true + }, + { + "id": 23, + "name": "Haskell (ghc 8.2.1)", + "is_archived": true + }, + { + "id": 61, + "name": "Haskell (GHC 8.8.1)", + "is_archived": false + }, + { + "id": 25, + "name": "Insect (5.0.0)", + "is_archived": true + }, + { + "id": 62, + "name": "Java (OpenJDK 13.0.1)", + "is_archived": false + }, + { + "id": 28, + "name": "Java (OpenJDK 7)", + "is_archived": true + }, + { + "id": 27, + "name": "Java (OpenJDK 8)", + "is_archived": true + }, + { + "id": 26, + "name": "Java (OpenJDK 9 with Eclipse OpenJ9)", + "is_archived": true + }, + { + "id": 63, + "name": "JavaScript (Node.js 12.14.0)", + "is_archived": false + }, + { + "id": 30, + "name": "JavaScript (nodejs 7.10.1)", + "is_archived": true + }, + { + "id": 29, + "name": "JavaScript (nodejs 8.5.0)", + "is_archived": true + }, + { + "id": 64, + "name": "Lua (5.3.5)", + "is_archived": false + }, + { + "id": 31, + "name": "OCaml (4.05.0)", + "is_archived": true + }, + { + "id": 65, + "name": "OCaml (4.09.0)", + "is_archived": false + }, + { + "id": 32, + "name": "Octave (4.2.0)", + "is_archived": true + }, + { + "id": 66, + "name": "Octave (5.1.0)", + "is_archived": false + }, + { + "id": 33, + "name": "Pascal (fpc 3.0.0)", + "is_archived": true + }, + { + "id": 67, + "name": "Pascal (FPC 3.0.4)", + "is_archived": false + }, + { + "id": 68, + "name": "PHP (7.4.1)", + "is_archived": false + }, + { + "id": 43, + "name": "Plain Text", + "is_archived": false + }, + { + "id": 69, + "name": "Prolog (GNU Prolog 1.4.5)", + "is_archived": false + }, + { + "id": 37, + "name": "Python (2.6.9)", + "is_archived": true + }, + { + "id": 70, + "name": "Python (2.7.17)", + "is_archived": false + }, + { + "id": 36, + "name": "Python (2.7.9)", + "is_archived": true + }, + { + "id": 35, + "name": "Python (3.5.3)", + "is_archived": true + }, + { + "id": 34, + "name": "Python (3.6.0)", + "is_archived": true + }, + { + "id": 71, + "name": "Python (3.8.1)", + "is_archived": false + }, + { + "id": 41, + "name": "Ruby (2.1.9)", + "is_archived": true + }, + { + "id": 40, + "name": "Ruby (2.2.6)", + "is_archived": true + }, + { + "id": 39, + "name": "Ruby (2.3.3)", + "is_archived": true + }, + { + "id": 38, + "name": "Ruby (2.4.0)", + "is_archived": true + }, + { + "id": 72, + "name": "Ruby (2.7.0)", + "is_archived": false + }, + { + "id": 42, + "name": "Rust (1.20.0)", + "is_archived": true + }, + { + "id": 73, + "name": "Rust (1.40.0)", + "is_archived": false + }, + { + "id": 74, + "name": "TypeScript (3.7.4)", + "is_archived": false + } + ] \ No newline at end of file diff --git a/docs/api/statuses_and_languages/get_languages.md b/docs/api/statuses_and_languages/get_languages.md new file mode 100644 index 0000000000000000000000000000000000000000..99ab84fcc8b00b35c126f8291e0f119692d6d467 --- /dev/null +++ b/docs/api/statuses_and_languages/get_languages.md @@ -0,0 +1,134 @@ +### Get Languages [GET] +Get active languages. + ++ Response 200 (application/json) +[ + { + "id": 45, + "name": "Assembly (NASM 2.14.02)" + }, + { + "id": 46, + "name": "Bash (5.0.0)" + }, + { + "id": 47, + "name": "Basic (FBC 1.07.1)" + }, + { + "id": 48, + "name": "C (GCC 7.4.0)" + }, + { + "id": 52, + "name": "C++ (GCC 7.4.0)" + }, + { + "id": 49, + "name": "C (GCC 8.3.0)" + }, + { + "id": 53, + "name": "C++ (GCC 8.3.0)" + }, + { + "id": 50, + "name": "C (GCC 9.2.0)" + }, + { + "id": 54, + "name": "C++ (GCC 9.2.0)" + }, + { + "id": 51, + "name": "C# (Mono 6.6.0.161)" + }, + { + "id": 55, + "name": "Common Lisp (SBCL 2.0.0)" + }, + { + "id": 56, + "name": "D (DMD 2.089.1)" + }, + { + "id": 57, + "name": "Elixir (1.9.4)" + }, + { + "id": 58, + "name": "Erlang (OTP 22.2)" + }, + { + "id": 44, + "name": "Executable" + }, + { + "id": 59, + "name": "Fortran (GFortran 9.2.0)" + }, + { + "id": 60, + "name": "Go (1.13.5)" + }, + { + "id": 61, + "name": "Haskell (GHC 8.8.1)" + }, + { + "id": 62, + "name": "Java (OpenJDK 13.0.1)" + }, + { + "id": 63, + "name": "JavaScript (Node.js 12.14.0)" + }, + { + "id": 64, + "name": "Lua (5.3.5)" + }, + { + "id": 65, + "name": "OCaml (4.09.0)" + }, + { + "id": 66, + "name": "Octave (5.1.0)" + }, + { + "id": 67, + "name": "Pascal (FPC 3.0.4)" + }, + { + "id": 68, + "name": "PHP (7.4.1)" + }, + { + "id": 43, + "name": "Plain Text" + }, + { + "id": 69, + "name": "Prolog (GNU Prolog 1.4.5)" + }, + { + "id": 70, + "name": "Python (2.7.17)" + }, + { + "id": 71, + "name": "Python (3.8.1)" + }, + { + "id": 72, + "name": "Ruby (2.7.0)" + }, + { + "id": 73, + "name": "Rust (1.40.0)" + }, + { + "id": 74, + "name": "TypeScript (3.7.4)" + } +] \ No newline at end of file diff --git a/docs/api/statuses_and_languages/get_statuses.md b/docs/api/statuses_and_languages/get_statuses.md new file mode 100644 index 0000000000000000000000000000000000000000..aac1bbaaa9865a60eff1f94c6530359e9298fd45 --- /dev/null +++ b/docs/api/statuses_and_languages/get_statuses.md @@ -0,0 +1,61 @@ +## Status [/statuses] +### Get Statuses [GET] ++ Response 200 (application/json) + [ + { + "id": 1, + "description": "In Queue" + }, + { + "id": 2, + "description": "Processing" + }, + { + "id": 3, + "description": "Accepted" + }, + { + "id": 4, + "description": "Wrong Answer" + }, + { + "id": 5, + "description": "Time Limit Exceeded" + }, + { + "id": 6, + "description": "Compilation Error" + }, + { + "id": 7, + "description": "Runtime Error (SIGSEGV)" + }, + { + "id": 8, + "description": "Runtime Error (SIGXFSZ)" + }, + { + "id": 9, + "description": "Runtime Error (SIGFPE)" + }, + { + "id": 10, + "description": "Runtime Error (SIGABRT)" + }, + { + "id": 11, + "description": "Runtime Error (NZEC)" + }, + { + "id": 12, + "description": "Runtime Error (Other)" + }, + { + "id": 13, + "description": "Internal Error" + }, + { + "id": 14, + "description": "Exec Format Error" + } + ] diff --git a/docs/api/statuses_and_languages/languages.md b/docs/api/statuses_and_languages/languages.md new file mode 100644 index 0000000000000000000000000000000000000000..2731c0de94816d235808b394aac3a8e78f909e46 --- /dev/null +++ b/docs/api/statuses_and_languages/languages.md @@ -0,0 +1,4 @@ +## Language [/languages/{id}] + + + \ No newline at end of file diff --git a/docs/api/statuses_and_languages/statuses_and_languages.md b/docs/api/statuses_and_languages/statuses_and_languages.md new file mode 100644 index 0000000000000000000000000000000000000000..6388caae9f68daa784cec932dc8691acc72e3bf1 --- /dev/null +++ b/docs/api/statuses_and_languages/statuses_and_languages.md @@ -0,0 +1,3 @@ +# Group Statuses and Languages + + \ No newline at end of file diff --git a/docs/api/style.html b/docs/api/style.html new file mode 100644 index 0000000000000000000000000000000000000000..42c29e645aa776ed60be9da8c89d283ad6e7a388 --- /dev/null +++ b/docs/api/style.html @@ -0,0 +1,24 @@ + + + diff --git a/docs/api/submissions/create_a_submission.md b/docs/api/submissions/create_a_submission.md new file mode 100644 index 0000000000000000000000000000000000000000..010c8966bffbaebbba17d3053739c1ba0a636d87 --- /dev/null +++ b/docs/api/submissions/create_a_submission.md @@ -0,0 +1,159 @@ +### Create a Submission [POST] +Creates new submission. Created submission waits in queue to be processed. On successful +creation, you are returned submission token which can be used to [check submission status](#submissions-submission-get). + +If submission's `source_code`, `stdin` or `expected_output` contains non printable characters, or +characters which cannot be sent with JSON, then set `base64_encoded` parameter to `true` and +send these attributes Base64 encoded. Your responsibility is to encode each of mentioned attributes +(`source_code`, `stdin` and `expected_output`) even if just one of them contains non printable +characters. By default, this parameter is set to `false` and Judge0 assumes you are sending plain text data. + +By default you are returned submission token on successful submission creation. With this token you can [check submission status](#submission-submission-get). +Instead of checking submission status by making another request, you can set the `wait` query parameter to `true` which will enable you to get submission status immediately as part of response to the request you made. +Please note that this feature may or may not be enabled on all Judge0 hosts. So before using this feature please check [configuration](#system-and-configuration-configuration-info-get) of Judge0 you are using. On an [official Judge0](https://api.judge0.com) this feature **is not** enabled. + +::: note +

Note

+* We **do not** recommend the use of `wait=true` feature because it does not scale well. +::: + ++ Parameters + + base64_encoded = `false` (optional, boolean, `false`) ... Set to `true` if you want to send Base64 encoded data to Judge0. + + wait = `false` (optional, boolean, `false`) ... Set to `true` to immediately get submission result. + ++ Request (application/json) + { + "source_code": "#include \n\nint main(void) {\n char name[10];\n scanf(\"%s\", name);\n printf(\"hello, %s\\n\", name);\n return 0;\n}", + "language_id": 4, + "stdin": "world" + } + ++ Response 201 (application/json) + { + "token": "d85cd024-1548-4165-96c7-7bc88673f194" + } + + ++ Request (application/json) + { + "source_code": "#include \n\nint main(void) {\n char name[10];\n scanf(\"%s\", name);\n printf(\"hello, %s\\n\", name);\n return 0;\n}" + } + ++ Response 422 (application/json) + { + "language_id": [ + "can't be blank" + ] + } + + ++ Request (application/json) + { + "source_code": "#include \n\nint main(void) {\n char name[10];\n scanf(\"%s\", name);\n printf(\"hello, %s\\n\", name);\n return 0;\n}", + "language_id": 150000, + "stdin": "world", + "expected_output": "hello, world" + } + ++ Response 422 (application/json) + { + "language_id": [ + "language with id 150000 doesn't exist" + ] + } + + ++ Request (application/json) + { + "source_code": "#include \n\nint main(void) {\n char name[10];\n scanf(\"%s\", name);\n printf(\"hello, %s\\n\", name);\n return 0;\n}", + "language_id": 4, + "number_of_runs": 1, + "stdin": "Judge0", + "expected_output": "hello, Judge0", + "cpu_time_limit": 1, + "cpu_extra_time": 0.5, + "wall_time_limit": 100000, + "memory_limit": 128000, + "stack_limit": 128000, + "enable_per_process_and_thread_time_limit": false, + "enable_per_process_and_thread_memory_limit": false, + "max_file_size": 1024 + } + ++ Response 422 (application/json) + { + "wall_time_limit": [ + "must be less than or equal to 150" + ] + } + + ++ Request (appliction/json) + Sending Base64 encoded `source_code` and `stdin`. Note that in this request `base64_encoded` query parameter **must** be + set to `true`. + + Body + { + "source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBuYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxvLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=", + "language_id": 4, + "input": "SnVkZ2Uw" + } + ++ Response 201 (application/json) + { + "token": "f3fe0215-72f3-4fe6-97f5-353df6682db4" + } + ++ Request (application/json) + Creating a submission with `wait=true` that results with one or more attributes that cannot be serialized to JSON without Base64 encoding. + + Body + { + "language_id": 70, + "source_code": "print(\"\\xFE\")" + } + ++ Response 201 (application/json) + { + "token": "fcd0de6d-ee52-4a9d-8a00-6e0d98d394cf", + "error": "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter" + } + ++ Request (application/json) + Waiting for submission to finish. Note that in this request `wait` query parameter **must** be set to `true`. + + Body + { + "source_code": "#include \n\nint main(void) {\n char name[10];\n scanf(\"%s\", name);\n printf(\"hello, %s\\n\", name);\n return 0;\n}", + "language_id": "4", + "stdin": "Judge0", + "expected_output": "hello, Judge0" + } + ++ Response 201 (application/json) + { + "stdout": "hello, Judge0\n", + "time": "0.001", + "memory": 380, + "stderr": null, + "token": "eb0dd001-66db-47f4-8a69-b736c9bc23f6", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + } + ++ Response 400 (application/json) + If wait is not allowed. + + Body + { + "error": "wait not allowed" + } + ++ Response 503 (application/json) + If submission queue is full. + + Body + { + "error": "queue is full" + } + + diff --git a/docs/api/submissions/create_a_submission_batch.md b/docs/api/submissions/create_a_submission_batch.md new file mode 100644 index 0000000000000000000000000000000000000000..663e53daddb16e9cd319c4a2302f6911db0f1390 --- /dev/null +++ b/docs/api/submissions/create_a_submission_batch.md @@ -0,0 +1,73 @@ +### Create a Submission Batch [POST] +Create multiple submissions at once. + ++ Parameters + + base64_encoded = `false` (optional, boolean, `false`) ... Set to `true` if you are sending Base64 encoded data. + ++ Request (application/json) + { + "submissions": + [ + { + "language_id": 46, + "source_code": "echo hello from Bash" + }, + { + "language_id": 71, + "source_code": "print(\"hello from Python\")" + }, + { + "language_id": 72, + "source_code": "puts(\"hello from Ruby\")" + } + ] + } + ++ Response 201 (application/json) + [ + { + "token": "db54881d-bcf5-4c7b-a2e3-d33fe7e25de7" + }, + { + "token": "ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1" + }, + { + "token": "1b35ec3b-5776-48ef-b646-d5522bdeb2cc" + } + ] + ++ Request (application/json) + { + "submissions": + [ + { + "language_id": 46, + "source_code": "echo hello from Bash" + }, + { + "language_id": 123456789, + "source_code": "print(\"hello from Python\")" + }, + { + "language_id": 72, + "source_code": "" + } + ] + } + ++ Response 201 (application/json) + [ + { + "token": "c2dd8881-644b-462d-b1f9-73dd3bb0118a" + }, + { + "language_id": [ + "language with id 123456789 doesn't exist" + ] + }, + { + "source_code": [ + "can't be blank" + ] + } + ] \ No newline at end of file diff --git a/docs/api/submissions/delete_a_submission.md b/docs/api/submissions/delete_a_submission.md new file mode 100644 index 0000000000000000000000000000000000000000..3fb3bdca4149485021c590edce1b16aff60face7 --- /dev/null +++ b/docs/api/submissions/delete_a_submission.md @@ -0,0 +1,39 @@ +### Delete a Submission [DELETE] +Delete specific submission. + +You need to be authorized to issue this request. Although you are +authorized you might not be able to delete submission because administrator of Judge0 instance +you are using disallowed submission deletion. So before using this feature please check [configuration](#system-and-configuration-configuration-info-get) of Judge0 you are using. + +For this request query parameter `base64_encoded` is implicitly set to `true` and cannot be changed. +This guarantees you will successfully get requested submission attributes after deletion. + ++ Parameters + + token (required, string, `d85cd024-1548-4165-96c7-7bc88673f194`) ... Token of submission. You got this token when you created submission. + + fields = `stdout,time,memory,stderr,token,compile_output,message,status` (optional, string, `stdout,stderr,status_id,language_id`) ... Return only the desired attributes. + ++ Response 200 (applcation/json) + + Body + { + "stdout": "aGVsbG8sIHdvcmxkCg==\n", + "time": "0.045", + "memory": 8556, + "stderr": null, + "token": "e80153f5-e7d8-4cd2-9e10-6c0ddbf9e3bf", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + } + ++ Response 400 (application/json) +If submission status is `1` or `2`. + + Body + { + "error": "submission cannot be deleted because its status is 1 (In Queue)" + } + + + \ No newline at end of file diff --git a/docs/api/submissions/get_a_submission.md b/docs/api/submissions/get_a_submission.md new file mode 100644 index 0000000000000000000000000000000000000000..809edfab224191a49b29f878ab6adaf78317ef7f --- /dev/null +++ b/docs/api/submissions/get_a_submission.md @@ -0,0 +1,61 @@ +### Get a Submission [GET] +Returns details about submission. + +Just like in [create submission](/#submission-submission-post) you can receive Base64 encoded data for every text type attribute (check the [table](#submission-submission) to see which attributes are text type). By default, this parameter is set to `false` and Judge0 will send you raw data. + +By default Judge0 is sending 8 attributes for submission. By sending `fields` query parameter you can specify exactly which attributes you want from Judge0. Special value `*` will return all available attributes. + ++ Parameters + + token (required, string, `d85cd024-1548-4165-96c7-7bc88673f194`) ... Token of submission. You got this token when you created submission. + + base64_encoded (optional, boolean, `false`) ... Set to `true` if you want to receive Base64 encoded data from Judge0. You should set this to `true` if you expect the program's stdout to contain non-printable characters or if you expect the compiler to output non-printable characters during a compile error (GCC does this, for instance). + + fields = `stdout,time,memory,stderr,token,compile_output,message,status` (optional, string, `stdout,stderr,status_id,language_id`) ... Return only the desired attributes. + ++ Response 200 (applicatiion/json) + { + "stdout": "hello, world\n", + "status_id": 5, + "language_id": 4, + "stderr": null + } + ++ Response 200 (application/json) + This is the default response. Leave `fields` parameter empty if you want to get default response. + + Body + { + "stdout": "hello, Judge0\n", + "time": "0.001", + "memory": 376, + "stderr": null, + "token": "8531f293-1585-4d36-a34c-73726792e6c9", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + } + ++ Response 200 (application/json) + Receiving Base64 encoded data for text type attributes. Note that in this request `base64_encoded` query parameter **must** be set to `true`. + + Body + { + "stdout": "aGVsbG8sIEp1ZGdlMAo=\n", + "time": "0.002", + "memory": 376, + "stderr": null, + "token": "4e00f214-b8cb-4fcb-977b-429113c81ece", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + } + ++ Response 400 (application/json) + + Body + { + "error": "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter" + } + + diff --git a/docs/api/submissions/get_a_submission_batch.md b/docs/api/submissions/get_a_submission_batch.md new file mode 100644 index 0000000000000000000000000000000000000000..5b549edd5def08467d0488fa551b09cc427deb7a --- /dev/null +++ b/docs/api/submissions/get_a_submission_batch.md @@ -0,0 +1,34 @@ +### Get a Submission Batch [GET] +Get multiple submissions at once. + ++ Parameters + + tokens (required, string, `db54881d-bcf5-4c7b-a2e3-d33fe7e25de7,ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1,1b35ec3b-5776-48ef-b646-d5522bdeb2cc`) ... Submission tokens separeted with `,`. + + base64_encoded = `false` (optional, boolean, `false`) ... Set to `true` if you want to receive Base64 encoded data. + + fields = `stdout,time,memory,stderr,token,compile_output,message,status` (optional, string, `token,stdout,stderr,status_id,language_id`) ... Return only the desired attributes. + ++ Response 200 (application/json) + { + "submissions": [ + { + "language_id": 46, + "stdout": "hello from Bash\n", + "status_id": 3, + "stderr": null, + "token": "db54881d-bcf5-4c7b-a2e3-d33fe7e25de7" + }, + { + "language_id": 71, + "stdout": "hello from Python\n", + "status_id": 3, + "stderr": null, + "token": "ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1" + }, + { + "language_id": 72, + "stdout": "hello from Ruby\n", + "status_id": 3, + "stderr": null, + "token": "1b35ec3b-5776-48ef-b646-d5522bdeb2cc" + } + ] + } \ No newline at end of file diff --git a/docs/api/submissions/get_submissions.md b/docs/api/submissions/get_submissions.md new file mode 100644 index 0000000000000000000000000000000000000000..19e39bf608922a29464024e0bfe75bcfcba35604 --- /dev/null +++ b/docs/api/submissions/get_submissions.md @@ -0,0 +1,105 @@ +### Get Submissions [GET] ++ Parameters + + base64_encoded = `false` (optional, boolean, `false`) ... Set to `true` if you want to receive Base64 encoded data from Judge0. + + page = `1` (optional, integer, `4`) ... Pagination page number. + + per_page = `20` (optional, integer, `2`) ... Number of submissions to return per page. + + fields = `stdout,time,memory,stderr,token,compile_output,message,status` (optional, string, `status,language,time`) ... Return only the desired attributes. + ++ Response 200 (application/json) + { + "submissions": [ + { + "time": "0.001", + "status": { + "id": 3, + "description": "Accepted" + }, + "language": { + "id": 4, + "name": "C (gcc 7.2.0)" + } + }, + { + "time": "0.001", + "status": { + "id": 3, + "description": "Accepted" + }, + "language": { + "id": 4, + "name": "C (gcc 7.2.0)" + } + } + ], + "meta": { + "current_page": 4, + "next_page": 5, + "prev_page": 3, + "total_pages": 31, + "total_count": 62 + } + } + ++ Response 200 (application/json) + When `base64_encoded` is set to `true`. + + Body + { + "submissions": [ + { + "stdout": "aGVsbG8sIEp1ZGdlMAo=\n", + "time": "0.001", + "memory": 376, + "stderr": null, + "token": "a1133bc6-a0f6-46bf-a2d8-6157418c6fe2", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + }, + { + "stdout": "aGVsbG8sIEp1ZGdlMAo=\n", + "time": "0.001", + "memory": 380, + "stderr": null, + "token": "eb0dd001-66db-47f4-8a69-b736c9bc23f6", + "compile_output": null, + "message": null, + "status": { + "id": 3, + "description": "Accepted" + } + } + ], + "meta": { + "current_page": 4, + "next_page": 5, + "prev_page": 3, + "total_pages": 31, + "total_count": 62 + } + } + ++ Response 400 (application/json) + When `page` parameter is invalid. + + Body + { + "error": "invalid page: -4" + } + ++ Response 400 (application/json) + When `per_page` parameter is invalid. + + Body + { + "error": "invalid per_page: -2" + } + ++ Response 400 (application/json) + + Body + { + "error": "some attributes for one or more submissions cannot be converted to UTF-8, use base64_encoded=true query parameter" + } + + + diff --git a/docs/api/submissions/submissions.md b/docs/api/submissions/submissions.md new file mode 100644 index 0000000000000000000000000000000000000000..997943ef6398f23a111e8c3cf10752021d4ce925 --- /dev/null +++ b/docs/api/submissions/submissions.md @@ -0,0 +1,76 @@ +## Group Submissions +## Submission [/submissions/{token}{?base64_encoded,wait,fields,page,per_page}] +Submission is used for running arbitrary source code in one of +the [available programming languages](#statuses-and-languages-language-get) with specified runtime constraints. + +Submission has 33 attributes. Attributes 1-20 are used for creating a new submissions, whereas +attributes 21-33 give detailed information of submission after it's execution. + +Attributes 7-18 are called [*configuration variables*](#system-and-configuration-configuration-info) +and can be used to configure submission runtime constraints such as time and memory limits. + +|# |Name |Type |Unit |Description |Default Value | +|:---:|:----|:----:|:----:|:-----------|:-------------| +|1|**`source_code`**|text||Program's source code.|No default. This attribute is **required** for [single-file programs](#header-single-file-programs-and-multi-file-programs).| +|2|**`language_id`**|integer||[Language](#statuses-and-languages-language) ID.|No default. This attribute is **required**.| +|3|`compiler_options`|string (max. 512 chars)||Options for the compiler (i.e. compiler flags).|`null`| +|4|`command_line_arguments`|string (max. 512 chars)||Command line arguments for the program.|`null`| +|5|`stdin`|text||Input for program.|`null`. Program won't receive anything to standard input.| +|6|`expected_output`|text||Expected output of program. Used when you want to compare with `stdout`.|`null`. Program's `stdout` won't be compared with `expected_output`.| +|7|`cpu_time_limit`|float|second|Default runtime limit for every program. Time in which the OS assigns the processor to different tasks is not counted.|Depends on [configuration](#system-and-configuration-configuration-info).| +|8|`cpu_extra_time`|float|second|When a time limit is exceeded, wait for extra time, before killing the program. This has the advantage that the real execution time is reported, even though it slightly exceeds the limit.|Depends on [configuration](#system-and-configuration-configuration-info).| +|9|`wall_time_limit`|float|second|Limit wall-clock time in seconds. Decimal numbers are allowed. This clock measures the time from the start of the program to its exit, so it does not stop when the program has lost the CPU or when it is waiting for an external event. We recommend to use `cpu_time_limit` as the main limit, but set `wall_time_limit` to a much higher value as a precaution against sleeping programs.|Depends on [configuration](#system-and-configuration-configuration-info).| +|10|`memory_limit`|float|kilobyte|Limit address space of the program.|Depends on [configuration](#system-and-configuration-configuration-info).| +|11|`stack_limit`|integer|kilobyte|Limit process stack.|Depends on [configuration](#system-and-configuration-configuration-info).| +|12|`max_processes_and_or_threads`|integer||Maximum number of processes and/or threads program can create.|Depends on [configuration](#system-and-configuration-configuration-info).| +|13|`enable_per_process_and_thread_time_limit`|boolean||If `true` then `cpu_time_limit` will be used as per process and thread.|Depends on [configuration](#system-and-configuration-configuration-info).| +|14|`enable_per_process_and_thread_memory_limit`|boolean||If `true` then `memory_limit` will be used as per process and thread.|Depends on [configuration](#system-and-configuration-configuration-info).| +|15|`max_file_size`|integer|kilobyte|Limit file size created or modified by the program.|Depends on [configuration](#system-and-configuration-configuration-info).| +|16|`redirect_stderr_to_stdout`|boolean||If `true` standard error will be redirected to standard output.|Depends on [configuration](#system-and-configuration-configuration-info).| +|17|`enable_network`|boolean||If `true` program will have network access.|Depends on [configuration](#system-and-configuration-configuration-info).| +|18|`number_of_runs`|integer||Run each program `number_of_runs` times and take average of `time` and `memory`.|Depends on [configuration](#system-and-configuration-configuration-info).| +|19|**`additional_files`**|Base64 Encoded String||Additional files that should be available alongside the source code. Value of this string should represent the content of a `.zip` that contains additional files. This attribute is **required** for [multi-file programs](#header-single-file-programs-and-multi-file-programs).|`null`| +|20|`callback_url`|string||URL on which Judge0 will issue `PUT` request with the submission in a request body after submission has been done.|`null`| +|21|`stdout`|text||Standard output of the program after execution.|| +|22|`stderr`|text||Standard error of the program after execution.|| +|23|`compile_output`|text||Compiler output after compilation.|| +|24|`message`|text||If submission status is `Internal Error` then this message comes from Judge0 itself, otherwise this is status message from [isolate](https://github.com/ioi/isolate).|| +|25|`exit_code`|integer||The program's exit code.|| +|26|`exit_signal`|integer||Signal code that the program recieved before exiting.|| +|27|`status`|object||Submission [status](#statuses-and-languages-status).|| +|28|`created_at`|datetime||Date and time when submission was created.|| +|29|`finished_at`|datetime||Date and time when submission was processed.|`null` if submission is still in queue or if submission is processing.| +|30|`token`|string||Unique submission token which can be used to [get a specific submission](#submissions-submission-get).|| +|31|`time`|float|second|Program's run time.|| +|32|`wall_time`|float|second|Program's wall time. Will be greater or equal to `time`.|| +|33|`memory`|float|kilobyte|Memory used by the program after execution.|| + +### Single-file programs and multi-file programs +Judge0 can run both single-file and multi-file programs in a sandboxed environment with specified resource limitations. +The usage of multi-file programs is slightly different from single-file programs and this section explains their differences and when they should be used. + +#### Single-file programs +This is the simplest way to run a program with Judge0. Pick a [language](#statuses-and-languages-language-get) with `language_id`, provide a `source_code` and Judge0 will use predefined compilation and execution scripts for specified language. Additionally you can set custom compile flags, provide command line arguments and send `additional_files` that will be available in the sandbox alongside your single-file program. + +With `additional_files` you can send, for example, Python modules which are imported by your main program that you provided in `source_code` attribute. For C or C++ programs with `additional_files` you can send header files which are included by your main program that you provided in `source_code` attribute. + +Even though you can send and use multiple Python modules or C and C++ header files, we call this *single-file programs* because for compiled languages only **one** source file is compiled with predefined compilation scripts. + +#### Multi-file programs +Multi-file programs are available since [v1.10.0](https://github.com/judge0/judge0/tree/v1.10.0) and they allow you specify your own compilation and execution scripts that Judge0 will use. + +To use multi-file program feature you need to choose a language called *Multi-file program* whoose ID is **89**. Moreover, you need to send all program files with `additional_files` attribute. With multi-file programs attribute `source_code` cannot be used, i.e. all files should be sent with `additional_files` attribute. + +As mentioned in the table above, `additional_files` attribute should be a content of a Base64 encoded `.zip` archive. This archive will be extracted in the sandbox before compilation and execution. + +For the Judge0 to know how to compile and execute your multi-file program you need to provide two special files that should be available in the root of the `.zip` archive that you are sending with `additional_files` attribute. These files should be named `compile` and `run`, and are expected to be Bash scripts that know how to compile and execute your multi-file program. If your multi-file program does not need compilation step, then you don't need to provide `compile` script. Take a look at [this example](https://github.com/judge0/examples/tree/master/cpp-and-cmake-01) to learn how to use this feature to compile and run multi-file C++ project that uses CMake. + + + + + + +## Submission Batch [/submissions/batch{?tokens,base64_encoded,fields}] + + + diff --git a/docs/api/system_and_configuration/configuration_info.md b/docs/api/system_and_configuration/configuration_info.md new file mode 100644 index 0000000000000000000000000000000000000000..2f5440e1a78ee14725a84baaa0e93b7f04972463 --- /dev/null +++ b/docs/api/system_and_configuration/configuration_info.md @@ -0,0 +1,90 @@ +## Configuration Info [/config_info] +## Configuration Info [GET] +Configuration information gives you detailed information about configuration of Judge0. +This configuration can be changed through [judge0.conf](https://github.com/judge0/judge0/blob/master/judge0.conf) +file by admin who hosts Judge0 instance. + +This configuration gives every admin a flexibility to configure Judge0 according to server abilities and needs. It also gives users +insight on some *default configuration values* which are used when their programs are run. + +Each of these *configuration variables* have *default values* which we consider as recommended in case you are not sure should you change them. + +We will refer to *default values* as values which Judge0 automatically assigns to each of these *configuration variables*, +if admin didn't set them. For example, default value of *configuration variable* `cpu_time_limit` is `2`. + +|# |Name|Type |Unit |Description|Default Value| +|:---:|:---|:---:|:---:|:----------|:------------| +|1|`enable_wait_result`|boolean||If enabled user can request to synchronously wait for submission result on submission create.|true| +|2|`enable_compiler_options`|boolean||If enabled user can set `compiler_options`.|true| +|3|`allowed_languages_for_compile_options`|list of strings||Languages for which setting compiler options is allowed.|Empty, i.e. for all languages it is allowed to set compiler options.| +|4|`enable_command_line_arguments`|boolean||If enabled user can set `command_line_arguments`.|true| +|5|`enable_submission_delete`|boolean||If enabled authorized user can [delete a submission](#submissions-submission-delete).|false| +|6|`max_queue_size`|integer||Maximum number of submissions that can wait in queue.|100| +|7|`cpu_time_limit`|float|second|Default runtime limit for every program (in seconds). Decimal numbers are allowed. Time in which the OS assigns the processor to different tasks is not counted.|2| +|8|`cpu_extra_time`|float|second|When a time limit is exceeded, wait for extra time, before killing the program. This has the advantage that the real execution time is reported, even though it slightly exceeds the limit.|0.5| +|9|`wall_time_limit`|float|second|Limit wall-clock time in seconds. Decimal numbers are allowed. This clock measures the time from the start of the program to its exit, for an external event. We recommend to use `cpu_time_limit` as the main limit, but set `wall_time_limit` to a much higher value as a precaution against sleeping programs.|5| +|10|`memory_limit`|integer|kilobyte|Limit address space of the program in kilobytes.|128000| +|11|`stack_limit`|integer|kilobyte|Limit process stack in kilobytes.|64000| +|12|`max_processes_and_or_threads`|integer||Maximum number of processes and/or threads program can create.|60| +|13|`enable_per_process_and_thread_time_limit`|boolean||If `true` then `cpu_time_limit` will be used as per process and thread.|false| +|14|`enable_per_process_and_thread_memory_limit`|boolean||If `true` then `memory_limit` will be used as per process and thread.|true| +|15|`max_file_size`|integer|kilobyte|Limit size of files created (or modified) by the program.|1024| +|16|`allow_enable_network`|boolean||If enabled user can set `enable_network`.|true| +|17|`enable_network`|boolean||If enabled program will have network access.|true| +|18|`number_of_runs`|integer||Run each program this many times and take average of time and memory.|1| + +*Default configuration value* for each variable is given to you as response of this API call. For example, *default configuration value* +for variable `cpu_extra_time` might be `2`, and if admin didn't set this, then it is `0.5` (*default value*). +This means that admin set `cpu_extra_time` *configuration variable* to value `2` and we say it is now *default configuration value* for this +variable `cpu_extra_time`. + +Every [submission](#submissions-submission) can change each of the configuration variables according to its needs. For example, +user might create submission which has `cpu_time_limit` of `5` seconds. For security reasons we need to limit values of each of these +configuration variables. For example, we don't want user to create a submission which has `cpu_time_limit` of `100000` seconds. + +For this security reason we are introducing *limit configuration variables* for each *configuration variable*. + +|# |Name|Type |Unit |Description|Default Value| +|:---:|:---|:---:|:---:|:----------|:------------| +|1|`max_cpu_time_limit`|float|second|Maximum custom `cpu_time_limit`|15| +|2|`max_cpu_extra_time`|float|second|Maximum custom `cpu_extra_time`|2| +|3|`max_wall_time_limit`|float|second|Maximum custom `wall_time_limit`|20| +|4|`max_memory_limit`|integer|kilobyte|Maximum custom `memory_limit`|256000| +|5|`max_stack_limit`|integer|kilobyte|Maximum custom `stack_limit`|128000| +|6|`max_max_processes_and_or_threads`|integer||Maximum custom `max_processes_and_or_threads`|120| +|7|`allow_enable_per_process_and_thread_time_limit`|boolean||If `false` user won't be able to set `enable_per_process_and_thread_time_limit` to `true`|true| +|8|`allow_enable_per_process_and_thread_memory_limit`|boolean||If `false` user won't be able to set `enable_per_process_and_thread_memory_limit` to `true`|true| +|9|`max_max_file_size`|integer|kilobyte|Maximux custom `max_file_size`|4096| +|10|`max_number_of_runs`|integer||Maximum custom `number_of_runs`|20| + +For example, `max_cpu_time_limit` with value `20` means that user cannot create new submission which has `cpu_time_limit` greater than `20`. + ++ Response 200 (application/json) + { + "enable_wait_result": true, + "enable_compiler_options": true, + "allowed_languages_for_compile_options": [], + "enable_command_line_arguments": true, + "enable_submission_delete": false, + "max_queue_size": 100, + "cpu_time_limit": 2, + "max_cpu_time_limit": 15, + "cpu_extra_time": 0.5, + "max_cpu_extra_time": 2, + "wall_time_limit": 5, + "max_wall_time_limit": 20, + "memory_limit": 128000, + "max_memory_limit": 256000, + "stack_limit": 64000, + "max_stack_limit": 128000, + "max_processes_and_or_threads": 60, + "max_max_processes_and_or_threads": 120, + "enable_per_process_and_thread_time_limit": false, + "allow_enable_per_process_and_thread_time_limit": true, + "enable_per_process_and_thread_memory_limit": true, + "allow_enable_per_process_and_thread_memory_limit": true, + "max_file_size": 1024, + "max_max_file_size": 4096, + "number_of_runs": 1, + "max_number_of_runs": 20 + } \ No newline at end of file diff --git a/docs/api/system_and_configuration/system_and_configuration.md b/docs/api/system_and_configuration/system_and_configuration.md new file mode 100644 index 0000000000000000000000000000000000000000..225979ff8169c71d78807f88c6c1d71e500846fb --- /dev/null +++ b/docs/api/system_and_configuration/system_and_configuration.md @@ -0,0 +1,3 @@ +# Group System and Configuration + + \ No newline at end of file diff --git a/docs/api/system_and_configuration/system_info.md b/docs/api/system_and_configuration/system_info.md new file mode 100644 index 0000000000000000000000000000000000000000..d356df60b981ea78cdd05ede26fd1f20a0f674b2 --- /dev/null +++ b/docs/api/system_and_configuration/system_info.md @@ -0,0 +1,42 @@ +## System Info [/system_info] +### System Info [GET] +System information gives you detailed information about system on which Judge0 is running. + +This information is result of two commands on a host system: +- `lscpu` +- `free -h` + +Please note that Judge0 consists of two systems: **web** and **worker**. **Web** system is the one who +provides you the web API, and **Worker** is the one who processes your submissions. They can be placed on two or more +different hosts with different system configurations. Result of this API request is always from web system. +This means that this request might be irrelevant to you if you as user don't know if web and worker are +hosted on the same machine. To find that out, please contact admins who host Judge0 you are using. ++ Response 200 (application/json) + { + "Architecture": "x86_64", + "CPU op-mode(s)": "32-bit, 64-bit", + "Byte Order": "Little Endian", + "CPU(s)": "4", + "On-line CPU(s) list": "0-3", + "Thread(s) per core": "2", + "Core(s) per socket": "2", + "Socket(s)": "1", + "NUMA node(s)": "1", + "Vendor ID": "GenuineIntel", + "CPU family": "6", + "Model": "61", + "Model name": "Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz", + "Stepping": "4", + "CPU MHz": "2508.703", + "CPU max MHz": "2700.0000", + "CPU min MHz": "500.0000", + "BogoMIPS": "4392.12", + "Virtualization": "VT-x", + "L1d cache": "32K", + "L1i cache": "32K", + "L2 cache": "256K", + "L3 cache": "3072K", + "NUMA node0 CPU(s)": "0-3", + "Mem": "7.7G", + "Swap": "8.0G" + } \ No newline at end of file diff --git a/docs/maintainers/README.md b/docs/maintainers/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4c42f6b0d52cfb9ba0076d19786871012b5d71c9 --- /dev/null +++ b/docs/maintainers/README.md @@ -0,0 +1,2 @@ +# Documentation for Maintainers +Here you can find documentation for Judge0 maintainers. \ No newline at end of file diff --git a/docs/maintainers/RELEASE_NOTES_TEMPLATE.md b/docs/maintainers/RELEASE_NOTES_TEMPLATE.md new file mode 100644 index 0000000000000000000000000000000000000000..dc82e3a19071af304f1e30a6c2b1fe361b20f56e --- /dev/null +++ b/docs/maintainers/RELEASE_NOTES_TEMPLATE.md @@ -0,0 +1,61 @@ +# vX.Y.Z (YYYY-MM-DD) +## API Changes + +## New Features + +## Improvements + +## Security Improvements + +## Bug Fixes + +## Security Fixes + +## Other Changes + +## Deployment Procedure +Judge0 is collecting telemetry data to help understand how to improve the product and to better understand how Judge0 is used in various production environments. Read more about telemetry [here](https://github.com/judge0/judge0/blob/vX.Y.Z/TELEMETRY.md). + +Please note that Judge0 has only been tested on **Linux** and **macOS**, and might not work on Windows, thus we do not provide support for it. + +### With HTTP +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract the release archive: +``` +wget https://github.com/judge0/judge0/releases/download/vX.Y.Z/judge0-vX.Y.Z.zip +unzip judge0-vX.Y.Z.zip +``` + +3. Run all services and wait a few seconds until everything is initialized: +``` +cd judge0-vX.Y.Z +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +4. Your instance of Judge0 vX.Y.Z is now available at `http://:2358`. + +### With HTTPS (SSL/TLS) +1. Install [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose). +2. Download and extract the release archive: +``` +wget https://github.com/judge0/judge0/releases/download/vX.Y.Z/judge0-vX.Y.Z-https.zip +unzip judge0-vX.Y.Z-https.zip +``` + +3. Change directory to `judge0-vX.Y.Z-https`: +``` +cd judge0-vX.Y.Z-https +``` +4. Edit `docker-compose.yml` and change variables `VIRTUAL_HOST`, `LETSENCRYPT_HOST` and `LETSENCRYPT_EMAIL`. +5. Run all services and wait a few seconds until everything is initialized: +``` +docker-compose up -d db redis +sleep 10s +docker-compose up -d +sleep 5s +``` + +6. Your instance of Judge0 vX.Y.Z is now available at `https://`. diff --git a/judge0.conf b/judge0.conf new file mode 100644 index 0000000000000000000000000000000000000000..9110d77c181e69aaa8f5629841468333db6f0fdd --- /dev/null +++ b/judge0.conf @@ -0,0 +1,369 @@ +################################################################################ +# Judge0 Configuration File +################################################################################ +# Judge0 is a highly configurable which allows you to use it for many +# different use-cases. Please, before deploying Judge0 take a look at this +# configuration file that is divided in several logical sections that will help +# you understand what can you do with Judge0. +# +# This default configuration file is designed to work out of the box for you and +# you can start with it when deploying Judge0 on your server. +# +# If you have any questions please don't hasitate to send an email or open an +# issue on the GitHub page of the project. + + +################################################################################ +# Judge0 Server Configuration +################################################################################ +# Enable or disable Judge0 Telemetry. +# Read more about it here: https://github.com/judge0/judge0/blob/master/TELEMETRY.md +# Default: true +JUDGE0_TELEMETRY_ENABLE= + +# Automatically restart Judge0 server if it fails to start. +# Default: 10 +RESTART_MAX_TRIES= + +# Maintenance mode is a mode in which clients cannot +# create or delete submissions while maintenance is enabled. +# Default: false +MAINTENANCE_MODE= + +# Set custom maintenance message that will be returned to clients +# who try to create or delete submisions. +# Default: Judge0 is currently in maintenance. +MAINTENANCE_MESSAGE= + +# If enabled user can request to synchronically wait for +# submission result on submission create. +# Default: true, i.e. user can request to wait for the result +ENABLE_WAIT_RESULT= + +# If enabled user is allowed to set custom compiler options. +# Default: true +ENABLE_COMPILER_OPTIONS= + +# List language names, separated by space, for which setting compiler options is allowed. +# Note that ENABLE_COMPILER_OPTIONS has higher priority, so this option will be +# ignored if setting compiler options is disabled with ENABLE_COMPILER_OPTIONS. +# For example, ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS="C C++ Java" would only +# allow setting compiler options for languages C, C++ and Java. +# Default: empty - for every compiled language setting compiler options is allowed. +ALLOWED_LANGUAGES_FOR_COMPILER_OPTIONS= + +# If enabled user is allowed to set custom command line arguments. +# Default: true +ENABLE_COMMAND_LINE_ARGUMENTS= + +# If enabled authorized users can delete a submission. +# Default: false +ENABLE_SUBMISSION_DELETE= + +# If enabled user can GET and POST batched submissions. +# Default: true +ENABLE_BATCHED_SUBMISSIONS= + +# Maximum number of submissions that can be created or get in a batch. +# Default: 20 +MAX_SUBMISSION_BATCH_SIZE= + +# If enabled user can use callbacks. +# Default: true +ENABLE_CALLBACKS= + +# Maximum number of callback tries before giving up. +# Default: 3 +CALLBACKS_MAX_TRIES= + +# Timeout callback call after this many seconds. +# Default: 5 +CALLBACKS_TIMEOUT= + +# If enabled user can preset additional files in the sandbox. +# Default: true +ENABLE_ADDITIONAL_FILES= + +# Duration (in seconds) of submission cache. Decimal numbers are allowed. +# Set to 0 to turn of submission caching. Note that this does not apply to +# batched submissions. +# Default: 1 +SUBMISSION_CACHE_DURATION= + +# If true the documentation page will be used as a homepage, otherwise, the +# homepage will be empty. You can always access the documentation page via /docs. +# Default: false +USE_DOCS_AS_HOMEPAGE= + +# If true Judge0 behaves such that base64_encoded=true is assumed by default if +# not explicitly turned of with base64_encoded=false. +# Default: false +DISABLE_IMPLICIT_BASE64_ENCODING= + + +################################################################################ +# Judge0 Workers Configuration +################################################################################ +# Specify polling frequency in seconds. Decimal numbers are allowed. +# Default: 0.1 +INTERVAL= + +# Specify how many parallel workers to run. +# Default: 2*nproc (https://linux.die.net/man/1/nproc) +COUNT= + +# Specify maximum queue size. Represents maximum number of submissions that +# can wait in the queue at once. If request for new submission comes and the +# queue if full then submission will be rejected. +# Default: 100 +MAX_QUEUE_SIZE= + + +################################################################################ +# Judge0 Server Access Configuration +################################################################################ +# Allow only specified origins. +# If left blank, then all origins will be allowed (denoted with '*'). +# Example: +# ALLOW_ORIGIN="www.judge0.com judge0.com www.example.com blog.example.com" +ALLOW_ORIGIN= + +# Disallow only specified origins. +# If left blank, then no origin will be disallowed. +# Example: +# DISALLOW_ORIGIN="www.judge0.com judge0.com www.example.com blog.example.com" +DISALLOW_ORIGIN= + +# Allow only specified IP addresses. +# If left blank, then all IP addresses will be allowed. +# Example: +# ALLOW_IP="192.168.10.10 96.239.226.228 208.23.207.242" +ALLOW_IP= + +# Disallow only specified IP addresses. +# If left blank, then no IP addresses will be disallowed. +# Example: +# DISALLOW_IP="192.168.10.10 96.239.226.228 208.23.207.242" +DISALLOW_IP= + + +################################################################################ +# Judge0 Authentication Configuration +################################################################################ +# You can protect your API with (AUTHN_HEADER, AUTHN_TOKEN) pair. +# Each request then needs to have this pair either in headers or +# query parameters. For example let AUTHN_HEADER=X-Judge0-Token and +# AUTHN_TOKEN=mySecretToken. Then user should authenticate by sending this +# in headers or query parameters in each request, e.g.: +# https://ce.judge0.com/system_info?X-Judge0-Token=mySecretToken + +# Specify authentication header name. +# Default: X-Auth-Token +AUTHN_HEADER= + +# Specify valid authentication tokens. +# Default: empty - authentication is disabled +AUTHN_TOKEN= + + +################################################################################ +# Judge0 Authorization Configuration +################################################################################ +# Protected API calls can be issued with (AUTHZ_HEADER, AUTHZ_TOKEN) pair. +# To see exactly which API calls are protected with authorization tokens +# please read the docs at https://ce.judge0.com. +# API authorization ensures that only specified users call protected API calls. +# For example let AUTHZ_HEADER=X-Judge0-User and AUTHZ_TOKEN=mySecretToken. +# Then user should authorize be sending this in headers or query parameters in +# each request, e.g.: https://ce.judge0.com/system_info?X-Judge0-User=mySecretToken +# Note that if you enabled authentication, then user should also send valid +# authentication token. + +# Specify authorization header name. +# Default: X-Auth-User +AUTHZ_HEADER= + +# Specify valid authorization tokens. +# Default: empty - authorization is disabled, protected API calls cannot be issued +AUTHZ_TOKEN= + + +################################################################################ +# Redis Configuration +################################################################################ +# Specify Redis host. +# Default: localhost +REDIS_HOST=redis + +# Specify Redis port. +# Default: 6379 +REDIS_PORT= + +# Specify Redis password. Cannot be blank. +# Default: NO DEFAULT! MUST BE SET! +REDIS_PASSWORD= + +# Specify Resque namespace. +# Default: Resque's default namespace +# Example: +# RESQUE_NAMESPACE=dev:resque +RESQUE_NAMESPACE= + + +################################################################################ +# PostgreSQL Configuration +################################################################################ +# Specify Postgres host. +# Default: localhost +POSTGRES_HOST=db + +# Specify Postgres port. +# Default: 5432 +POSTGRES_PORT= + +# Name of the database to use. Used only in production. +# Default: postgres +POSTGRES_DB=judge0 + +# User who can access this database. Used only in production. +# Default: postgres +POSTGRES_USER=judge0 + +# Password of the user. Cannot be blank. Used only in production. +# Default: NO DEFAULT, YOU MUST SET YOUR PASSWORD +POSTGRES_PASSWORD= + + +################################################################################ +# Submission Configuration +################################################################################ +# Judge0 uses isolate as an sandboxing environment. +# Almost all of the options you see here can be mapped to one of the options +# that isolate provides. For more information about these options please +# check for the isolate documentation here: +# https://raw.githubusercontent.com/ioi/isolate/master/isolate.1.txt + +# Default runtime limit for every program (in seconds). Decimal numbers are allowed. +# Time in which the OS assigns the processor to different tasks is not counted. +# Default: 5 +CPU_TIME_LIMIT= + +# Maximum custom CPU_TIME_LIMIT. +# Default: 15 +MAX_CPU_TIME_LIMIT= + +# When a time limit is exceeded, wait for extra time (in seconds), before +# killing the program. This has the advantage that the real execution time +# is reported, even though it slightly exceeds the limit. +# Default: 1 +CPU_EXTRA_TIME= + +# Maximum custom CPU_EXTRA_TIME. +# Default: 5 +MAX_CPU_EXTRA_TIME= + +# Limit wall-clock time in seconds. Decimal numbers are allowed. +# This clock measures the time from the start of the program to its exit, +# so it does not stop when the program has lost the CPU or when it is waiting +# for an external event. We recommend to use CPU_TIME_LIMIT as the main limit, +# but set WALL_TIME_LIMIT to a much higher value as a precaution against +# sleeping programs. +# Default: 10 +WALL_TIME_LIMIT= + +# Maximum custom WALL_TIME_LIMIT. +# Default: 20 +MAX_WALL_TIME_LIMIT= + +# Limit address space of the program in kilobytes. +# Default: 128000 +MEMORY_LIMIT= + +# Maximum custom MEMORY_LIMIT. +# Default: 512000 +MAX_MEMORY_LIMIT= + +# Limit process stack in kilobytes. +# Default: 64000 +STACK_LIMIT= + +# Maximum custom STACK_LIMIT. +# Default: 128000 +MAX_STACK_LIMIT= + +# Maximum number of processes and/or threads program can create. +# Default: 60 +MAX_PROCESSES_AND_OR_THREADS= + +# Maximum custom MAX_PROCESSES_AND_OR_THREADS. +# Default: 120 +MAX_MAX_PROCESSES_AND_OR_THREADS= + +# If true then CPU_TIME_LIMIT will be used as per process and thread. +# Default: false, i.e. CPU_TIME_LIMIT is set as a total limit for all processes and threads. +ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT= + +# If false, user won't be able to set ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT. +# Default: true +ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT= + +# If true then MEMORY_LIMIT will be used as per process and thread. +# Default: false, i.e. MEMORY_LIMIT is set as a total limit for all processes and threads. +ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT= + +# If false, user won't be able to set ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT. +# Default: true +ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT= + +# Limit size of files created (or modified) by the program in kilobytes. +# Default: 1024 +MAX_FILE_SIZE= + +# Maximum custom MAX_FILE_SIZE. +# Default: 4096 +MAX_MAX_FILE_SIZE= + +# Run each program this many times and take average of time and memory. +# Default: 1 +NUMBER_OF_RUNS= + +# Maximum custom NUMBER_OF_RUNS. +# Default: 20 +MAX_NUMBER_OF_RUNS= + +# Redirect stderr to stdout. +# Default: false +REDIRECT_STDERR_TO_STDOUT= + +# Maximum total size (in kilobytes) of extracted files from additional files archive. +# Default: 10240, i.e. maximum of 10MB in total can be extracted. +MAX_EXTRACT_SIZE= + +# If false, user won't be able to set ENABLE_NETWORK. +# Default: true, i.e. allow user to permit or deny network calls from the submission. +ALLOW_ENABLE_NETWORK= + +# If true submission will by default be able to do network calls. +# Default: false, i.e. programs cannot do network calls. +ENABLE_NETWORK= + + +################################################################################ +# Rails Configuration +################################################################################ +# Specify Rails environment: production or development +# Default: production +RAILS_ENV= + +# Specify maximum number of concurrent Rails threads. +# Default: nproc (https://linux.die.net/man/1/nproc) +RAILS_MAX_THREADS= + +# Specify how many processes will be created for handing requests. Each process +# will additionally create RAILS_MAX_THREADS threads. +# Default: 2 +RAILS_SERVER_PROCESSES= + +# Secret key base for production, if not set it will be randomly generated +# Default: randomly generated +SECRET_KEY_BASE= diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 0000000000000000000000000000000000000000..0fb6cfacc595e35460020e0e872d8ef5ef6f95a0 --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,45 @@ +if Rails.env.development? + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'routes' => 'false', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'true', + 'exclude_fixtures' => 'true', + 'exclude_factories' => 'true', + 'exclude_serializers' => 'true', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,boolean', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil + ) + end + + Annotate.load_tasks +end diff --git a/lib/tasks/clear_cache.rake b/lib/tasks/clear_cache.rake new file mode 100644 index 0000000000000000000000000000000000000000..384827598bf5427951d8a170aba478ecfb865dab --- /dev/null +++ b/lib/tasks/clear_cache.rake @@ -0,0 +1,7 @@ +desc "Clear cache." + +namespace :judge0 do + task :clear_cache => :environment do + Rails.cache.clear + end +end \ No newline at end of file diff --git a/lib/tasks/run_submissions_in_queue.rake b/lib/tasks/run_submissions_in_queue.rake new file mode 100644 index 0000000000000000000000000000000000000000..d29d6cec269df9ccb014020252455bf9c73a3f25 --- /dev/null +++ b/lib/tasks/run_submissions_in_queue.rake @@ -0,0 +1,14 @@ +desc "Run all submission with status 'In Queue'." + +namespace :judge0 do + task :run_in_queue => :environment do + ARGV.each { |a| task a.to_sym do ; end } + Submission.where(status_id: Status.queue).each do |s| + if ARGV[1].to_s == "now" + IsolateRunner.perform_now(s) + else + IsolateRunner.perform_later(s) + end + end + end +end diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/public/docs.html b/public/docs.html new file mode 100644 index 0000000000000000000000000000000000000000..3b3df5b3ba490af5afd87edb9358876db20cb489 --- /dev/null +++ b/public/docs.html @@ -0,0 +1,1910 @@ +Judge0 CE - API Docs Back to top

Judge0 CE - API Docs

+ + + +

About

+

Judge0 is a robust, scalable, and open-source online code execution system. You can use it to build a wide range of applications that need online code execution features. Some examples include competitive programming platforms, e-learning platforms, candidate assessment and recruitment platforms, online code editors, online IDEs, and many more.

+

In our research paper Robust and Scalable Online Code Execution System, we present Judge0’s modern modular architecture that can be easily deployed and scaled. We study its design, comment on the various challenges in building such systems, and compare it with other available online code execution systems and online judge systems.

+

To see Judge0 in action, try Judge0 IDE - our free and open-source online code editor. You can also try using a dummy client that can help you explore and test most of the features of Judge0.

+

Features

+
    +
  • Quick and easy installation
  • +
  • Rich and verbose API documentation
  • +
  • Scalable architecture
  • +
  • Sandboxed compilation and execution
  • +
  • Support for 60+ languages
  • +
  • Compilation and execution of multi-file programs
  • +
  • Support for additional files alongside the user's program
  • +
  • Support for custom user-defined compiler options, command-line arguments, and time and memory limits
  • +
  • Detailed execution results
  • +
  • Webhooks (HTTP callbacks)
  • +
+

Get Started

+

Feel free to start with the FREE Basic Plan on RapidAPI or host it yourself.

+

You can find our detailed plans and pricing here.

+

Why should you use Judge0 on RapidAPI?

+

Our infrastructure allows you to focus on building your product and forget about the know-how of maintaining and scaling Judge0.

+

RapidAPI plans are not (good) enough for you?

+

Let’s talk. Contact us.

+

Flavors

+

Judge0 comes in two flavors: Judge0 CE and Judge0 Extra CE. They differ mostly in the supported languages.

+

You can find the source code for Judge0 CE on the master branch, while you can find the source code for Judge0 Extra CE on the extra branch.

+

Judge0 Extra CE is also available on RapidAPI.

+

Version

+

This document describes Judge0 CE v1.13.1.

+

Date and time formats

+

ISO 8601 standard is used.

+

Example: 2016-09-11T10:19:35Z

+

License

+

Judge0 is licensed under the GNU General Public License v3.0.

+

Authentication

Administrators of Judge0 can configure Judge0 to require you to have an authentication token (a.k.a. API key). +If that is the case with the instance of Judge0 you are using, then you +should provide X-Auth-Token header field in every API request.

+

Authenticate

Authenticate
POST/authenticate

Check if your authentication token is valid.

+
+

Note

+
    +
  • +

    X-Auth-Token is default header field name, but administrators of Judge0 instance you are using +can change this default field name.

    +
  • +
  • +

    Contact administrator of Judge0 instance you are using to get your authentication token.

    +
  • +
+
+
+

Security Warning

+
    +
  • Although you can send authentication token as URI parameter, always send authentication token through headers.
  • +
+
+

Example URI

POST https://ce.judge0.com/authenticate
Request
HideShow
Headers
X-Auth-Token: f6583e60-b13b-4228-b554-2eb332ca64e7
Response  200
HideShow

If your authentication token is valid or authentication is disabled. +If authentication is disabled you do not need an authentication token.

+
Response  401
HideShow

Authentication failed because your authentication token is invalid.

+

Authorization

To issue some API calls you need to be authorized. For example, you need to be authorized to +list all submissions on Judge0.

+

Authorize

Authorize
POST/authorize

With this API call you can check if your authorization token is valid. If authentication is enabled you should also +authenticate in this API call.

+
+

Note

+
    +
  • +

    X-Auth-User is default header field name, but administrators of Judge0 instance you are using +can change this default field name.

    +
  • +
  • +

    Contact administrator of Judge0 instance you are using to get your authorization token.

    +
  • +
+
+
+

Security Warning

+
    +
  • Although you can send authorization token as URI parameter, always send authorization token through headers.
  • +
+
+

Example URI

POST https://ce.judge0.com/authorize
Request
HideShow
Headers
X-Auth-User: a1133bc6-a0f6-46bf-a2d8-6157418c6fe2
Response  200
HideShow

If your authorization token is valid.

+
Response  401
HideShow

Authentication failed. Please read about authentication process.

+
Response  403
HideShow

Authorization failed because your authorization token is invalid.

+

Submissions

Submission

Submission is used for running arbitrary source code in one of +the available programming languages with specified runtime constraints.

+

Submission has 33 attributes. Attributes 1-20 are used for creating a new submissions, whereas +attributes 21-33 give detailed information of submission after it’s execution.

+

Attributes 7-18 are called configuration variables +and can be used to configure submission runtime constraints such as time and memory limits.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#NameTypeUnitDescriptionDefault Value
1source_codetextProgram’s source code.No default. This attribute is required for single-file programs.
2language_idintegerLanguage ID.No default. This attribute is required.
3compiler_optionsstring (max. 512 chars)Options for the compiler (i.e. compiler flags).null
4command_line_argumentsstring (max. 512 chars)Command line arguments for the program.null
5stdintextInput for program.null. Program won’t receive anything to standard input.
6expected_outputtextExpected output of program. Used when you want to compare with stdout.null. Program’s stdout won’t be compared with expected_output.
7cpu_time_limitfloatsecondDefault runtime limit for every program. Time in which the OS assigns the processor to different tasks is not counted.Depends on configuration.
8cpu_extra_timefloatsecondWhen a time limit is exceeded, wait for extra time, before killing the program. This has the advantage that the real execution time is reported, even though it slightly exceeds the limit.Depends on configuration.
9wall_time_limitfloatsecondLimit wall-clock time in seconds. Decimal numbers are allowed. This clock measures the time from the start of the program to its exit, so it does not stop when the program has lost the CPU or when it is waiting for an external event. We recommend to use cpu_time_limit as the main limit, but set wall_time_limit to a much higher value as a precaution against sleeping programs.Depends on configuration.
10memory_limitfloatkilobyteLimit address space of the program.Depends on configuration.
11stack_limitintegerkilobyteLimit process stack.Depends on configuration.
12max_processes_and_or_threadsintegerMaximum number of processes and/or threads program can create.Depends on configuration.
13enable_per_process_and_thread_time_limitbooleanIf true then cpu_time_limit will be used as per process and thread.Depends on configuration.
14enable_per_process_and_thread_memory_limitbooleanIf true then memory_limit will be used as per process and thread.Depends on configuration.
15max_file_sizeintegerkilobyteLimit file size created or modified by the program.Depends on configuration.
16redirect_stderr_to_stdoutbooleanIf true standard error will be redirected to standard output.Depends on configuration.
17enable_networkbooleanIf true program will have network access.Depends on configuration.
18number_of_runsintegerRun each program number_of_runs times and take average of time and memory.Depends on configuration.
19additional_filesBase64 Encoded StringAdditional files that should be available alongside the source code. Value of this string should represent the content of a .zip that contains additional files. This attribute is required for multi-file programs.null
20callback_urlstringURL on which Judge0 will issue PUT request with the submission in a request body after submission has been done.null
21stdouttextStandard output of the program after execution.
22stderrtextStandard error of the program after execution.
23compile_outputtextCompiler output after compilation.
24messagetextIf submission status is Internal Error then this message comes from Judge0 itself, otherwise this is status message from isolate.
25exit_codeintegerThe program’s exit code.
26exit_signalintegerSignal code that the program recieved before exiting.
27statusobjectSubmission status.
28created_atdatetimeDate and time when submission was created.
29finished_atdatetimeDate and time when submission was processed.null if submission is still in queue or if submission is processing.
30tokenstringUnique submission token which can be used to get a specific submission.
31timefloatsecondProgram’s run time.
32wall_timefloatsecondProgram’s wall time. Will be greater or equal to time.
33memoryfloatkilobyteMemory used by the program after execution.
+

Single-file programs and multi-file programs

+

Judge0 can run both single-file and multi-file programs in a sandboxed environment with specified resource limitations. +The usage of multi-file programs is slightly different from single-file programs and this section explains their differences and when they should be used.

+

Single-file programs

+

This is the simplest way to run a program with Judge0. Pick a language with language_id, provide a source_code and Judge0 will use predefined compilation and execution scripts for specified language. Additionally you can set custom compile flags, provide command line arguments and send additional_files that will be available in the sandbox alongside your single-file program.

+

With additional_files you can send, for example, Python modules which are imported by your main program that you provided in source_code attribute. For C or C++ programs with additional_files you can send header files which are included by your main program that you provided in source_code attribute.

+

Even though you can send and use multiple Python modules or C and C++ header files, we call this single-file programs because for compiled languages only one source file is compiled with predefined compilation scripts.

+

Multi-file programs

+

Multi-file programs are available since v1.10.0 and they allow you specify your own compilation and execution scripts that Judge0 will use.

+

To use multi-file program feature you need to choose a language called Multi-file program whoose ID is 89. Moreover, you need to send all program files with additional_files attribute. With multi-file programs attribute source_code cannot be used, i.e. all files should be sent with additional_files attribute.

+

As mentioned in the table above, additional_files attribute should be a content of a Base64 encoded .zip archive. This archive will be extracted in the sandbox before compilation and execution.

+

For the Judge0 to know how to compile and execute your multi-file program you need to provide two special files that should be available in the root of the .zip archive that you are sending with additional_files attribute. These files should be named compile and run, and are expected to be Bash scripts that know how to compile and execute your multi-file program. If your multi-file program does not need compilation step, then you don’t need to provide compile script. Take a look at this example to learn how to use this feature to compile and run multi-file C++ project that uses CMake.

+

Create a Submission
POST/submissions/{?base64_encoded,wait}

Creates new submission. Created submission waits in queue to be processed. On successful +creation, you are returned submission token which can be used to check submission status.

+

If submission’s source_code, stdin or expected_output contains non printable characters, or +characters which cannot be sent with JSON, then set base64_encoded parameter to true and +send these attributes Base64 encoded. Your responsibility is to encode each of mentioned attributes +(source_code, stdin and expected_output) even if just one of them contains non printable +characters. By default, this parameter is set to false and Judge0 assumes you are sending plain text data.

+

By default you are returned submission token on successful submission creation. With this token you can check submission status. +Instead of checking submission status by making another request, you can set the wait query parameter to true which will enable you to get submission status immediately as part of response to the request you made. +Please note that this feature may or may not be enabled on all Judge0 hosts. So before using this feature please check configuration of Judge0 you are using. On an official Judge0 this feature is not enabled.

+
+

Note

+
    +
  • We do not recommend the use of wait=true feature because it does not scale well.
  • +
+
+

Example URI

POST https://ce.judge0.com/submissions/?base64_encoded=false&wait=false
URI Parameters
HideShow
base64_encoded
boolean (optional) Default: false Example: false

Set to true if you want to send Base64 encoded data to Judge0.

+
wait
boolean (optional) Default: false Example: false

Set to true to immediately get submission result.

+
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
+  "language_id": 4,
+  "stdin": "world"
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
{
+  "token": "d85cd024-1548-4165-96c7-7bc88673f194"
+}
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}"
+}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
+  "language_id": [
+    "can't be blank"
+  ]
+}
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
+  "language_id": 150000,
+  "stdin": "world",
+  "expected_output": "hello, world"
+}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
+  "language_id": [
+    "language with id 150000 doesn't exist"
+  ]
+}
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
+  "language_id": 4,
+  "number_of_runs": 1,
+  "stdin": "Judge0",
+  "expected_output": "hello, Judge0",
+  "cpu_time_limit": 1,
+  "cpu_extra_time": 0.5,
+  "wall_time_limit": 100000,
+  "memory_limit": 128000,
+  "stack_limit": 128000,
+  "enable_per_process_and_thread_time_limit": false,
+  "enable_per_process_and_thread_memory_limit": false,
+  "max_file_size": 1024
+}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
+  "wall_time_limit": [
+    "must be less than or equal to 150"
+  ]
+}
Request
HideShow

Sending Base64 encoded source_code and stdin. Note that in this request base64_encoded query parameter must be +set to true.

+
Headers
Content-Type: appliction/json
Body
{
+  "source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBuYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxvLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=",
+  "language_id": 4,
+  "input": "SnVkZ2Uw"
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
{
+  "token": "f3fe0215-72f3-4fe6-97f5-353df6682db4"
+}
Request
HideShow

Creating a submission with wait=true that results with one or more attributes that cannot be serialized to JSON without Base64 encoding.

+
Headers
Content-Type: application/json
Body
{
+    "language_id": 70,
+    "source_code": "print(\"\xFE\")"
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
{
+  "token": "fcd0de6d-ee52-4a9d-8a00-6e0d98d394cf",
+  "error": "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter"
+}
Request
HideShow

Waiting for submission to finish. Note that in this request wait query parameter must be set to true.

+
Headers
Content-Type: application/json
Body
{
+  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
+  "language_id": "4",
+  "stdin": "Judge0",
+  "expected_output": "hello, Judge0"
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
{
+  "stdout": "hello, Judge0\n",
+  "time": "0.001",
+  "memory": 380,
+  "stderr": null,
+  "token": "eb0dd001-66db-47f4-8a69-b736c9bc23f6",
+  "compile_output": null,
+  "message": null,
+  "status": {
+    "id": 3,
+    "description": "Accepted"
+  }
+}
Response  400
HideShow

If wait is not allowed.

+
Headers
Content-Type: application/json
Body
{
+  "error": "wait not allowed"
+}
Response  503
HideShow

If submission queue is full.

+
Headers
Content-Type: application/json
Body
{
+  "error": "queue is full"
+}
Response  401
HideShow

Authentication failed. Please read about authentication process.

+

Get a Submission
GET/submissions/{token}{?base64_encoded,fields}

Returns details about submission.

+

Just like in create submission you can receive Base64 encoded data for every text type attribute (check the table to see which attributes are text type). By default, this parameter is set to false and Judge0 will send you raw data.

+

By default Judge0 is sending 8 attributes for submission. By sending fields query parameter you can specify exactly which attributes you want from Judge0. Special value * will return all available attributes.

+

Example URI

GET https://ce.judge0.com/submissions/d85cd024-1548-4165-96c7-7bc88673f194?base64_encoded=false&fields=stdout,stderr,status_id,language_id
URI Parameters
HideShow
token
string (required) Example: d85cd024-1548-4165-96c7-7bc88673f194

Token of submission. You got this token when you created submission.

+
base64_encoded
boolean (optional) Example: false

Set to true if you want to receive Base64 encoded data from Judge0. You should set this to true if you expect the program’s stdout to contain non-printable characters or if you expect the compiler to output non-printable characters during a compile error (GCC does this, for instance).

+
fields
string (optional) Default: stdout,time,memory,stderr,token,compile_output,message,status Example: stdout,stderr,status_id,language_id

Return only the desired attributes.

+
Response  200
HideShow
Headers
Content-Type: applicatiion/json
Body
{
+  "stdout": "hello, world\n",
+  "status_id": 5,
+  "language_id": 4,
+  "stderr": null
+}
Response  200
HideShow

This is the default response. Leave fields parameter empty if you want to get default response.

+
Headers
Content-Type: application/json
Body
{
+  "stdout": "hello, Judge0\n",
+  "time": "0.001",
+  "memory": 376,
+  "stderr": null,
+  "token": "8531f293-1585-4d36-a34c-73726792e6c9",
+  "compile_output": null,
+  "message": null,
+  "status": {
+    "id": 3,
+    "description": "Accepted"
+  }
+}
Response  200
HideShow

Receiving Base64 encoded data for text type attributes. Note that in this request base64_encoded query parameter must be set to true.

+
Headers
Content-Type: application/json
Body
{
+  "stdout": "aGVsbG8sIEp1ZGdlMAo=\n",
+  "time": "0.002",
+  "memory": 376,
+  "stderr": null,
+  "token": "4e00f214-b8cb-4fcb-977b-429113c81ece",
+  "compile_output": null,
+  "message": null,
+  "status": {
+    "id": 3,
+    "description": "Accepted"
+  }
+}
Response  400
HideShow
Headers
Content-Type: application/json
Body
{
+  "error": "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter"
+}
Response  401
HideShow

Authentication failed. Please read about authentication process.

+

Get Submissions
GET/submissions/{?base64_encoded,fields,page,per_page}

Example URI

GET https://ce.judge0.com/submissions/?base64_encoded=false&fields=status,language,time&page=4&per_page=2
URI Parameters
HideShow
base64_encoded
boolean (optional) Default: false Example: false

Set to true if you want to receive Base64 encoded data from Judge0.

+
page
integer (optional) Default: 1 Example: 4

Pagination page number.

+
per_page
integer (optional) Default: 20 Example: 2

Number of submissions to return per page.

+
fields
string (optional) Default: stdout,time,memory,stderr,token,compile_output,message,status Example: status,language,time

Return only the desired attributes.

+
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "submissions": [
+    {
+      "time": "0.001",
+      "status": {
+        "id": 3,
+        "description": "Accepted"
+      },
+      "language": {
+        "id": 4,
+        "name": "C (gcc 7.2.0)"
+      }
+    },
+    {
+      "time": "0.001",
+      "status": {
+        "id": 3,
+        "description": "Accepted"
+      },
+      "language": {
+        "id": 4,
+        "name": "C (gcc 7.2.0)"
+      }
+    }
+  ],
+  "meta": {
+    "current_page": 4,
+    "next_page": 5,
+    "prev_page": 3,
+    "total_pages": 31,
+    "total_count": 62
+  }
+}
Response  200
HideShow

When base64_encoded is set to true.

+
Headers
Content-Type: application/json
Body
{
+  "submissions": [
+    {
+      "stdout": "aGVsbG8sIEp1ZGdlMAo=\n",
+      "time": "0.001",
+      "memory": 376,
+      "stderr": null,
+      "token": "a1133bc6-a0f6-46bf-a2d8-6157418c6fe2",
+      "compile_output": null,
+      "message": null,
+      "status": {
+        "id": 3,
+        "description": "Accepted"
+      }
+    },
+    {
+      "stdout": "aGVsbG8sIEp1ZGdlMAo=\n",
+      "time": "0.001",
+      "memory": 380,
+      "stderr": null,
+      "token": "eb0dd001-66db-47f4-8a69-b736c9bc23f6",
+      "compile_output": null,
+      "message": null,
+      "status": {
+        "id": 3,
+        "description": "Accepted"
+      }
+    }
+  ],
+  "meta": {
+    "current_page": 4,
+    "next_page": 5,
+    "prev_page": 3,
+    "total_pages": 31,
+    "total_count": 62
+  }
+}
Response  400
HideShow

When page parameter is invalid.

+
Headers
Content-Type: application/json
Body
{
+  "error": "invalid page: -4"
+}
Response  400
HideShow

When per_page parameter is invalid.

+
Headers
Content-Type: application/json
Body
{
+  "error": "invalid per_page: -2"
+}
Response  400
HideShow
Headers
Content-Type: application/json
Body
{
+  "error": "some attributes for one or more submissions cannot be converted to UTF-8, use base64_encoded=true query parameter"
+}
Response  401
HideShow

Authentication failed. Please read about authentication process.

+
Response  403
HideShow

Authorization failed. Please read about authorization process.

+

Delete a Submission
DELETE/submissions/{token}{?fields}

Delete specific submission.

+

You need to be authorized to issue this request. Although you are +authorized you might not be able to delete submission because administrator of Judge0 instance +you are using disallowed submission deletion. So before using this feature please check configuration of Judge0 you are using.

+

For this request query parameter base64_encoded is implicitly set to true and cannot be changed. +This guarantees you will successfully get requested submission attributes after deletion.

+

Example URI

DELETE https://ce.judge0.com/submissions/d85cd024-1548-4165-96c7-7bc88673f194?fields=stdout,stderr,status_id,language_id
URI Parameters
HideShow
token
string (required) Example: d85cd024-1548-4165-96c7-7bc88673f194

Token of submission. You got this token when you created submission.

+
fields
string (optional) Default: stdout,time,memory,stderr,token,compile_output,message,status Example: stdout,stderr,status_id,language_id

Return only the desired attributes.

+
Response  200
HideShow
Headers
Content-Type: applcation/json
Body
{
+  "stdout": "aGVsbG8sIHdvcmxkCg==\n",
+  "time": "0.045",
+  "memory": 8556,
+  "stderr": null,
+  "token": "e80153f5-e7d8-4cd2-9e10-6c0ddbf9e3bf",
+  "compile_output": null,
+  "message": null,
+  "status": {
+    "id": 3,
+    "description": "Accepted"
+  }
+}
Response  400
HideShow

If submission status is 1 or 2.

+
Headers
Content-Type: application/json
Body
{
+  "error": "submission cannot be deleted because its status is 1 (In Queue)"
+}
Response  401
HideShow

Authentication failed. Please read about authentication process.

+
Response  403
HideShow

Authorization failed. Please read about authorization process.

+

Submission Batch

Create a Submission Batch
POST/submissions/batch{?base64_encoded}

Create multiple submissions at once.

+

Example URI

POST https://ce.judge0.com/submissions/batch?base64_encoded=false
URI Parameters
HideShow
base64_encoded
boolean (optional) Default: false Example: false

Set to true if you are sending Base64 encoded data.

+
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "submissions": [
+    {
+      "language_id": 46,
+      "source_code": "echo hello from Bash"
+    },
+    {
+      "language_id": 71,
+      "source_code": "print(\"hello from Python\")"
+    },
+    {
+      "language_id": 72,
+      "source_code": "puts(\"hello from Ruby\")"
+    }
+  ]
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "token": "db54881d-bcf5-4c7b-a2e3-d33fe7e25de7"
+  },
+  {
+    "token": "ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1"
+  },
+  {
+    "token": "1b35ec3b-5776-48ef-b646-d5522bdeb2cc"
+  }
+]
Request
HideShow
Headers
Content-Type: application/json
Body
{
+  "submissions": [
+    {
+      "language_id": 46,
+      "source_code": "echo hello from Bash"
+    },
+    {
+      "language_id": 123456789,
+      "source_code": "print(\"hello from Python\")"
+    },
+    {
+      "language_id": 72,
+      "source_code": ""
+    }
+  ]
+}
Response  201
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "token": "c2dd8881-644b-462d-b1f9-73dd3bb0118a"
+  },
+  {
+    "language_id": [
+      "language with id 123456789 doesn't exist"
+    ]
+  },
+  {
+    "source_code": [
+      "can't be blank"
+    ]
+  }
+]

Get a Submission Batch
GET/submissions/batch{?tokens,base64_encoded,fields}

Get multiple submissions at once.

+

Example URI

GET https://ce.judge0.com/submissions/batch?tokens=db54881d-bcf5-4c7b-a2e3-d33fe7e25de7,ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1,1b35ec3b-5776-48ef-b646-d5522bdeb2cc&base64_encoded=false&fields=token,stdout,stderr,status_id,language_id
URI Parameters
HideShow
tokens
string (required) Example: db54881d-bcf5-4c7b-a2e3-d33fe7e25de7,ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1,1b35ec3b-5776-48ef-b646-d5522bdeb2cc

Submission tokens separeted with ,.

+
base64_encoded
boolean (optional) Default: false Example: false

Set to true if you want to receive Base64 encoded data.

+
fields
string (optional) Default: stdout,time,memory,stderr,token,compile_output,message,status Example: token,stdout,stderr,status_id,language_id

Return only the desired attributes.

+
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "submissions": [
+    {
+      "language_id": 46,
+      "stdout": "hello from Bash\n",
+      "status_id": 3,
+      "stderr": null,
+      "token": "db54881d-bcf5-4c7b-a2e3-d33fe7e25de7"
+    },
+    {
+      "language_id": 71,
+      "stdout": "hello from Python\n",
+      "status_id": 3,
+      "stderr": null,
+      "token": "ecc52a9b-ea80-4a00-ad50-4ab6cc3bb2a1"
+    },
+    {
+      "language_id": 72,
+      "stdout": "hello from Ruby\n",
+      "status_id": 3,
+      "stderr": null,
+      "token": "1b35ec3b-5776-48ef-b646-d5522bdeb2cc"
+    }
+  ]
+}

Statuses and Languages

Language

Get Languages
GET/languages/

Get active languages.

+

Example URI

GET https://ce.judge0.com/languages/
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "id": 45,
+    "name": "Assembly (NASM 2.14.02)"
+  },
+  {
+    "id": 46,
+    "name": "Bash (5.0.0)"
+  },
+  {
+    "id": 47,
+    "name": "Basic (FBC 1.07.1)"
+  },
+  {
+    "id": 48,
+    "name": "C (GCC 7.4.0)"
+  },
+  {
+    "id": 52,
+    "name": "C++ (GCC 7.4.0)"
+  },
+  {
+    "id": 49,
+    "name": "C (GCC 8.3.0)"
+  },
+  {
+    "id": 53,
+    "name": "C++ (GCC 8.3.0)"
+  },
+  {
+    "id": 50,
+    "name": "C (GCC 9.2.0)"
+  },
+  {
+    "id": 54,
+    "name": "C++ (GCC 9.2.0)"
+  },
+  {
+    "id": 51,
+    "name": "C# (Mono 6.6.0.161)"
+  },
+  {
+    "id": 55,
+    "name": "Common Lisp (SBCL 2.0.0)"
+  },
+  {
+    "id": 56,
+    "name": "D (DMD 2.089.1)"
+  },
+  {
+    "id": 57,
+    "name": "Elixir (1.9.4)"
+  },
+  {
+    "id": 58,
+    "name": "Erlang (OTP 22.2)"
+  },
+  {
+    "id": 44,
+    "name": "Executable"
+  },
+  {
+    "id": 59,
+    "name": "Fortran (GFortran 9.2.0)"
+  },
+  {
+    "id": 60,
+    "name": "Go (1.13.5)"
+  },
+  {
+    "id": 61,
+    "name": "Haskell (GHC 8.8.1)"
+  },
+  {
+    "id": 62,
+    "name": "Java (OpenJDK 13.0.1)"
+  },
+  {
+    "id": 63,
+    "name": "JavaScript (Node.js 12.14.0)"
+  },
+  {
+    "id": 64,
+    "name": "Lua (5.3.5)"
+  },
+  {
+    "id": 65,
+    "name": "OCaml (4.09.0)"
+  },
+  {
+    "id": 66,
+    "name": "Octave (5.1.0)"
+  },
+  {
+    "id": 67,
+    "name": "Pascal (FPC 3.0.4)"
+  },
+  {
+    "id": 68,
+    "name": "PHP (7.4.1)"
+  },
+  {
+    "id": 43,
+    "name": "Plain Text"
+  },
+  {
+    "id": 69,
+    "name": "Prolog (GNU Prolog 1.4.5)"
+  },
+  {
+    "id": 70,
+    "name": "Python (2.7.17)"
+  },
+  {
+    "id": 71,
+    "name": "Python (3.8.1)"
+  },
+  {
+    "id": 72,
+    "name": "Ruby (2.7.0)"
+  },
+  {
+    "id": 73,
+    "name": "Rust (1.40.0)"
+  },
+  {
+    "id": 74,
+    "name": "TypeScript (3.7.4)"
+  }
+]

Get a Language
GET/languages/{id}

Example URI

GET https://ce.judge0.com/languages/1
URI Parameters
HideShow
id
integer (required) Example: 1

Language ID.

+
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "id": 1,
+  "name": "Bash (4.4)",
+  "is_archived": true,
+  "source_file": "script.sh",
+  "compile_cmd": null,
+  "run_cmd": "/usr/local/bash-4.4/bin/bash script.sh"
+}

Active and Archived Languages

Get Active and Archived Languages
GET/languages/all

Get active and archived languages.

+

Example URI

GET https://ce.judge0.com/languages/all
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "id": 45,
+    "name": "Assembly (NASM 2.14.02)",
+    "is_archived": false
+  },
+  {
+    "id": 2,
+    "name": "Bash (4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 1,
+    "name": "Bash (4.4)",
+    "is_archived": true
+  },
+  {
+    "id": 46,
+    "name": "Bash (5.0.0)",
+    "is_archived": false
+  },
+  {
+    "id": 3,
+    "name": "Basic (fbc 1.05.0)",
+    "is_archived": true
+  },
+  {
+    "id": 47,
+    "name": "Basic (FBC 1.07.1)",
+    "is_archived": false
+  },
+  {
+    "id": 15,
+    "name": "C++ (g++ 4.8.5)",
+    "is_archived": true
+  },
+  {
+    "id": 14,
+    "name": "C++ (g++ 4.9.4)",
+    "is_archived": true
+  },
+  {
+    "id": 13,
+    "name": "C++ (g++ 5.4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 12,
+    "name": "C++ (g++ 6.3.0)",
+    "is_archived": true
+  },
+  {
+    "id": 11,
+    "name": "C++ (g++ 6.4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 10,
+    "name": "C++ (g++ 7.2.0)",
+    "is_archived": true
+  },
+  {
+    "id": 9,
+    "name": "C (gcc 4.8.5)",
+    "is_archived": true
+  },
+  {
+    "id": 8,
+    "name": "C (gcc 4.9.4)",
+    "is_archived": true
+  },
+  {
+    "id": 7,
+    "name": "C (gcc 5.4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 6,
+    "name": "C (gcc 6.3.0)",
+    "is_archived": true
+  },
+  {
+    "id": 5,
+    "name": "C (gcc 6.4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 4,
+    "name": "C (gcc 7.2.0)",
+    "is_archived": true
+  },
+  {
+    "id": 48,
+    "name": "C (GCC 7.4.0)",
+    "is_archived": false
+  },
+  {
+    "id": 52,
+    "name": "C++ (GCC 7.4.0)",
+    "is_archived": false
+  },
+  {
+    "id": 49,
+    "name": "C (GCC 8.3.0)",
+    "is_archived": false
+  },
+  {
+    "id": 53,
+    "name": "C++ (GCC 8.3.0)",
+    "is_archived": false
+  },
+  {
+    "id": 50,
+    "name": "C (GCC 9.2.0)",
+    "is_archived": false
+  },
+  {
+    "id": 54,
+    "name": "C++ (GCC 9.2.0)",
+    "is_archived": false
+  },
+  {
+    "id": 18,
+    "name": "Clojure (1.8.0)",
+    "is_archived": true
+  },
+  {
+    "id": 17,
+    "name": "C# (mono 5.2.0.224)",
+    "is_archived": true
+  },
+  {
+    "id": 16,
+    "name": "C# (mono 5.4.0.167)",
+    "is_archived": true
+  },
+  {
+    "id": 51,
+    "name": "C# (Mono 6.6.0.161)",
+    "is_archived": false
+  },
+  {
+    "id": 55,
+    "name": "Common Lisp (SBCL 2.0.0)",
+    "is_archived": false
+  },
+  {
+    "id": 19,
+    "name": "Crystal (0.23.1)",
+    "is_archived": true
+  },
+  {
+    "id": 56,
+    "name": "D (DMD 2.089.1)",
+    "is_archived": false
+  },
+  {
+    "id": 20,
+    "name": "Elixir (1.5.1)",
+    "is_archived": true
+  },
+  {
+    "id": 57,
+    "name": "Elixir (1.9.4)",
+    "is_archived": false
+  },
+  {
+    "id": 21,
+    "name": "Erlang (OTP 20.0)",
+    "is_archived": true
+  },
+  {
+    "id": 58,
+    "name": "Erlang (OTP 22.2)",
+    "is_archived": false
+  },
+  {
+    "id": 44,
+    "name": "Executable",
+    "is_archived": false
+  },
+  {
+    "id": 59,
+    "name": "Fortran (GFortran 9.2.0)",
+    "is_archived": false
+  },
+  {
+    "id": 60,
+    "name": "Go (1.13.5)",
+    "is_archived": false
+  },
+  {
+    "id": 22,
+    "name": "Go (1.9)",
+    "is_archived": true
+  },
+  {
+    "id": 24,
+    "name": "Haskell (ghc 8.0.2)",
+    "is_archived": true
+  },
+  {
+    "id": 23,
+    "name": "Haskell (ghc 8.2.1)",
+    "is_archived": true
+  },
+  {
+    "id": 61,
+    "name": "Haskell (GHC 8.8.1)",
+    "is_archived": false
+  },
+  {
+    "id": 25,
+    "name": "Insect (5.0.0)",
+    "is_archived": true
+  },
+  {
+    "id": 62,
+    "name": "Java (OpenJDK 13.0.1)",
+    "is_archived": false
+  },
+  {
+    "id": 28,
+    "name": "Java (OpenJDK 7)",
+    "is_archived": true
+  },
+  {
+    "id": 27,
+    "name": "Java (OpenJDK 8)",
+    "is_archived": true
+  },
+  {
+    "id": 26,
+    "name": "Java (OpenJDK 9 with Eclipse OpenJ9)",
+    "is_archived": true
+  },
+  {
+    "id": 63,
+    "name": "JavaScript (Node.js 12.14.0)",
+    "is_archived": false
+  },
+  {
+    "id": 30,
+    "name": "JavaScript (nodejs 7.10.1)",
+    "is_archived": true
+  },
+  {
+    "id": 29,
+    "name": "JavaScript (nodejs 8.5.0)",
+    "is_archived": true
+  },
+  {
+    "id": 64,
+    "name": "Lua (5.3.5)",
+    "is_archived": false
+  },
+  {
+    "id": 31,
+    "name": "OCaml (4.05.0)",
+    "is_archived": true
+  },
+  {
+    "id": 65,
+    "name": "OCaml (4.09.0)",
+    "is_archived": false
+  },
+  {
+    "id": 32,
+    "name": "Octave (4.2.0)",
+    "is_archived": true
+  },
+  {
+    "id": 66,
+    "name": "Octave (5.1.0)",
+    "is_archived": false
+  },
+  {
+    "id": 33,
+    "name": "Pascal (fpc 3.0.0)",
+    "is_archived": true
+  },
+  {
+    "id": 67,
+    "name": "Pascal (FPC 3.0.4)",
+    "is_archived": false
+  },
+  {
+    "id": 68,
+    "name": "PHP (7.4.1)",
+    "is_archived": false
+  },
+  {
+    "id": 43,
+    "name": "Plain Text",
+    "is_archived": false
+  },
+  {
+    "id": 69,
+    "name": "Prolog (GNU Prolog 1.4.5)",
+    "is_archived": false
+  },
+  {
+    "id": 37,
+    "name": "Python (2.6.9)",
+    "is_archived": true
+  },
+  {
+    "id": 70,
+    "name": "Python (2.7.17)",
+    "is_archived": false
+  },
+  {
+    "id": 36,
+    "name": "Python (2.7.9)",
+    "is_archived": true
+  },
+  {
+    "id": 35,
+    "name": "Python (3.5.3)",
+    "is_archived": true
+  },
+  {
+    "id": 34,
+    "name": "Python (3.6.0)",
+    "is_archived": true
+  },
+  {
+    "id": 71,
+    "name": "Python (3.8.1)",
+    "is_archived": false
+  },
+  {
+    "id": 41,
+    "name": "Ruby (2.1.9)",
+    "is_archived": true
+  },
+  {
+    "id": 40,
+    "name": "Ruby (2.2.6)",
+    "is_archived": true
+  },
+  {
+    "id": 39,
+    "name": "Ruby (2.3.3)",
+    "is_archived": true
+  },
+  {
+    "id": 38,
+    "name": "Ruby (2.4.0)",
+    "is_archived": true
+  },
+  {
+    "id": 72,
+    "name": "Ruby (2.7.0)",
+    "is_archived": false
+  },
+  {
+    "id": 42,
+    "name": "Rust (1.20.0)",
+    "is_archived": true
+  },
+  {
+    "id": 73,
+    "name": "Rust (1.40.0)",
+    "is_archived": false
+  },
+  {
+    "id": 74,
+    "name": "TypeScript (3.7.4)",
+    "is_archived": false
+  }
+]

Status

Get Statuses
GET/statuses

Example URI

GET https://ce.judge0.com/statuses
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "id": 1,
+    "description": "In Queue"
+  },
+  {
+    "id": 2,
+    "description": "Processing"
+  },
+  {
+    "id": 3,
+    "description": "Accepted"
+  },
+  {
+    "id": 4,
+    "description": "Wrong Answer"
+  },
+  {
+    "id": 5,
+    "description": "Time Limit Exceeded"
+  },
+  {
+    "id": 6,
+    "description": "Compilation Error"
+  },
+  {
+    "id": 7,
+    "description": "Runtime Error (SIGSEGV)"
+  },
+  {
+    "id": 8,
+    "description": "Runtime Error (SIGXFSZ)"
+  },
+  {
+    "id": 9,
+    "description": "Runtime Error (SIGFPE)"
+  },
+  {
+    "id": 10,
+    "description": "Runtime Error (SIGABRT)"
+  },
+  {
+    "id": 11,
+    "description": "Runtime Error (NZEC)"
+  },
+  {
+    "id": 12,
+    "description": "Runtime Error (Other)"
+  },
+  {
+    "id": 13,
+    "description": "Internal Error"
+  },
+  {
+    "id": 14,
+    "description": "Exec Format Error"
+  }
+]

System and Configuration

System Info

System Info
GET/system_info

System information gives you detailed information about system on which Judge0 is running.

+

This information is result of two commands on a host system:

+
    +
  • +

    lscpu

    +
  • +
  • +

    free -h

    +
  • +
+

Please note that Judge0 consists of two systems: web and worker. Web system is the one who +provides you the web API, and Worker is the one who processes your submissions. They can be placed on two or more +different hosts with different system configurations. Result of this API request is always from web system. +This means that this request might be irrelevant to you if you as user don’t know if web and worker are +hosted on the same machine. To find that out, please contact admins who host Judge0 you are using.

+

Example URI

GET https://ce.judge0.com/system_info
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "Architecture": "x86_64",
+  "CPU op-mode(s)": "32-bit, 64-bit",
+  "Byte Order": "Little Endian",
+  "CPU(s)": "4",
+  "On-line CPU(s) list": "0-3",
+  "Thread(s) per core": "2",
+  "Core(s) per socket": "2",
+  "Socket(s)": "1",
+  "NUMA node(s)": "1",
+  "Vendor ID": "GenuineIntel",
+  "CPU family": "6",
+  "Model": "61",
+  "Model name": "Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz",
+  "Stepping": "4",
+  "CPU MHz": "2508.703",
+  "CPU max MHz": "2700.0000",
+  "CPU min MHz": "500.0000",
+  "BogoMIPS": "4392.12",
+  "Virtualization": "VT-x",
+  "L1d cache": "32K",
+  "L1i cache": "32K",
+  "L2 cache": "256K",
+  "L3 cache": "3072K",
+  "NUMA node0 CPU(s)": "0-3",
+  "Mem": "7.7G",
+  "Swap": "8.0G"
+}

Configuration Info

Configuration Info
GET/config_info

Configuration information gives you detailed information about configuration of Judge0. +This configuration can be changed through judge0.conf +file by admin who hosts Judge0 instance.

+

This configuration gives every admin a flexibility to configure Judge0 according to server abilities and needs. It also gives users +insight on some default configuration values which are used when their programs are run.

+

Each of these configuration variables have default values which we consider as recommended in case you are not sure should you change them.

+

We will refer to default values as values which Judge0 automatically assigns to each of these configuration variables, +if admin didn’t set them. For example, default value of configuration variable cpu_time_limit is 2.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#NameTypeUnitDescriptionDefault Value
1enable_wait_resultbooleanIf enabled user can request to synchronously wait for submission result on submission create.true
2enable_compiler_optionsbooleanIf enabled user can set compiler_options.true
3allowed_languages_for_compile_optionslist of stringsLanguages for which setting compiler options is allowed.Empty, i.e. for all languages it is allowed to set compiler options.
4enable_command_line_argumentsbooleanIf enabled user can set command_line_arguments.true
5enable_submission_deletebooleanIf enabled authorized user can delete a submission.false
6max_queue_sizeintegerMaximum number of submissions that can wait in queue.100
7cpu_time_limitfloatsecondDefault runtime limit for every program (in seconds). Decimal numbers are allowed. Time in which the OS assigns the processor to different tasks is not counted.2
8cpu_extra_timefloatsecondWhen a time limit is exceeded, wait for extra time, before killing the program. This has the advantage that the real execution time is reported, even though it slightly exceeds the limit.0.5
9wall_time_limitfloatsecondLimit wall-clock time in seconds. Decimal numbers are allowed. This clock measures the time from the start of the program to its exit, for an external event. We recommend to use cpu_time_limit as the main limit, but set wall_time_limit to a much higher value as a precaution against sleeping programs.5
10memory_limitintegerkilobyteLimit address space of the program in kilobytes.128000
11stack_limitintegerkilobyteLimit process stack in kilobytes.64000
12max_processes_and_or_threadsintegerMaximum number of processes and/or threads program can create.60
13enable_per_process_and_thread_time_limitbooleanIf true then cpu_time_limit will be used as per process and thread.false
14enable_per_process_and_thread_memory_limitbooleanIf true then memory_limit will be used as per process and thread.true
15max_file_sizeintegerkilobyteLimit size of files created (or modified) by the program.1024
16allow_enable_networkbooleanIf enabled user can set enable_network.true
17enable_networkbooleanIf enabled program will have network access.true
18number_of_runsintegerRun each program this many times and take average of time and memory.1
+

Default configuration value for each variable is given to you as response of this API call. For example, default configuration value +for variable cpu_extra_time might be 2, and if admin didn’t set this, then it is 0.5 (default value). +This means that admin set cpu_extra_time configuration variable to value 2 and we say it is now default configuration value for this +variable cpu_extra_time.

+

Every submission can change each of the configuration variables according to its needs. For example, +user might create submission which has cpu_time_limit of 5 seconds. For security reasons we need to limit values of each of these +configuration variables. For example, we don’t want user to create a submission which has cpu_time_limit of 100000 seconds.

+

For this security reason we are introducing limit configuration variables for each configuration variable.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#NameTypeUnitDescriptionDefault Value
1max_cpu_time_limitfloatsecondMaximum custom cpu_time_limit15
2max_cpu_extra_timefloatsecondMaximum custom cpu_extra_time2
3max_wall_time_limitfloatsecondMaximum custom wall_time_limit20
4max_memory_limitintegerkilobyteMaximum custom memory_limit256000
5max_stack_limitintegerkilobyteMaximum custom stack_limit128000
6max_max_processes_and_or_threadsintegerMaximum custom max_processes_and_or_threads120
7allow_enable_per_process_and_thread_time_limitbooleanIf false user won’t be able to set enable_per_process_and_thread_time_limit to truetrue
8allow_enable_per_process_and_thread_memory_limitbooleanIf false user won’t be able to set enable_per_process_and_thread_memory_limit to truetrue
9max_max_file_sizeintegerkilobyteMaximux custom max_file_size4096
10max_number_of_runsintegerMaximum custom number_of_runs20
+

For example, max_cpu_time_limit with value 20 means that user cannot create new submission which has cpu_time_limit greater than 20.

+

Example URI

GET https://ce.judge0.com/config_info
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "enable_wait_result": true,
+  "enable_compiler_options": true,
+  "allowed_languages_for_compile_options": [],
+  "enable_command_line_arguments": true,
+  "enable_submission_delete": false,
+  "max_queue_size": 100,
+  "cpu_time_limit": 2,
+  "max_cpu_time_limit": 15,
+  "cpu_extra_time": 0.5,
+  "max_cpu_extra_time": 2,
+  "wall_time_limit": 5,
+  "max_wall_time_limit": 20,
+  "memory_limit": 128000,
+  "max_memory_limit": 256000,
+  "stack_limit": 64000,
+  "max_stack_limit": 128000,
+  "max_processes_and_or_threads": 60,
+  "max_max_processes_and_or_threads": 120,
+  "enable_per_process_and_thread_time_limit": false,
+  "allow_enable_per_process_and_thread_time_limit": true,
+  "enable_per_process_and_thread_memory_limit": true,
+  "allow_enable_per_process_and_thread_memory_limit": true,
+  "max_file_size": 1024,
+  "max_max_file_size": 4096,
+  "number_of_runs": 1,
+  "max_number_of_runs": 20
+}

Statistics

Statistics

Statistics
GET/statistics

Get some statistics from current instance. Result is cached for 10 minutes.

+

Example URI

GET https://ce.judge0.com/statistics
URI Parameters
HideShow
invalidate_cache
boolean (optional) Example: false

Set to true if you want to invalidate current cache and fetch new statistics.

+

Health Check

Workers

Workers
GET/workers

For each queue you will get:

+
    +
  • +

    queue name

    +
  • +
  • +

    queue size, i.e. number of submissions that are currently waiting to be processed

    +
  • +
  • +

    available number of workers

    +
  • +
  • +

    how many workers are idle

    +
  • +
  • +

    how many workers are currently working

    +
  • +
  • +

    how many workers are paused

    +
  • +
  • +

    how many jobs failed

    +
  • +
+

Example URI

GET https://ce.judge0.com/workers
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
+  {
+    "queue": "default",
+    "size": 0,
+    "available": 1,
+    "idle": 1,
+    "working": 0,
+    "paused": 0,
+    "failed": 0
+  }
+]

Information

About

About
GET/about

Returns general information.

+

Example URI

GET https://ce.judge0.com/about
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
+  "version": "1.5.0",
+  "homepage": "https://judge0.com",
+  "source_code": "https://github.com/judge0/judge0",
+  "maintainer": "Herman Zvonimir Došilović <hermanz.dosilovic@gmail.com>"
+}

Version

Version
GET/version

Returns current version.

+

Example URI

GET https://ce.judge0.com/version

Isolate

Isolate
GET/isolate

Returns result of isolate --version.

+

Example URI

GET https://ce.judge0.com/isolate

License

License
GET/license

Returns a license.

+

Example URI

GET https://ce.judge0.com/license

Generated by aglio on 17 Apr 2024

\ No newline at end of file diff --git a/public/dummy-client.html b/public/dummy-client.html new file mode 100644 index 0000000000000000000000000000000000000000..f73d78b648dd6e7ddf4216ba435b2157333ef114 --- /dev/null +++ b/public/dummy-client.html @@ -0,0 +1,346 @@ + + + + + Judge0 Dummy Client + + + + +

Judge0 Dummy Client

+

+ Judge0 dummy client can be used to try and test features of Judge0. Data is not validated on client side. + Client first creates new submission and then fetches submission status every 1500ms. + Client stops fetching submission status after recieving an error or when submission status is not In Queue or Processing. +

+

+ Note that you need to define API URL. This is the base url of some Judge0 host (e.g. https://api.judge0.com). + Description of network errors can be found in console of your browser, so check that for more information. +

+ +
+ + API URL  +

+ AUTHENTICATION HEADER  +

+ AUTHENTICATION TOKEN  +

+ AUTHORIZATION HEADER  +

+ AUTHORIZATION TOKEN  +

+ Source Code + null
+

+ Language ID  + + null

+ Number Of Runs  + + null

+ + CPU Time Limit  + + null

+ + CPU Extra Time  + + null

+ + Wall Time Limit  + + null

+ + Memory Limit  + + null

+ + Stack Limit  + + null

+ + Max Processes And Or Threads  + + null

+ + Enable Per Process And Thread Time Limit + true + false + null

+ + Enable Per Process And Thread Memory Limit + true + false + null

+ + Max File Size  + + null

+ + Enable Network + true + false + null

+ + Stdin + null
+

+ + Expected Output + null
+

+ + Fields  +

+ + + Wait for submission

+ + + Send request with Base64 encoded data

+ + + Accept response with Base64 encoded data

+ +
+ + + + +
+ +
+ +

Request/Response Log


+

+
+  
+
+
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000000000000000000000000000000000000..457b2748de5dcca5d0670be25fc319924ed3e607
Binary files /dev/null and b/public/favicon.ico differ
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/scripts/dev/bundle b/scripts/dev/bundle
new file mode 100644
index 0000000000000000000000000000000000000000..8b46dc23b3ac2a8f66c056d8d06f66d0f5e13c8f
--- /dev/null
+++ b/scripts/dev/bundle
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Script for creating release bundle.
+#
+# Usage: ./scripts/dev/bundle
+#
+set -e
+
+commit_tag="$(git tag --points-at HEAD)"
+if [[ $commit_tag == "" ]]; then
+    echo "No tag for current commit."
+    exit -1
+fi
+
+docker_tag=${commit_tag:1} # Drop the "v" at the beginning.
+
+release_dir=release-$commit_tag
+mkdir -p $release_dir
+
+for ext in "" ".https" ".workers" ".server"; do
+    instance_dir=judge0-$commit_tag
+    if [[ $ext != "" ]]; then
+        instance_dir=$instance_dir-${ext:1}
+    fi
+    pushd $release_dir
+    mkdir -p $instance_dir
+    cp ../docker-compose$ext.yml $instance_dir/docker-compose.yml
+    cp ../judge0.conf $instance_dir/
+    sed -i.bak "s/judge0:latest/judge0:$docker_tag/g" $instance_dir/docker-compose.yml
+    rm $instance_dir/docker-compose.yml.bak
+    zip -r $instance_dir.zip $instance_dir
+    popd
+done
\ No newline at end of file
diff --git a/scripts/dev/clean b/scripts/dev/clean
new file mode 100644
index 0000000000000000000000000000000000000000..87318d8f0db8611d55cb6466c95b2632789044c8
--- /dev/null
+++ b/scripts/dev/clean
@@ -0,0 +1,7 @@
+#!/bin/bash
+# Script for removing Judge0 development
+# environment (containers and volumes).
+#
+# Usage: ./scripts/dev/clean
+#
+docker-compose -f docker-compose.dev.yml down -v
diff --git a/scripts/dev/generate-docs b/scripts/dev/generate-docs
new file mode 100644
index 0000000000000000000000000000000000000000..b7adfbd8f80799a2cdf6c50fbe97703e0e2df6d7
--- /dev/null
+++ b/scripts/dev/generate-docs
@@ -0,0 +1,6 @@
+#!/bin/bash
+# Script for generating Judge0 documentation.
+#
+# Usage: ./scripts/dev/generate-docs
+#
+aglio --theme-full-width -i docs/api/docs.md -o public/docs.html
diff --git a/scripts/dev/serve-docs b/scripts/dev/serve-docs
new file mode 100644
index 0000000000000000000000000000000000000000..071d1ef40977c0baf8052fdbfbaef2b7a6913fd1
--- /dev/null
+++ b/scripts/dev/serve-docs
@@ -0,0 +1,7 @@
+#!/bin/bash
+# Script for serving Judge0 documentation.
+# Used in "development" mode when documentation is written.
+#
+# Usage: ./scripts/dev/serve-docs
+#
+aglio --theme-full-width -i docs/api/docs.md -s -h 0.0.0.0 -p 3001
diff --git a/scripts/dev/shell b/scripts/dev/shell
new file mode 100644
index 0000000000000000000000000000000000000000..95e2f3f4815ca78df08c49d4e4de3eee7f6573f0
--- /dev/null
+++ b/scripts/dev/shell
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Script for creating a new or using existing
+# Judge0 development environment and
+# opening new shell inside Judge0 container.
+#
+# Usage: ./scripts/dev/shell
+#
+docker-compose -f docker-compose.dev.yml up -d
+docker-compose -f docker-compose.dev.yml exec --privileged judge0 bash
diff --git a/scripts/load-config b/scripts/load-config
new file mode 100644
index 0000000000000000000000000000000000000000..e42cd3440845e479678a9b4ad922682790e730cf
--- /dev/null
+++ b/scripts/load-config
@@ -0,0 +1,51 @@
+#!/bin/bash
+if [[ -f /api/judge0.conf ]]; then
+    CONFIG_FILE=/api/judge0.conf
+elif [[ -f /judge0.conf ]]; then
+    CONFIG_FILE=/judge0.conf
+fi
+
+if [[ -v CONFIG_FILE ]]; then
+    set -o allexport
+
+    source $CONFIG_FILE # Source the configuration file.
+
+    set +o allexport
+fi
+
+# Now set defaults if needed...
+
+# Judge0
+export MAINTENANCE_MESSAGE=${MAINTENANCE_MESSAGE:-Judge0 is currently in maintenance.}
+export RESTART_MAX_TRIES=${RESTART_MAX_TRIES:-10}
+
+# Rails
+export RAILS_ENV=${RAILS_ENV:-production}
+export RAILS_MAX_THREADS=${RAILS_MAX_THREADS:-$(nproc)}
+export RAILS_SERVER_PROCESSES=${RAILS_SERVER_PROCESSES:-2}
+export SECRET_KEY_BASE=${SECRET_KEY_BASE:-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 128 | head -n 1)}
+export PORT=${PORT:-2358} # This option is not available in judge0.conf
+export RAILS_LOG_TO_STDOUT=true # This options is not available in judge0.conf
+
+# Authentication
+export AUTHN_HEADER=${AUTHN_HEADER:-X-Auth-Token}
+
+# Authorization
+export AUTHZ_HEADER=${AUTHZ_HEADER:-X-Auth-User}
+
+# Workers
+export INTERVAL=${INTERVAL:-0.1}
+export COUNT=${COUNT:-$(( $(nproc) * 2 ))}
+export QUEUE=${JUDGE0_VERSION:-unknown} # This option is not available in judge0.conf
+
+# Database
+export REDIS_HOST=${REDIS_HOST:-localhost}
+export REDIS_PORT=${REDIS_PORT:-6379}
+export POSTGRES_HOST=${POSTGRES_HOST:-localhost}
+export POSTGRES_PORT=${POSTGRES_PORT:-5432}
+export POSTGRES_DB=${POSTGRES_DB:-postgres}
+export POSTGRES_USER=${POSTGRES_USER:-postgres}
+
+# Other
+export RUBYOPT=-W:no-deprecated
+export DISABLE_DATABASE_ENVIRONMENT_CHECK=1
diff --git a/scripts/server b/scripts/server
new file mode 100644
index 0000000000000000000000000000000000000000..d6011f4ffedd360b99f2711270352b4c14d9df77
--- /dev/null
+++ b/scripts/server
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Script for running Judge0 server.
+#
+# Usage: ./scripts/server
+#
+source ./scripts/load-config
+export | sudo tee /api/environment
+
+for i in $(seq 1 $RESTART_MAX_TRIES); do
+    [[ -f tmp/pids/server.pid ]] && rm -f tmp/pids/server.pid
+
+    rails db:create db:migrate db:seed
+    rails s -b 0.0.0.0
+    [[ $? -eq 0 ]] && break
+    sleep 2s
+done
diff --git a/scripts/workers b/scripts/workers
new file mode 100644
index 0000000000000000000000000000000000000000..5419c5875af4c57c8acd886e44613297a5590078
--- /dev/null
+++ b/scripts/workers
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Script for running Judge0 workers.
+#
+# Usage: ./scripts/workers
+#
+source ./scripts/load-config
+export | sudo tee /api/environment
+
+run_resque=1
+resque_pid=0
+scheduler_pid=0
+
+date_now() {
+    echo -n $(date +"%Y-%m-%d-%H-%M-%S")
+}
+
+exit_gracefully() {
+    echo "[$(date_now)] Killing workers."
+    run_resque=0
+    kill -SIGQUIT $(pgrep -P $resque_pid)
+    kill -SIGTERM $resque_pid
+}
+
+trap exit_gracefully SIGTERM SIGINT
+
+mkdir -p tmp/pids &> /dev/null
+while [[ $run_resque -eq 1 ]]; do
+    echo "[$(date_now)] Starting scheduler."
+    if ! ps -p $scheduler_pid &> /dev/null; then
+        rake resque:scheduler &
+        scheduler_pid=$!
+    fi
+
+    rm -rf tmp/pids/resque.pid &> /dev/null
+    echo "[$(date_now)] Starting workers."
+    rails resque:workers &
+    resque_pid=$!
+    while ps -p $resque_pid > /dev/null; do sleep 1s; done
+    echo "[$(date_now)] Workers are stopped."
+done
diff --git a/spec/controllers/languages_controller_spec.rb b/spec/controllers/languages_controller_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..8d238e436680812078608140348c0c1b3c01cd76
--- /dev/null
+++ b/spec/controllers/languages_controller_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+RSpec.describe LanguagesController, type: :controller do
+  describe "GET #index" do
+    it "returns all languages" do
+      create_list(:language, 10)
+      get :index
+      json = JSON.parse(response.body)
+      expect(response).to be_success
+      expect(json).to have_serialized(Language.all).with(LanguageSerializer)
+    end
+  end
+end
diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..f34b84b9c681eedfe404abb63450f5d0f26a0a0b
--- /dev/null
+++ b/spec/controllers/statuses_controller_spec.rb
@@ -0,0 +1,12 @@
+require 'rails_helper'
+
+RSpec.describe StatusesController, type: :controller do
+  describe "GET #index" do
+    it "returns all statuses" do
+      get :index
+      json = JSON.parse(response.body)
+      expect(response).to be_success
+      expect(json).to have_serialized(Status.all).with(StatusSerializer)
+    end
+  end
+end
diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..0e00788c33d55b2222f3444de12705bd74075628
--- /dev/null
+++ b/spec/controllers/submissions_controller_spec.rb
@@ -0,0 +1,52 @@
+require 'rails_helper'
+
+RSpec.describe SubmissionsController, type: :controller do
+
+  let(:submission) { create(:submission) }
+
+  describe "GET #show" do
+    it "returns one submission" do
+      get :show, params: { token: submission.token }
+      json = JSON.parse(response.body)
+      expect(response).to be_success
+      expect(json).to have_serialized(submission).with(SubmissionSerializer)
+    end
+
+    it "returns 404" do
+      expect {
+        get :show, params: { token: submission.token + " give me 404" }
+      }.to raise_error(ActiveRecord::RecordNotFound)
+    end
+  end
+
+  describe "POST #create" do
+    context "with valid params" do
+      it "creates a new Submission" do
+        expect {
+          post :create, params: attributes_for(:valid_submission)
+        }.to change(Submission, :count).by(1)
+      end
+
+      it "returns only id of new Submission" do
+        post :create, params: attributes_for(:valid_submission)
+        json = JSON.parse(response.body)
+        expect(response).to be_success
+        expect(json).to have_serialized(Submission.first).with(SubmissionSerializer, { fields: [:token] })
+      end
+
+      it "doesn't create new Submission because given Language doesn't exist" do
+        attributes = attributes_for(:valid_submission)
+        attributes[:language_id] = 142 # Language with id 142 doesn't exist
+        post :create, params: attributes
+        expect(response).to have_http_status(422)
+      end
+    end
+
+    context "with invalid params" do
+      it "doesn't create new Submission" do
+        post :create, params: { submission: attributes_for(:invalid_submission) }
+        expect(response).to have_http_status(422)
+      end
+    end
+  end
+end
diff --git a/spec/factories/languages.rb b/spec/factories/languages.rb
new file mode 100644
index 0000000000000000000000000000000000000000..1d1b0cfb4bee8600c71775b1e0cf0b1e40716bf3
--- /dev/null
+++ b/spec/factories/languages.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+  factory :language do
+    sequence(:name) { |n| "C (gcc #{n})" }
+    run_cmd './a.out'
+    source_file 'main.c'
+  end
+end
diff --git a/spec/factories/submissions.rb b/spec/factories/submissions.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a857e4a0dfa7e5c83b8018f225486ff3d0c7edd1
--- /dev/null
+++ b/spec/factories/submissions.rb
@@ -0,0 +1,24 @@
+FactoryGirl.define do
+  factory :valid_submission, class: Submission do
+    sequence(:token) { |n| SecureRandom.uuid + "-#{n}" }
+    source_code 'name = gets.strip; puts "hello, " + name'
+    language_id { create(:language).id }
+    number_of_runs 1
+    stdin "world"
+    expected_output "hello, world"
+  end
+
+  factory :submission, parent: :valid_submission do
+    stdout "hello, world"
+    status_id 1
+    time 1.0
+    memory 256
+  end
+
+  factory :invalid_submission, class: Submission do
+    source_code 'name = gets.strip; puts "hello, " + name'
+    # language_id 14 # :language_id should be present
+    stdin "world"
+    expected_output "hello, world"
+  end
+end
diff --git a/spec/jobs/isolate_job_spec.rb b/spec/jobs/isolate_job_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..f6e48bd262e604dad88ca5fb0e8a72b6e27550c3
--- /dev/null
+++ b/spec/jobs/isolate_job_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+
+RSpec.describe IsolateJob, type: :job do
+end
diff --git a/spec/models/language_spec.rb b/spec/models/language_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..b246837fa083fa7388ec1d208433b6902676fc38
--- /dev/null
+++ b/spec/models/language_spec.rb
@@ -0,0 +1,7 @@
+require 'rails_helper'
+
+RSpec.describe Language, type: :model do
+  it { should validate_presence_of(:name) }
+  it { should validate_presence_of(:run_cmd) }
+  it { should validate_presence_of(:source_file) }
+end
diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..602b683da0f91fea1a20139c6d6e31d40a315aa7
--- /dev/null
+++ b/spec/models/submission_spec.rb
@@ -0,0 +1,26 @@
+require 'rails_helper'
+
+RSpec.describe Submission, type: :model do
+  it { should validate_presence_of(:source_code) }
+  it { should validate_presence_of(:language_id) }
+
+  describe "#language" do
+    let(:language) { create(:language) }
+
+    it "returns language" do
+      submission = create(:submission, { language_id: language.id })
+      expect(submission.language).to eq(language)
+    end
+  end
+
+  it "is invalid because Language with given id doesn't exist" do
+    submission = build(:submission, { language_id: Language.all.size + 1 })
+    expect(submission).not_to be_valid
+  end
+
+  it "is valid because Language with given id exists" do
+    language = create(:language)
+    submission = build(:submission, { language_id: language.id })
+    expect(submission).to be_valid
+  end
+end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
new file mode 100644
index 0000000000000000000000000000000000000000..4e0eec9c34573dda3dd529c5a0a61597f0638012
--- /dev/null
+++ b/spec/rails_helper.rb
@@ -0,0 +1,16 @@
+ENV['RAILS_ENV'] = 'test'
+require File.expand_path('../../config/environment', __FILE__)
+abort("The Rails environment is running in production mode!") if Rails.env.production?
+require 'spec_helper'
+require 'rspec/rails'
+require 'pry-byebug'
+
+Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
+
+ActiveRecord::Migration.maintain_test_schema!
+
+RSpec.configure do |config|
+  config.fixture_path = "#{::Rails.root}/spec/fixtures"
+  config.infer_spec_type_from_file_location!
+  config.filter_rails_from_backtrace!
+end
diff --git a/spec/requests/languages_spec.rb b/spec/requests/languages_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..42370bb72e9a706cd37ab4180851a6b8e7f1d23a
--- /dev/null
+++ b/spec/requests/languages_spec.rb
@@ -0,0 +1,10 @@
+require 'rails_helper'
+
+RSpec.describe "Languages", type: :request do
+  describe "GET /languages" do
+    it "has a 200 status code" do
+      get languages_path
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/requests/submissions_spec.rb b/spec/requests/submissions_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..232377b19822fa86d5c28f64960d8d7d30003243
--- /dev/null
+++ b/spec/requests/submissions_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+
+RSpec.describe "Submissions", type: :request do
+end
diff --git a/spec/routing/languages_routing_spec.rb b/spec/routing/languages_routing_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..3a5ef59d8e7abd2a84e49847351a3e4b10255e0e
--- /dev/null
+++ b/spec/routing/languages_routing_spec.rb
@@ -0,0 +1,9 @@
+require "rails_helper"
+
+RSpec.describe LanguagesController, type: :routing do
+  describe "routing" do
+    it "routes to #index" do
+      expect(get: "/languages").to route_to("languages#index")
+    end
+  end
+end
diff --git a/spec/routing/submissions_routing_spec.rb b/spec/routing/submissions_routing_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..9f458bdd38a4513eab69dd8f2d2dba45702f1164
--- /dev/null
+++ b/spec/routing/submissions_routing_spec.rb
@@ -0,0 +1,14 @@
+require "rails_helper"
+
+RSpec.describe SubmissionsController, type: :routing do
+  describe "routing" do
+    it "routes to #show" do
+      token = SecureRandom.uuid
+      expect(:get => "/submissions/#{token}").to route_to("submissions#show", token: token)
+    end
+
+    it "routes to #create" do
+      expect(:post => "/submissions").to route_to("submissions#create")
+    end
+  end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000000000000000000000000000000000000..68ee794321ee2fb9e7d73a44e7e06f9595421903
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,16 @@
+require 'codeclimate-test-reporter'
+
+CodeClimate::TestReporter.start
+CodeClimate::TestReporter.configuration.git_dir = ".."
+
+RSpec.configure do |config|
+  config.expect_with :rspec do |expectations|
+    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+  end
+
+  config.mock_with :rspec do |mocks|
+    mocks.verify_partial_doubles = true
+  end
+
+  config.shared_context_metadata_behavior = :apply_to_host_groups
+end
diff --git a/spec/support/active_model_serializer_matcher.rb b/spec/support/active_model_serializer_matcher.rb
new file mode 100644
index 0000000000000000000000000000000000000000..342d51a4f662266cdc0ccf5afb090270798754a0
--- /dev/null
+++ b/spec/support/active_model_serializer_matcher.rb
@@ -0,0 +1,56 @@
+RSpec::Matchers.define :have_serialized do |unserialized|
+  chain :with do |serializer, options = {}|
+    @serializer = serializer
+    @options = options
+  end
+
+  chain :wrap do |collection_serializer, options = {}|
+    @collection_serializer = collection_serializer
+  end
+
+  def serialize(object)
+    @collection_serializer ||= ActiveModel::Serializer::CollectionSerializer
+
+    if object.respond_to?(:map)
+      serializer = @collection_serializer.new(object, serializer: @serializer)
+    else
+      serializer = @serializer.new(object)
+    end
+
+    json = ActiveModelSerializers::Adapter::Attributes.new(serializer, @options).to_json
+    JSON.parse(json)
+  end
+
+  match do |serialized|
+    serialized == serialize(unserialized)
+  end
+
+  failure_message do |serialized|
+    <<-FAIL.strip_heredoc
+    expected:
+    #{serialized}
+    to match:
+    #{serialize(unserialized)}
+    ---
+    #{inspect}
+    FAIL
+  end
+
+  failure_message_when_negated do |serialized|
+    <<-FAIL.strip_heredoc
+    expected
+    #{serialized}
+    not to match:
+    #{serialize(unserialized)}
+    ---
+    #{inspect}
+    FAIL
+  end
+
+  def inspect
+    <<-INSPECT.strip_heredoc
+    Using object serializer: #{@serializer}
+    Using collection serializer: #{@collection_serializer}
+    INSPECT
+  end
+end
diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a63b7a0b4ca48b223f54e91b14c573c829edda50
--- /dev/null
+++ b/spec/support/database_cleaner.rb
@@ -0,0 +1,21 @@
+require 'database_cleaner'
+
+RSpec.configure do |config|
+  config.use_transactional_fixtures = false
+
+  config.before(:suite) do
+    DatabaseCleaner.clean_with(:truncation)
+  end
+
+  config.before(:each) do
+    DatabaseCleaner.strategy = :transaction
+  end
+
+  config.before(:each) do
+    DatabaseCleaner.start
+  end
+
+  config.after(:each) do
+    DatabaseCleaner.clean
+  end
+end
diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb
new file mode 100644
index 0000000000000000000000000000000000000000..196b203048edcfdc6173d8b7b57f05a7cc16cd9e
--- /dev/null
+++ b/spec/support/factory_girl.rb
@@ -0,0 +1,5 @@
+require 'factory_girl_rails'
+
+RSpec.configure do |config|
+  config.include FactoryGirl::Syntax::Methods
+end
diff --git a/spec/support/shoulda_matchers.rb b/spec/support/shoulda_matchers.rb
new file mode 100644
index 0000000000000000000000000000000000000000..0d42430f6213702d291e669bd4352c4e169acdcc
--- /dev/null
+++ b/spec/support/shoulda_matchers.rb
@@ -0,0 +1,8 @@
+require 'shoulda-matchers'
+
+Shoulda::Matchers.configure do |config|
+  config.integrate do |with|
+    with.test_framework :rspec
+    with.library :rails
+  end
+end
diff --git a/tmp/.keep b/tmp/.keep
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/vendor/.keep b/vendor/.keep
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391