Repository navigation
feat(dockerfiles): add minimal Dockerfile.nemo-gym - #1444
Conversation
Adds a minimal NeMo Gym runtime container for running ng_run / ng_collect_rollouts against a pre-hosted or separately-launched policy server. No torch, vLLM, Megatron, or CUDA in this image — the policy LLM is reached over HTTP; this container only holds Gym orchestration and FastAPI resource/agent servers. - BASE_IMAGE defaults to python:3.12-slim-bookworm - GYM_COMMIT pinned to NVIDIA-NeMo/Gym@90770c32 (current main) and pulled hermetically via ADD from GitHub - uv installed to /usr/local/bin so it survives SLURM/pyxis PATH resets - Venv pre-created at /opt/NeMo-Gym/.venv with --copies so it doesn't depend on a uv-managed interpreter path that can vanish during image flattening - Sanity check confirms nemo_gym import and ng_run / ng_collect_rollouts are on PATH inside the baked venv Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
Adds a dedicated workflow that builds dockerfiles/Dockerfile.nemo-gym on PRs that modify the dockerfile (or the workflow itself), with registry-cache push/pull to GHCR so subsequent builds reuse layers. Path-filtered rather than added to tests.yml because the nemo-gym image is not used by pytest — gating every PR on this build would be wasted CI time. Matches the policy used for the other non-test dockerfiles (nemo-rl, vllm, verl, megatron) which are also not built per-PR. Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
This reverts commit 0d2a4ef. Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
📝 WalkthroughWalkthroughAdds a new Dockerfile for a minimal NeMo-Gym runtime (pinned source, Python 3.12 venv, uv-managed deps, sanity checks) and registers the ChangesNeMo-Gym Docker Runtime Setup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dockerfiles/Dockerfile.nemo-gym`:
- Around line 56-79: The final image stage runs as root; create a non-root user
and switch to it before finishing the "gym" stage: add a dedicated user/group
(e.g., nemo or nemo_gym_user) and a home directory, chown the app dir
(/opt/NeMo-Gym) and the baked venv (.venv) to that user, and set USER to that
account (and optionally set HOME and PATH) so subsequent containers run
non-root; update any RUNs that rely on root-only paths to use the new user
ownership (refer to the "gym" stage, the .venv, NEMO_GYM_PATH, and the uv/venv
setup commands when adjusting ownership).
- Line 53: The Dockerfile currently pipes the remote installer directly into sh
using the RUN curl ... | sh pattern for the UV installer (UV_VERSION, installer
URL https://astral.sh/uv/${UV_VERSION}/install.sh and target dir
/usr/local/bin); change this to first download the installer and its published
checksum (or a signed artifact) into the image, verify the checksum/signature
against a trusted value, and only then execute the installer; implement this by
replacing the pipe with a sequence that curl -fSLo the install.sh and checksum
file, validate the checksum for install.sh, and then run install.sh with
UV_INSTALL_DIR=/usr/local/bin, failing the build if verification fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a9086948-caad-4f88-b08c-b28a6aa8e771
📒 Files selected for processing (2)
.github/workflows/dockerfile_nemo_gym.ymldockerfiles/Dockerfile.nemo-gym
| # Install uv into /usr/local/bin so it's on the default PATH even when SLURM/pyxis | ||
| # strips the image's ENV PATH (pyxis resets PATH to the host's default and the | ||
| # image's ENV PATH is dropped, which can make `uv` unfindable inside the job). | ||
| RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find and examine the Dockerfile
find . -name "Dockerfile.nemo-gym" -type f 2>/dev/nullRepository: NVIDIA-NeMo/Skills
Length of output: 96
🏁 Script executed:
# Check file size and examine the relevant section
if [ -f "dockerfiles/Dockerfile.nemo-gym" ]; then
wc -l "dockerfiles/Dockerfile.nemo-gym"
echo "=== Lines 45-60 ==="
sed -n '45,60p' "dockerfiles/Dockerfile.nemo-gym"
echo "=== Full file ==="
cat -n "dockerfiles/Dockerfile.nemo-gym"
fiRepository: NVIDIA-NeMo/Skills
Length of output: 4308
🏁 Script executed:
# Search for USER directive in the Dockerfile
if [ -f "dockerfiles/Dockerfile.nemo-gym" ]; then
grep -n "USER" "dockerfiles/Dockerfile.nemo-gym" || echo "No USER directive found"
fiRepository: NVIDIA-NeMo/Skills
Length of output: 86
🌐 Web query:
uv installer checksum verification astral.sh
💡 Result:
Answer (2026-05-12): For uv’s standalone shell installer, checksum verification is done in the generated installer script itself (it verifies the downloaded uv tarball against embedded sha256 values). Historically there was a period where the installer printed “no checksums to verify”, but issue/PR activity indicates this was addressed for the.sh installers (with Windows PowerShell still noted as missing at the time). [1][2] What “uv installer checksum verification” means in practice 1) The default install path the docs promote is running the installer script from https://astral.sh/uv/install.sh via curl|sh. [3] 2) In older installer behavior, the script could download uv but not verify checksums (“no checksums to verify”). That was reported as a security-gap; the investigation noted the installer script logic existed but lacked checksum values. [1] 3) Later, uv’s project indicates the.sh installers embed and check tarball checksums starting with version 0.11.0; Windows (.ps1) was still missing in that timeframe. [1] 4) There is also related work explicitly targeting “Enable checksum verification in the generated installer script” by embedding checksums into the installer scripts. [2] Current/implementation details you can use to validate manually - The installer is a script; for the.sh installer it includes checksum values and should output/perform verification when downloading the tarball (the earlier example output shows downloading a matching.sha256 and then “verifying checksum sha256 … for … input.tar.gz”). [1] If you want to do defense-in-depth yourself, you can: - Inspect the installer before executing (the docs mention you can pipe to less, which is useful to confirm checksum-related code/embedded values are present). [3] - Prefer a pinned version URL (the docs show version-specific install.sh URLs). [3]
Citations:
- 1: Verify checksum in installer script astral-sh/uv#13074
- 2: Enable checksum verification in the generated installer script astral-sh/uv#18625
- 3: https://docs.astral.sh/uv/getting-started/installation/
🌐 Web query:
uv package manager installation security signature verification
💡 Result:
The uv package manager (from Astral) installation via the recommended standalone installer (curl -LsSf https://astral.sh/uv/install.sh | sh) downloads a prebuilt binary tarball and verifies its checksum. Since uv version 0.11.0, the.sh installers embed and automatically check the tarball's checksums before installation [1][2]. The Windows.ps1 installer was still missing this at the time of the discussion, but recent releases provide GitHub Artifact Attestations for downloaded binaries, verifiable via gh attestation verify [3]. Official docs suggest inspecting the script before piping to sh for added caution [4][5]. For Python packages installed using uv (e.g., uv pip install, uv add), uv follows standard Python packaging security: it verifies wheel file hashes from the lockfile (uv.lock) against downloads from PyPI or configured indexes, preventing tampering [6]. There is no additional cryptographic signature verification on PyPI packages themselves, as PyPI does not provide signed packages—security relies on HTTPS transport, hash verification from metadata, and lockfiles [7]. uv supports PEP 700 upload-time for exclude-newer to block recently published (potentially malicious) packages [7][8]. uv also has a preview uv audit command to scan locked dependencies for known vulnerabilities from the Python Packaging Advisory Database [9]. For publishing packages with uv publish, it supports uploading attestations (e.g., SLSA Provenance) if present, but does not generate them [10]. No cryptographic signatures on the uv tool binary itself beyond checksums and attestations.
Citations:
- 1: Verify checksum in installer script astral-sh/uv#13074
- 2: Enable checksum verification in the generated installer script astral-sh/uv#18625
- 3: https://newreleases.io/project/github/astral-sh/uv/release/0.11.2
- 4: https://docs.astral.sh/uv/getting-started/installation/
- 5: https://docs.astral.sh/uv/reference/installer/
- 6: https://github.com/astral-sh/uv/security
- 7: https://pydevtools.com/handbook/how-to/how-to-protect-against-python-supply-chain-attacks-with-uv/
- 8: https://docs.astral.sh/uv/reference/cli/
- 9:
uv auditCommand for Security Vulnerability Scanning astral-sh/uv#9189 - 10: https://docs.astral.sh/uv/guides/package/
Avoid piping a remote installer script straight to sh.
This is a supply-chain gap: the build executes network content without an integrity check. The uv installer for version 0.9.30 does not include built-in checksum verification. Download, verify checksum, then execute.
Suggested hardening
ARG UV_VERSION=0.9.30 # Gym's pyproject.toml sets [tool.uv] required-version = ">=0.9.30"
+ARG UV_INSTALLER_SHA256=<publish-and-pin-this>
# Install uv into /usr/local/bin so it's on the default PATH even when SLURM/pyxis
# strips the image's ENV PATH (pyxis resets PATH to the host's default and the
# image's ENV PATH is dropped, which can make `uv` unfindable inside the job).
-RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh
+RUN curl -fLsS "https://astral.sh/uv/${UV_VERSION}/install.sh" -o /tmp/uv-install.sh \
+ && echo "${UV_INSTALLER_SHA256} /tmp/uv-install.sh" | sha256sum -c - \
+ && env UV_INSTALL_DIR=/usr/local/bin sh /tmp/uv-install.sh \
+ && rm -f /tmp/uv-install.sh📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh | |
| ARG UV_VERSION=0.9.30 # Gym's pyproject.toml sets [tool.uv] required-version = ">=0.9.30" | |
| ARG UV_INSTALLER_SHA256=<publish-and-pin-this> | |
| # Install uv into /usr/local/bin so it's on the default PATH even when SLURM/pyxis | |
| # strips the image's ENV PATH (pyxis resets PATH to the host's default and the | |
| # image's ENV PATH is dropped, which can make `uv` unfindable inside the job). | |
| RUN curl -fLsS "https://astral.sh/uv/${UV_VERSION}/install.sh" -o /tmp/uv-install.sh \ | |
| && echo "${UV_INSTALLER_SHA256} /tmp/uv-install.sh" | sha256sum -c - \ | |
| && env UV_INSTALL_DIR=/usr/local/bin sh /tmp/uv-install.sh \ | |
| && rm -f /tmp/uv-install.sh |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@dockerfiles/Dockerfile.nemo-gym` at line 53, The Dockerfile currently pipes
the remote installer directly into sh using the RUN curl ... | sh pattern for
the UV installer (UV_VERSION, installer URL
https://astral.sh/uv/${UV_VERSION}/install.sh and target dir /usr/local/bin);
change this to first download the installer and its published checksum (or a
signed artifact) into the image, verify the checksum/signature against a trusted
value, and only then execute the installer; implement this by replacing the pipe
with a sequence that curl -fSLo the install.sh and checksum file, validate the
checksum for install.sh, and then run install.sh with
UV_INSTALL_DIR=/usr/local/bin, failing the build if verification fails.
| FROM base AS gym | ||
|
|
||
| WORKDIR /opt/NeMo-Gym | ||
| COPY --from=gym-src / /opt/NeMo-Gym/ | ||
|
|
||
| # Pre-create the venv + warm the uv cache. `nemo_gym_rollouts` runs | ||
| # `uv venv --python 3.12 --allow-existing .venv` + `uv sync --active --extra dev` | ||
| # at job start; with the cache warm this completes in ~1s. | ||
| # | ||
| # --copies places a full python binary inside .venv/bin so the venv doesn't | ||
| # depend on any uv-managed interpreter path that could vanish during image | ||
| # flattening (otherwise the symlink target under /root/.local/share/uv/python/ | ||
| # can be missing in the final squashfs). | ||
| ENV UV_LINK_MODE=copy | ||
| RUN uv venv --python /usr/local/bin/python3.12 .venv \ | ||
| && uv sync --active --extra dev | ||
|
|
||
| # Sanity: verify the baked venv imports Gym's core modules and exposes ng_run. | ||
| RUN . .venv/bin/activate \ | ||
| && python -c "import nemo_gym, nemo_gym.cli; print('nemo_gym', nemo_gym.__version__)" \ | ||
| && command -v ng_run \ | ||
| && command -v ng_collect_rollouts | ||
|
|
||
| ENV NEMO_GYM_PATH=/opt/NeMo-Gym |
There was a problem hiding this comment.
Run the final image as a non-root user.
The container currently runs as root. Add a dedicated user and switch to it in the final stage.
Suggested hardening
FROM base AS gym
@@
RUN . .venv/bin/activate \
&& python -c "import nemo_gym, nemo_gym.cli; print('nemo_gym', nemo_gym.__version__)" \
&& command -v ng_run \
&& command -v ng_collect_rollouts
ENV NEMO_GYM_PATH=/opt/NeMo-Gym
+RUN useradd --system --create-home --home-dir /home/nemo nemo \
+ && chown -R nemo:nemo /opt/NeMo-Gym
+USER nemo🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@dockerfiles/Dockerfile.nemo-gym` around lines 56 - 79, The final image stage
runs as root; create a non-root user and switch to it before finishing the "gym"
stage: add a dedicated user/group (e.g., nemo or nemo_gym_user) and a home
directory, chown the app dir (/opt/NeMo-Gym) and the baked venv (.venv) to that
user, and set USER to that account (and optionally set HOME and PATH) so
subsequent containers run non-root; update any RUNs that rely on root-only paths
to use the new user ownership (refer to the "gym" stage, the .venv,
NEMO_GYM_PATH, and the uv/venv setup commands when adjusting ownership).
So nemo_gym_rollouts picks up the new Dockerfile.nemo-gym image via cluster_config['containers']['nemo-gym'] without callers needing to pass --gym_container explicitly. Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
- nemo_skills/__init__.py: add nemo-gym to _containers so `ns setup` initializes the entry by default. - tests/gpu-tests/test-local.yaml: mirror the addition so GPU test configs are aligned with the example config. Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
| && command -v ng_run \ | ||
| && command -v ng_collect_rollouts | ||
|
|
||
| ENV NEMO_GYM_PATH=/opt/NeMo-Gym |
There was a problem hiding this comment.
maybe just /opt/Gym then? To match default repo name
Match the default checkout directory name from `git clone https://github.com/NVIDIA-NeMo/Gym.git` (which produces `Gym/`), per review feedback. Updates WORKDIR, COPY target, header comment, and NEMO_GYM_PATH env var. Signed-off-by: gwarmstrong <gwarmstrong@users.noreply.github.com>
There was a problem hiding this comment.
♻️ Duplicate comments (2)
dockerfiles/Dockerfile.nemo-gym (2)
56-80:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRun final image as non-root user.
The final
gymstage has noUSER, so runtime defaults to root. Add a dedicated user and chown/opt/Gym(including.venv) before switching.Suggested hardening diff
FROM base AS gym @@ RUN . .venv/bin/activate \ && python -c "import nemo_gym, nemo_gym.cli; print('nemo_gym', nemo_gym.__version__)" \ && command -v ng_run \ && command -v ng_collect_rollouts ENV NEMO_GYM_PATH=/opt/Gym +RUN useradd --system --create-home --home-dir /home/nemo nemo \ + && chown -R nemo:nemo /opt/Gym +USER nemo🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dockerfiles/Dockerfile.nemo-gym` around lines 56 - 80, The final gym image currently runs as root; create a non-root user and switch to it in the gym stage by adding a dedicated user (e.g., nemo or nemo_gym), chown /opt/Gym (including .venv) to that user after the uv venv/uv sync steps, and set USER to that account before the stage ends; reference the gym stage, the /opt/Gym directory (and its .venv), the uv venv/uv sync steps where ownership should be fixed, and the NEMO_GYM_PATH environment var so the runtime process (ng_run/ng_collect_rollouts) runs as the new non-root user.
53-53:⚠️ Potential issue | 🟠 Major | ⚡ Quick winHarden uv install by avoiding
curl | shon Line 53.This still executes remote script content directly at build time. Download, verify checksum/signature, then execute.
#!/bin/bash # Verify whether the Dockerfile still uses direct pipe-to-shell for uv installer rg -n 'astral\.sh/uv/.*/install\.sh\s*\|\s*env\s+UV_INSTALL_DIR=.*/usr/local/bin\s+sh' dockerfiles/Dockerfile.nemo-gymSuggested hardening diff
ARG UV_VERSION=0.9.30 # Gym's pyproject.toml sets [tool.uv] required-version = ">=0.9.30" +ARG UV_INSTALLER_SHA256=<pin-installer-sha256> # Install uv into /usr/local/bin so it's on the default PATH even when SLURM/pyxis # strips the image's ENV PATH (pyxis resets PATH to the host's default and the # image's ENV PATH is dropped, which can make `uv` unfindable inside the job). -RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh +RUN curl -fLsS "https://astral.sh/uv/${UV_VERSION}/install.sh" -o /tmp/uv-install.sh \ + && echo "${UV_INSTALLER_SHA256} /tmp/uv-install.sh" | sha256sum -c - \ + && env UV_INSTALL_DIR=/usr/local/bin sh /tmp/uv-install.sh \ + && rm -f /tmp/uv-install.sh🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dockerfiles/Dockerfile.nemo-gym` at line 53, Replace the unsafe "curl | sh" RUN step that installs uv (the line using UV_VERSION and astral.sh/uv/.../install.sh) by first downloading the installer to a temporary file with curl, verify its integrity (checksum or signature) against a known-good value or key, only then execute it with UV_INSTALL_DIR=/usr/local/bin sh, and finally remove the temporary installer; update the Dockerfile to reference UV_VERSION and add ENV/ARG or build-arg for the expected checksum/signature so the verification step can fail the build if validation does not match.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@dockerfiles/Dockerfile.nemo-gym`:
- Around line 56-80: The final gym image currently runs as root; create a
non-root user and switch to it in the gym stage by adding a dedicated user
(e.g., nemo or nemo_gym), chown /opt/Gym (including .venv) to that user after
the uv venv/uv sync steps, and set USER to that account before the stage ends;
reference the gym stage, the /opt/Gym directory (and its .venv), the uv venv/uv
sync steps where ownership should be fixed, and the NEMO_GYM_PATH environment
var so the runtime process (ng_run/ng_collect_rollouts) runs as the new non-root
user.
- Line 53: Replace the unsafe "curl | sh" RUN step that installs uv (the line
using UV_VERSION and astral.sh/uv/.../install.sh) by first downloading the
installer to a temporary file with curl, verify its integrity (checksum or
signature) against a known-good value or key, only then execute it with
UV_INSTALL_DIR=/usr/local/bin sh, and finally remove the temporary installer;
update the Dockerfile to reference UV_VERSION and add ENV/ARG or build-arg for
the expected checksum/signature so the verification step can fail the build if
validation does not match.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8f43ccd4-4c47-4508-aa54-023616fae06b
📒 Files selected for processing (1)
dockerfiles/Dockerfile.nemo-gym
Summary
Adds a minimal NeMo Gym runtime container (
dockerfiles/Dockerfile.nemo-gym) for runningng_run/ng_collect_rolloutsagainst a pre-hosted or separately-launched policy server.BASE_IMAGEdefaults topython:3.12-slim-bookworm.GYM_COMMITpinned to NVIDIA-NeMo/Gym@90770c32 (currentmain) and pulled hermetically viaADDfrom GitHub.uvinstalled to/usr/local/binso it survives SLURM/pyxis PATH resets./opt/NeMo-Gym/.venvwith--copiesso it doesn't depend on a uv-managed interpreter path that can vanish during image flattening.import nemo_gymand thatng_run/ng_collect_rolloutsare on PATH inside the baked venv.Summary by CodeRabbit
New Features
Configuration
Tests