This guide shows how to deploy the ByteCode Compiler on Azure VM with a REST API backend.
┌──────────────────┐ ┌──────────────────────┐
│ Frontend │ │ Azure VM │
│ (Vercel) │ ─HTTP──>│ ┌────────────┐ │
│ - Code Editor │ │ │ Node.js │ │
│ - Submit Code │ │ │ Express │ │
│ - Show Output │ │ │ API │ │
└──────────────────┘ │ └─────┬──────┘ │
│ │ │
│ ┌─────▼──────┐ │
│ │ Compiler │ │
│ │ Binary │ │
│ └────────────┘ │
└──────────────────────┘
- Go to Azure Portal
- Create a new Virtual Machine:
- OS: Ubuntu 22.04 LTS
- Size: Standard B2s (2 vCPUs, 4 GB RAM) or higher
- Authentication: SSH public key
- Add inbound port rules:
- Port 22 (SSH)
- Port 80 (HTTP)
- Port 443 (HTTPS)
- Port 3000 (API - temporary, will use NGINX)
ssh azureuser@<your-vm-ip># Update system
sudo apt update && sudo apt upgrade -y
# Install build tools
sudo apt install -y build-essential cmake git
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Install NGINX
sudo apt install -y nginx
# Install certbot for SSL
sudo apt install -y certbot python3-certbot-nginx# Clone your repository
cd ~
git clone https://github.com/IsVohi/ByteCode-Compiler.git
cd ByteCode-Compiler
# Build the compiler
mkdir build && cd build
cmake ..
make
# Verify it works
./compilercd ~/ByteCode-Compiler
npm init -y
npm install express cors body-parserThe backend API is in the server/ folder. It provides:
POST /api/compile- Compile and run codePOST /api/repl- Interactive REPL sessionGET /api/health- Health check
sudo nano /etc/systemd/system/compiler-api.serviceAdd:
[Unit]
Description=ByteCode Compiler API
After=network.target
[Service]
Type=simple
User=azureuser
WorkingDirectory=/home/azureuser/ByteCode-Compiler/server
ExecStart=/usr/bin/node api.js
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl daemon-reload
sudo systemctl enable compiler-api
sudo systemctl start compiler-api
sudo systemctl status compiler-apisudo nano /etc/nginx/sites-available/compilerAdd:
server {
listen 80;
server_name your-domain.com; # Replace with your domain or IP
location /api {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}Enable site:
sudo ln -s /etc/nginx/sites-available/compiler /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxsudo certbot --nginx -d your-domain.com# Test health endpoint
curl http://your-vm-ip/api/health
# Test compilation
curl -X POST http://your-vm-ip/api/compile \
-H "Content-Type: application/json" \
-d '{"code": "let x = 10; print(x * 2);"}'From your Vercel frontend, call the API:
const API_URL = 'https://your-domain.com/api';
async function compileCode(code) {
const response = await fetch(`${API_URL}/compile`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code })
});
return await response.json();
}- Rate Limiting: Add rate limiting to prevent abuse
- Timeout: Set execution timeouts (default: 5 seconds)
- Resource Limits: Limit memory and CPU usage
- Input Validation: Sanitize input code
- Firewall: Configure Azure NSG properly
- SSL: Always use HTTPS in production
# View API logs
sudo journalctl -u compiler-api -f
# View NGINX logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
# Monitor system resources
htopcd ~/ByteCode-Compiler
git pull origin main
cd build
cmake ..
make
sudo systemctl restart compiler-apisudo systemctl status compiler-api
sudo journalctl -u compiler-api -n 50cd ~/ByteCode-Compiler/build
cmake ..
make clean && makesudo lsof -i :3000
sudo kill -9 <PID>- Azure VM B2s: ~$30-40/month
- Domain: ~$10-15/year
- SSL: Free (Let's Encrypt)
Total: ~$30-40/month
Next Steps:
- Follow this guide to deploy on Azure
- Create frontend (see
frontend/folder) - Deploy frontend on Vercel
- Connect frontend to Azure backend