Monday, March 17, 2025

How to Install Judge0 - A Self-hosted Code Execution System

Judge0, pronounced "judge zero," is a robust and versatile open-source platform designed for online code execution. Its architecture is built for scalability and ease of deployment, making it a valuable tool for a wide spectrum of applications. From powering competitive programming websites and enhancing e-learning platforms to streamlining candidate assessments in recruitment processes, Judge0 provides a reliable and efficient solution for any system requiring the execution of submitted code. This article will delve into the capabilities of Judge0, its architectural design, and explore the practicalities of setting it up using Docker and Docker Compose.

The system's modular design allows for easy expansion and customization. This adaptability is crucial in addressing the diverse needs of various applications. For example, an online code editor could leverage Judge0's core functionality to provide real-time feedback to users, while a recruitment platform might employ it to automatically assess candidate code submissions, providing standardized and objective evaluation criteria. The flexibility of Judge0 allows developers to integrate code execution seamlessly into existing projects or to build entirely new systems around its powerful capabilities.

Our research, detailed in "Robust and Scalable Online Code Execution System," provides a comprehensive analysis of Judge0’s architecture and the challenges encountered during its development. This research also includes a comparative study of Judge0 against existing online code execution and online judge systems, highlighting its unique strengths and contributions to the field. The findings demonstrate the platform's significant advantages in terms of performance, scalability, and ease of integration.

Beyond its core capabilities, Judge0 offers a user-friendly online code editor, Judge0 IDE, which serves as a practical demonstration of the system's capabilities. This open-source editor provides a streamlined environment for writing, testing, and executing code, further highlighting the platform's versatility and accessibility.

Judge0 comes in two variants: Judge0 CE and Judge0 Extra CE. While both offer a powerful code execution engine, the key difference lies in the breadth of programming languages supported. Judge0 CE provides a solid foundation, supporting a comprehensive range of popular languages, while Judge0 Extra CE extends this support to include less common, more specialized, and newer languages.

Judge0 CE Supported Languages:

The following languages are supported by Judge0 CE. The version numbers indicate the specific compiler or interpreter used for each language:

  1. Assembly (NASM 2.14.02)

  2. Bash (5.0.0)

  3. Basic (FBC 1.07.1)

  4. C (Clang 7.0.1)

  5. C (GCC 7.4.0)

  6. C (GCC 8.3.0)

  7. C (GCC 9.2.0)

  8. C# (Mono 6.6.0.161)

  9. C++ (Clang 7.0.1)

  10. C++ (GCC 7.4.0)

  11. C++ (GCC 8.3.0)

  12. C++ (GCC 9.2.0)

  13. Clojure (1.10.1)

  14. COBOL (GnuCOBOL 2.2)

  15. Common Lisp (SBCL 2.0.0)

  16. D (DMD 2.089.1)

  17. Elixir (1.9.4)

  18. Erlang (OTP 22.2)

  19. Executable (allowing for execution of pre-compiled binaries)

  20. F# (.NET Core SDK 3.1.202)

  21. Fortran (GFortran 9.2.0)

  22. Go (1.13.5)

  23. Groovy (3.0.3)

  24. Haskell (GHC 8.8.1)

  25. Java (OpenJDK 13.0.1)

  26. JavaScript (Node.js 12.14.0)

  27. Kotlin (1.3.70)

  28. Lua (5.3.5)

  29. Objective-C (Clang 7.0.1)

  30. OCaml (4.09.0)

  31. Octave (5.1.0)

  32. Pascal (FPC 3.0.4)

  33. Perl (5.28.1)

  34. PHP (7.4.1)

  35. Plain Text (for simple text analysis)

  36. Prolog (GNU Prolog 1.4.5)

  37. Python (2.7.17)

  38. Python (3.8.1)

  39. R (4.0.0)

  40. Ruby (2.7.0)

  41. Rust (1.40.0)

  42. Scala (2.13.2)

  43. SQL (SQLite 3.27.2)

  44. Swift (5.2.3)

  45. TypeScript (3.7.4)

  46. Visual Basic.Net (vbnc 0.0.0.5943)

Judge0 Extra CE Supported Languages:

