# Production image of the code runner. It runs only on the dedicated runner # host or VM, never on the core application host; see docs/en/DEPLOYMENT.md. # # Base images are build arguments so that a release build can pin each one to # the digest it resolved; the defaults keep the agreed tags. ARG GO_IMAGE=golang:1.26.9-alpine ARG RUNTIME_IMAGE=python:alpine FROM ${GO_IMAGE} AS build # Never download another Go toolchain: a go.mod that asks for a newer Go # fails the build instead of silently replacing 1.26.9. ENV GOTOOLCHAIN=local WORKDIR /src/runner COPY go.mod go.sum ./ RUN go mod download COPY . ./ RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -trimpath -ldflags="-s -w" -o /out/lincodex-runner ./cmd/runner # The Go toolchain for candidate code: the compile and link tools and every # standard library package prebuilt without cgo, with an importcfg that maps # import paths to the archives. A build in the jail then needs no build # cache, no module download, and nothing writable outside its output. FROM ${GO_IMAGE} AS gostd ENV GOTOOLCHAIN=local ARG GO_TOOL_DIR=/usr/local/lib/lincodex-runner/go RUN set -eu; \ out=/out/go; \ mkdir -p "$out/std"; \ CGO_ENABLED=0 go list -trimpath -export -f '{{if .Export}}{{.ImportPath}} {{.Export}}{{end}}' std > /tmp/std.txt; \ while read -r package archive; do \ target="$out/std/$package.a"; \ mkdir -p "$(dirname "$target")"; \ cp "$archive" "$target"; \ printf 'packagefile %s=%s/std/%s.a\n' "$package" "$GO_TOOL_DIR" "$package" >> "$out/importcfg"; \ done < /tmp/std.txt; \ cp "$(go env GOTOOLDIR)/compile" "$(go env GOTOOLDIR)/link" "$out/" FROM ${RUNTIME_IMAGE} # The runtime is the Python base plus nsjail and the Go compile tools. # Package installers are removed, so a jailed program finds no pip, and # nothing is installed at run time. RUN apk upgrade --no-cache \ && apk add --no-cache nsjail \ && python -m pip uninstall --yes pip \ && python -c "import ensurepip, shutil; shutil.rmtree(ensurepip.__path__[0])" \ && install -d -m 0711 /var/lib/lincodex-runner/work COPY --from=gostd /out/go /usr/local/lib/lincodex-runner/go # The binary lives outside /usr and /lib, which are the only host paths # mounted into a jail. COPY --from=build /out/lincodex-runner /opt/lincodex-runner/lincodex-runner # The supervisor needs root on its dedicated host to create namespaces, map # the sandbox user, and write its delegated cgroup. Jailed programs run as # uid 99999 without capabilities, with no_new_privs and a seccomp policy. USER 0:0 EXPOSE 8443 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD ["/opt/lincodex-runner/lincodex-runner", "healthcheck"] ENTRYPOINT ["/opt/lincodex-runner/lincodex-runner"]