JudgeLib

Self-Host JudgeLib

Deploy JudgeLib on your own infrastructure with Docker and Kubernetes for maximum control, reliability, and performance.

Why Self-Host?

Full Control

  • Deploy on any cloud provider
  • Customize resource limits
  • Configure security policies

Better Performance

  • No free tier limitations
  • Horizontal auto-scaling
  • Dedicated resources

Choose Your Learning Path

Select how you want to get started with JudgeLib self-hosting

Architecture Overview

Workflow overview and architecture

Read Documentation

Detailed step-by-step written guide

Sample Code

Ready-to-use code examples and snippets

Want to jump right in?

Architecture Overview

Understand the self-hosting architecture and deployment process.

JudgeLib Self-Hosting Architecture

Install NPM Package

Install lib-judge in your application

Deploy Worker

Run the worker container with Redis

Scale with K8s

Auto-scale with Kubernetes

Prerequisite Requirements

1

Chocolatey Package Manager

Chocolatey is a package manager for Windows that simplifies the installation of software and dependencies. It is required for managing packages in your self-hosted environment.

Note: Follow the official Chocolatey installation guide to ensure proper setup. You may need administrator privileges to install Chocolatey on your system.

2

Install Kubernetes CLI (kubectl)

The Kubernetes CLI (kubectl) is required to interact with your Kubernetes cluster. You can install it using Chocolatey after the package manager is set up.

choco install kubernetes-cli

Tip: After installation, verify by running kubectl version --client in your terminal.

3

Install Kind (Kubernetes IN Docker)

Kind is a tool for running local Kubernetes clusters using Docker containers as nodes. It's especially useful for testing and development environments.

choco install kind

Tip: After installation, verify Kind is installed by running kind version in your terminal.

4

Setup Helm

Helm is a package manager for Kubernetes that helps you define, install, and upgrade Kubernetes applications. Use it to deploy monitoring and other services to your cluster.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace

Tip: Helm makes it easy to manage complex Kubernetes deployments with pre-configured charts.

5

Port Forward to Redis (OPTIONAL)

Port forwarding allows you to access Redis running inside your Kubernetes cluster from your local machine. This is useful for development and debugging purposes.

kubectl port-forward -n judge-namespace redis-0 6379:6379

Tip: This command forwards port 6379 from your Redis pod to your local machine.

Get Started

1

Install NPM Package

First, install the lib-judge package in your Node.js application:

# Install the package
npm install lib-judge
2

Environment Configuration

Create a .env file and add the Redis configuration variables:

# .env file
password_redis=your_redis_password
host_redis=redis-service.judge-namespace.svc.cluster.local
redis_port=6379
3

Deploy Worker Container (OPTIONAL)

Pull the worker image and run it with your Redis configuration:

# Pull the worker image
docker pull lightningsagar/worker:210b8cfd943b24e7381c4c8f1f3114c2d1fd3d81
4

Setup Kubernetes Operations

Clone the operations repository that contains Kubernetes configurations with horizontal pod autoscaling:

# Clone the ops repository
git clone https://github.com/lightning-sagar/worker-ops

Customizable: You can modify the code in the ops repository to suit your specific deployment requirements and infrastructure needs.

Deploy to Kubernetes

Apply Kubernetes Configurations

Deploy your JudgeLib worker with horizontal pod autoscaling enabled

Create Cluster:

# Creating Cluster
kind create cluster --config .\cluster.yml -n workers-clusters

Create namespace:

# Creating namespace
kubectl create namespace judge-namespace

Apply the deployment configuration:

# Deploy the application
kubectl apply -f judge-workers

Auto-scaling Benefits

The HPA configuration automatically scales your worker pods based on CPU usage and request load, ensuring optimal performance and cost efficiency.

Using lib-judge in Your Code

Sample Implementation

Here's how to use the lib-judge package in your Node.js application

# Sample usage
const result = await judge({
  codePath: tmpPath,
  ques_name: `question_${Date.now()}`,
  input,
  output,
  timeout: timeout, // in seconds
  sizeout: sizeout,
  language: langCode, // py, cpp, java
});

// or checkout the full code example here https://github.com/lightning-sagar/Judge/

Parameters:

codePath

Path to the code file to execute

ques_name

Unique identifier for the question/execution

input

Input data for the code execution

output

Expected output for validation

timeout

Execution timeout in seconds

sizeout

Memory limit for execution

language

Programming language (py, cpp, java)