为 Code Runner 新增 Go 和 Rust 两种编译型语言,沿用现有 base 镜像分层结构。 Go: - run_cmd 直接用 go run(单条命令,内部编译+运行) - 镜像把 GOCACHE/GOTMPDIR/GOPATH 重定向到 /tmp tmpfs (只读根文件系统下 /Users/issuser/.cache 不可写) - default_limits: 1 核 / 256MB / 10s(编译冷启动比解释型慢) Rust: - rustc 编译 + 运行是两步,但 docker.rs 注入脚本用 exec 执行 run_cmd, exec 替换 shell 进程后 'A && B' 后半段不执行, 因此镜像内置 /usr/local/bin/run-rust.sh wrapper 封装两步 - default_limits: 1 核 / 512MB / 15s(rustc 内存大、编译慢) 新增镜像与白名单后,默认 CODE_RUNNER_LANGUAGES=python,node,go,rust。
22 lines
711 B
Docker
22 lines
711 B
Docker
# Go 运行沙箱镜像。
|
||
# 与 src/api/code_runner/languages.rs 的 go 注册项对齐:
|
||
# image: yggdrasil-runner-go:latest
|
||
# run_cmd: go run /code/main.go
|
||
#
|
||
# go run 是单条命令(内部编译 + 运行),可直接作为 run_cmd(无需 wrapper)。
|
||
# 注意:运行时只读根文件系统 + tmpfs /code /tmp,$HOME/.cache 不可写,
|
||
# 必须把 GOCACHE / GOTMPDIR / GOPATH 重定向到可写的 /tmp tmpfs。
|
||
FROM yggdrasil-runner-base:latest
|
||
|
||
RUN apk add --no-cache go \
|
||
&& mkdir -p /tmp/go-cache /tmp/gopath \
|
||
&& chown -R runner:runner /tmp/go-cache /tmp/gopath
|
||
|
||
ENV GOCACHE=/tmp/go-cache \
|
||
GOTMPDIR=/tmp \
|
||
GOPATH=/tmp/gopath
|
||
|
||
COPY runner.toml /runner.toml
|
||
|
||
USER runner
|