Judge0 Extra CE expands upon the language support of Judge0 CE, adding several specialized and newer languages:

  1. Bosque (latest version)

  2. C (Clang 10.0.1)

  3. C (Clang 9.0.1)

  4. C# (.NET Core SDK 3.1.302)

  5. C# (Mono 6.10.0.104)

  6. C# Test (.NET Core SDK 3.1.302, NUnit 3.12.0) – Includes unit testing framework

  7. C++ (Clang 10.0.1)

  8. C++ (Clang 9.0.1)

  9. C++ Test (Clang 10.0.1, Google Test 1.8.1) – Includes unit testing framework

  10. C++ Test (GCC 8.4.0, Google Test 1.8.1) – Includes unit testing framework

  11. C3 (latest version)

  12. F# (.NET Core SDK 3.1.302)

  13. Java (OpenJDK 14.0.1)

  14. Java Test (OpenJDK 14.0.1, JUnit Platform Console Standalone 1.6.2) – Includes unit testing framework

  15. MPI (OpenRTE 3.1.3) with C (GCC 8.4.0) – Message Passing Interface support

  16. MPI (OpenRTE 3.1.3) with C++ (GCC 8.4.0) – Message Passing Interface support

  17. MPI (OpenRTE 3.1.3) with Python (3.7.7) – Message Passing Interface support

  18. Nim (stable version)

  19. Python for ML (3.7.7) – Optimized for machine learning tasks

  20. Visual Basic.Net (vbnc 0.0.0.5943)

Installing Judge0 with Docker and Docker Compose

For efficient deployment and management, Judge0 is ideally suited for containerization using Docker and Docker Compose. This approach streamlines the setup process and simplifies scaling. Below is an example of how to set up a Judge0 instance using these technologies. Remember to adjust paths and configurations to suit your specific environment.

First, ensure Docker and Docker Compose are installed on your system. Then, create a docker-compose.yml file with the following configuration:

version: "3.9"
services:
  db:  # Define the PostgreSQL service
    image: postgres:14 # Use a specific PostgreSQL version for consistency and security updates. Consider using a tag with a Long Term Support (LTS) release.
    restart: always # Ensure the database restarts automatically if it crashes
    environment:
      - POSTGRES_USER=judge0user # Create a dedicated user for Judge0
      - POSTGRES_PASSWORD=judge0password # Strong password, consider using a secure password manager
      - POSTGRES_DB=judge0db  # Create a dedicated database for Judge0
    volumes:
      - db_data:/var/lib/postgresql/data # Persist database data across container restarts. Crucial for data retention.
    ports:
      - "5432:5432" # Expose the database port for local access during development, consider disabling this in production for security.

  judge0:
    image: judge0/judge0
    ports:
      - "8080:8080" # Map port 8080 on your host to Judge0's internal port. Consider using a non-standard port for production environments.
    volumes:
      - ./judge0-config:/app/config # Mount a configuration directory, ensures easy modification of settings without rebuilding the image.
    depends_on:  # Ensure PostgreSQL is running before Judge0 starts. This prevents connection errors during startup.
      - db
    environment:
      - DATABASE_URL=postgresql://judge0user:judge0password@db:5432/judge0db # Updated connection string to match the PostgreSQL service configuration.  Using environment variables adds an extra layer of security.
      - JUDGE0_API_KEY=your_api_key  # Set a strong API key;  Generate a unique key for each deployment.
      # Add other environment variables as needed, consult Judge0 documentation for extensive customization options.

volumes:
  db_data: # Define a named volume for persistent data storage. This is critical for data preservation.
    

This configuration defines a service named judge0 that uses the official Judge0 Docker image. It maps port 8080 of your host machine to the internal port of the Judge0 container. Critically, it mounts a local directory (./judge0-config) to /app/config within the container. This allows for easy configuration management and customization without altering the container's image. The environment section sets essential environment variables, including the database connection string and a security API key. Remember to replace placeholders like user, password, db, and your_api_key with your actual credentials. You'll need a PostgreSQL database running, either locally or remotely.

Next, create the ./judge0-config directory and populate it with your configuration files. Refer to the official Judge0 documentation for details on configuration file structure and options. These files provide fine-grained control over various aspects of Judge0's behavior, such as resource limits, supported languages, and error handling.

Finally, execute the following command to start Judge0:

      docker-compose up -d
    

The -d flag runs the container in detached mode, allowing it to run in the background. You can then access the Judge0 API at http://localhost:8080. Remember to consult the official Judge0 documentation for details on the API endpoints and usage. This setup provides a robust and scalable solution for deploying and managing Judge0, taking advantage of Docker's containerization capabilities. The modular approach facilitates easy updates and scaling to meet increasing demands.

Judge0 offers a powerful and flexible solution for integrating online code execution into various applications. Its open-source nature, coupled with its robust architecture and extensive language support, makes it a valuable asset for developers across numerous domains. The ease of deployment using Docker and Docker Compose further enhances its accessibility and practicality.

0 comments:

Post a Comment