File size: 2,235 Bytes
5fed0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# syntax=docker/dockerfile:1

# Use official Ubuntu 22.04 as base image
FROM ubuntu:22.04

# Set environment variable to avoid interactive prompts during apt-get installation
ENV DEBIAN_FRONTEND=noninteractive

# --- 1. Install base dependencies, language toolchains and Node.js ---
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    curl \
    jq \
    git \
    unzip \
    zip \
    build-essential \
    pkg-config \
    python3 \
    python3-pip \
    pypy3 \
    openjdk-17-jdk \
    kotlin \
    rustc \
    cargo \
    golang \
    # Install Node.js 20.x
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    # Clean apt cache
    && rm -rf /var/lib/apt/lists/*

# --- 2. Update npm to latest version ---
RUN npm install -g npm@latest

# --- 3. Install go-judge (auto-detect architecture) ---
RUN set -eux; \
  arch="$(uname -m)"; \
  case "$arch" in \
    x86_64)  goarch="amd64" ;; \
    aarch64) goarch="arm64" ;; \
    *) echo "Unsupported arch: $arch" && exit 1 ;; \
  esac; \
  url=$(curl -fsSL https://api.github.com/repos/criyle/go-judge/releases/latest \
    | jq -r --arg goarch "$goarch" '.assets[] | select(.name | test("linux.*\($goarch).*tar.gz$")) | .browser_download_url' \
    | head -n 1); \
  echo "Downloading go-judge for $arch ($url)"; \
  curl -fsSL "$url" | tar -xz -C /usr/local/bin go-judge; \
  chmod +x /usr/local/bin/go-judge

# --- 4. Set application working directory and install Node.js dependencies ---
WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm install --omit=dev --ignore-scripts

# --- 5. Copy application code and entry script ---
COPY server.js entrypoint.sh ./
COPY judge/src/ ./src/
COPY judge/include/ ./include/
COPY judge/config/ ./config/
COPY judge/include/ /lib/testlib/

# Ensure entrypoint.sh is executable and fix possible Windows line ending issues
RUN chmod +x entrypoint.sh && sed -i 's/\r$//' entrypoint.sh

# --- 6. Set default environment variables ---
ENV PORT=8081 \
    GJ_ADDR=http://127.0.0.1:5050 \
    JUDGE_WORKERS=$(nproc) \
    GJ_PARALLELISM=$(nproc)

# --- 7. Set container entry point ---
ENTRYPOINT ["/app/entrypoint.sh"]