File size: 1,642 Bytes
092e3d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87e1426
092e3d5
 
 
 
fd95cd8
092e3d5
87e1426
ebb5c56
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# ============================================================================
# Online Exam IDE — Backend Dockerfile
# ============================================================================
# Multi-language code execution: Python, Node.js, Java (JDK), C++ (g++)
# ============================================================================

FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install system dependencies for multi-language code execution
RUN apt-get update && apt-get install -y --no-install-recommends \
    # Node.js for JavaScript execution
    nodejs \
    npm \
    # C++ compiler
    g++ \
    # Java JDK for Java execution
    default-jdk \
    # DNS utils (needed for MongoDB Atlas SRV records)
    dnsutils \
    # Cleanup
    && rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Copy requirements and install Python dependencies
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy backend source code
COPY backend/ .

# Expose port
# Expose port (informative, Railway ignores this and uses PORT env var)
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import urllib.request, os; port=os.environ.get('PORT', '8000'); urllib.request.urlopen(f'http://127.0.0.1:{port}/health')" || exit 1

# Run the application using the dynamic PORT provided by the platform (e.g. Railway)
# Use :: to listen on all interfaces (IPv4 + IPv6) — Railway routes via IPv6 internally
CMD sh -c "uvicorn main:app --host :: --port ${PORT:-8000}"