This project allows users to submit and execute code written in Python and C through pre-warmed Docker containers. A proxy server routes incoming requests to the appropriate backend container based on the specified programming language.
├── python-runner/ # Service to execute Python code
│ ├── app.py # Flask app to execute Python code
│ ├── Dockerfile # Dockerfile for Python runner
├── c-runner/ # Service to execute C code
│ ├── app.py # Flask app to compile and execute C code
│ ├── Dockerfile # Dockerfile for C runner
├── proxy-server/ # Proxy server to route requests
│ ├── app.py # Flask app acting as the proxy
│ ├── Dockerfile # Dockerfile for Proxy server
├── docker-compose.yml # Compose file to spin up all services
- Description: Executes Python code sent from the frontend.
- Endpoint:
POST /execute
- Port:
5001
(containerized) - Request Format (JSON):
{
"code": "for i in range(5): print(i)"
}
Response:
{
"output": "0\n1\n2\n3\n4\n",
"error": ""
}
- Description: Routes incoming requests to the appropriate runner container (Python or C) based on the language specified in the request.
- Endpoint:
POST /execute
- Port:
5000
(accessible from host) - Request Format (JSON):
{
"language": "python",
"code": "for i in range(5): print(i)"
}
- Response:
{
"output": "0\n1\n2\n3\n4\n",
"error": ""
}
-
Prerequisites
- Install Docker and Docker Compose on your machine.
-
Build and Run the Services
- Navigate to the project root directory.
- Run the following command to build and start all containers:
docker-compose up --build
-
Access the Proxy Server
- The proxy server will be accessible at:
http://localhost:8080/execute
- The proxy server will be accessible at:
-
Example Requests
- Use tools like Postman or
curl
to send POST requests to the proxy server.
Python Code Example:
curl -X POST http://localhost:8080/execute \ -H "Content-Type: application/json" \ -d '{ "language": "python", "code": "for i in range(5): print(i)" }'
C Code Example:
curl -X POST http://localhost:8080/execute \ -H "Content-Type: application/json" \ -d '{ "language": "c", "code": "#include <stdio.h>\nint main() {\n printf(\"Hello, World!\\n\");\n return 0;\n}" }'
- Use tools like Postman or
- Ensure that ports 5000, 5001, and 5002 are free on your host machine.
- The proxy server is the single entry point for code execution.
To stop and remove the containers, run:
docker-compose down
- Add support for additional programming languages.
- Implement authentication to restrict access.
- Use Kubernetes for container orchestration in production.