Repository navigation
[ci] Mirror bazel's downloads on the agent, and keep the config - #65605
Conversation
Three gaps around the bazel downloader rewrite #65599 added, all in the same mechanism, so one change. **The agent had no rewrite at all.** The images get it from ci/pypi_proxy_profile.sh, and the steps that never enter a container get nothing -- so release 104848's init step still fetched tomli-2.0.1-py3-none-any.whl from files.pythonhosted.org, the one direct origin fetch in that build's 41 finished jobs. It was served from bazel's SHA-256 cache this time; a cache miss goes to the origin, and init failing means zero release tests run. **ci/env/install-bazel.sh clears ~/.bazelrc.** Under CI it does `echo > ~/.bazelrc`, which drops the rewrite line wherever a hook already wrote it, and it runs *after* those hooks: `ci/ci.sh init` reaches it through install-dependencies.sh, and on macOS that is the line directly after ci/ray_ci/macos/macos_ci.sh sources the proxy. So the rewrite is restored after the clear. Restoring reads the config file's existence as the record that a hook probed the mirror and found it, so a job with an unreachable mirror still gets no rewrite. **The rewrite rules now live in one file**, ci/bazel_mirror_downloader.sh, rather than being copied into each caller. install_pypi_proxy.sh installs it beside the proxy, because the profile.d hook runs at shell start and cannot count on a checkout being there; the checkout paths cover images with no proxy. Also corrects the header of ci/pypi_proxy_profile.sh, which still described a usable "rewriting simple index at /simple" that the code below it had already ruled out. Tested: the helper sourced directly, checking that config writes both files, that a second call adds nothing, that restore re-adds the line after a clear, that restore is a no-op with no config, that a non-https mirror writes nothing, and that nothing is touched with BUILDKITE unset. Signed-off-by: Elliot Barnwell <[email protected]> Signed-off-by: elliot-barn <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 85262cd. Configure here.
There was a problem hiding this comment.
Code Review
This pull request refactors the Bazel downloader mirror configuration by extracting it into a dedicated helper script, ci/bazel_mirror_downloader.sh. This helper is integrated across various CI scripts (ci/env/install-bazel.sh, ci/pypi_proxy_agent.sh, and ci/pypi_proxy_profile.sh) to ensure that Bazel's downloader consistently routes requests through the CI package mirror. The review feedback suggests defensive improvements to handle scenarios where the HOME environment variable is unset or empty, which could cause permission issues, and recommends stripping trailing slashes from the mirror URL to prevent malformed double-slash paths in the rewritten URLs.
| _rayci_bazel_downloader_cfg_path() { | ||
| echo "${HOME}/.rayci_bazel_downloader.cfg" | ||
| } |
There was a problem hiding this comment.
If HOME is unset or empty, _rayci_bazel_downloader_cfg_path will return /.rayci_bazel_downloader.cfg, which can cause permission issues when attempting to write to the root directory.
We can add a defensive check to ensure HOME is set and non-empty, returning 1 if it is not.
| _rayci_bazel_downloader_cfg_path() { | |
| echo "${HOME}/.rayci_bazel_downloader.cfg" | |
| } | |
| _rayci_bazel_downloader_cfg_path() { | |
| [[ -n "${HOME:-}" ]] || return 1 | |
| echo "${HOME}/.rayci_bazel_downloader.cfg" | |
| } |
| rayci_bazel_downloader_config() { | ||
| local mirror="${1:-${RAYCI_PYPI_MIRROR_URL:-https://mirror.ci.ray.io}}" | ||
| local cfg | ||
| cfg="$(_rayci_bazel_downloader_cfg_path)" | ||
| local host="${mirror#*://}" |
There was a problem hiding this comment.
This suggestion addresses two potential issues:
- If
RAYCI_PYPI_MIRROR_URLor the passedmirrorargument contains a trailing slash (e.g.,https://mirror.ci.ray.io/), the extractedhostwill retain it (e.g.,mirror.ci.ray.io/). This leads to a double slash in the rewritten URL (e.g.,mirror.ci.ray.io//files.pythonhosted.org/...), which can cause 404 errors or resolution failures depending on the mirror's web server configuration. We can defensively strip any trailing slash frommirrorbefore extracting the host. - It handles the potential failure of
_rayci_bazel_downloader_cfg_pathifHOMEis unset or empty, failing open by returning0.
| rayci_bazel_downloader_config() { | |
| local mirror="${1:-${RAYCI_PYPI_MIRROR_URL:-https://mirror.ci.ray.io}}" | |
| local cfg | |
| cfg="$(_rayci_bazel_downloader_cfg_path)" | |
| local host="${mirror#*://}" | |
| rayci_bazel_downloader_config() { | |
| local mirror="${1:-${RAYCI_PYPI_MIRROR_URL:-https://mirror.ci.ray.io}}" | |
| mirror="${mirror%/}" | |
| local cfg | |
| cfg="$(_rayci_bazel_downloader_cfg_path)" || return 0 | |
| local host="${mirror#*://}" |
| local cfg | ||
| cfg="$(_rayci_bazel_downloader_cfg_path)" |
microcheck 52514 failed `wanda: forge` and `wanda: manylinux-x86_64` on
cp: cannot stat 'bazel_mirror_downloader.sh': No such file or directory
An image build sees only what its wanda spec lists in srcs, and the specs
that ship the proxy installer did not list the file it now copies. Both name
it, so the helper reaches the images that need it.
The copy is guarded as well, because the callers do not all hand this script
the same files: a spec that predates the file -- ci/docker/windows.build
being the next one -- should leave bazel on the origin, which the reader
already reports, rather than failing the whole image build on a missing cp.
Signed-off-by: Elliot Barnwell <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
The srcs entries got the file into the build context; these Dockerfiles
mount each proxy file into the RUN by name, so it still was not there when
install_pypi_proxy.sh looked. microcheck 52515 passed both image builds and
said so:
install_pypi_proxy: no bazel_mirror_downloader.sh in this context;
bazel downloads will stay on the origin in images built from it
which is the guarded copy degrading exactly as intended -- and exactly why
the message exists rather than a silent skip.
Signed-off-by: Elliot Barnwell <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
## Description Adds `add-host: rayci.localhost:host-gateway` to the docker buildkite plugin config that `makeRayDockerPlugin` emits for job containers. Wanda's `docker build` (#501) and ray's `ci/ray_ci/linux_container.py` both already pass this mapping, so a service listening on the agent — the package index proxy — is reachable by one stable name from an image build and from a test container. Containers rayci starts through the docker buildkite plugin were the one launcher missing it. The gap became visible when ray's CI images started baking the name into `PIP_INDEX_URL` (ray-project/ray#65578, armed by ray-project/ray#65605): any `job_env` step that runs pip at runtime resolves the baked index and fails DNS with `[Errno -5] No address associated with hostname`. Observed on ray's `doc: check API annotations` / `check API doc consistency` (via setuptools `fetch_build_eggs` for cython), `pyrefly type check` and `build: pip-compile dependencies` (direct runtime pip installs). The mapping is emitted unconditionally, matching the other two launchers. The docker buildkite plugin v5.8.0 supports `add-host` natively (verified in its plugin.yml). Agents where nothing listens on the name are unaffected — the entry only matters to a container that dials it. ## Testing - New `TestMakeRayDockerPlugin_addHost` asserts the emitted mapping. - `go test ./raycicmd` passes; `go test ./...` green except pre-existing local-env failures in `raycilint` (host git too old for `--initial-branch`), identical on clean `main`. Rollout note: after this merges and a release is cut, ray consumes it via `.rayciversion`; the `pyrefly type check` step is a live canary since it still pip-installs at runtime. AI assistance (Claude Code) was used to prepare this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Ray CI Test <[email protected]> Co-authored-by: Ray CI Test <[email protected]>
…project#65605) ## What Follows up ray-project#65599, which pointed bazel's downloader at the CI mirror inside the images. Three gaps in that same mechanism, so one change: 1. **The agent had no rewrite at all.** `ci/pypi_proxy_agent.sh` now sets it up for the steps that never enter a container — the release pipeline's `init` step and every wanda image build. 2. **`ci/env/install-bazel.sh` clears `~/.bazelrc`** and runs *after* the hooks that write into it, so the rewrite is restored after the clear. 3. **The rewrite rules move into one file**, `ci/bazel_mirror_downloader.sh`, instead of being copied per caller. It also corrects the header comment of `ci/pypi_proxy_profile.sh`, which still described a usable "rewriting simple index at `/simple`" that the code below it had already ruled out. Addresses both review comments from @sai-miduthuri on ray-project#65599. ## Why **The agent gap is measurable.** I audited all 41 finished jobs of release build 104848 and counted mirror versus origin fetches: 58 fetches through `mirror.ci.ray.io`, 0 untrusted-host warnings, and exactly one direct `https://files.pythonhosted.org` fetch — in `init`: ``` Fetching https://files.pythonhosted.org/.../tomli-2.0.1-py3-none-any.whl; Checking in SHA-256 cache ``` That is a bazel repository fetch, not pip. The rewrite is written by `ci/pypi_proxy_profile.sh`, which only runs inside the images; `init` runs on the bare agent. That one was served from the SHA-256 cache, but a cache miss goes to the origin — and `init` failing means zero release tests run. **The clobber is real and ordered against us.** `install-bazel.sh` does `echo > ~/.bazelrc` when `CI=true` and `BUILDKITE` is set, and `ci/ci.sh init` reaches it through `install-dependencies.sh`. On macOS it is the line immediately after the proxy is sourced: ```bash source ./ci/ray_ci/macos/pypi_proxy.sh || true # writes the rewrite into ~/.bazelrc . ./ci/ci.sh init && source ~/.zshenv # truncates ~/.bazelrc ``` Restore is deliberately not a second `config`: it re-adds the option only when the config file already exists, and that file's existence is the record that a hook probed the mirror and got an answer. A job whose mirror is unreachable therefore stays on the origin rather than acquiring a rewrite from here. Image builds are unaffected either way — they never set `CI=true`, so that block does not run at image build time. ## Testing Sourced the helper directly and checked each behaviour: | case | expected | result | |---|---|---| | `config` on a reachable mirror | writes cfg + one rc line | ✅ | | second `config` call | adds nothing | ✅ | | rc cleared, then `restore` | line back, cache settings intact | ✅ | | `restore` with no cfg | no-op | ✅ | | non-https mirror | nothing written, message on stderr | ✅ | | `BUILDKITE` unset | nothing touched | ✅ | `bash -n` clean on all four scripts; pre-commit (including shellcheck) clean. AI assistance was used for this change. Not a duplicate: ray-project#65599 is merged, and this is the follow-up its own review asked for. --------- Signed-off-by: Elliot Barnwell <[email protected]> Signed-off-by: elliot-barn <[email protected]>

What
Follows up #65599, which pointed bazel's downloader at the CI mirror inside the images. Three gaps in that same mechanism, so one change:
ci/pypi_proxy_agent.shnow sets it up for the steps that never enter a container — the release pipeline'sinitstep and every wanda image build.ci/env/install-bazel.shclears~/.bazelrcand runs after the hooks that write into it, so the rewrite is restored after the clear.ci/bazel_mirror_downloader.sh, instead of being copied per caller.It also corrects the header comment of
ci/pypi_proxy_profile.sh, which still described a usable "rewriting simple index at/simple" that the code below it had already ruled out.Addresses both review comments from @sai-miduthuri on #65599.
Why
The agent gap is measurable. I audited all 41 finished jobs of release build 104848 and counted mirror versus origin fetches: 58 fetches through
mirror.ci.ray.io, 0 untrusted-host warnings, and exactly one directhttps://files.pythonhosted.orgfetch — ininit:That is a bazel repository fetch, not pip. The rewrite is written by
ci/pypi_proxy_profile.sh, which only runs inside the images;initruns on the bare agent. That one was served from the SHA-256 cache, but a cache miss goes to the origin — andinitfailing means zero release tests run.The clobber is real and ordered against us.
install-bazel.shdoesecho > ~/.bazelrcwhenCI=trueandBUILDKITEis set, andci/ci.sh initreaches it throughinstall-dependencies.sh. On macOS it is the line immediately after the proxy is sourced:Restore is deliberately not a second
config: it re-adds the option only when the config file already exists, and that file's existence is the record that a hook probed the mirror and got an answer. A job whose mirror is unreachable therefore stays on the origin rather than acquiring a rewrite from here.Image builds are unaffected either way — they never set
CI=true, so that block does not run at image build time.Testing
Sourced the helper directly and checked each behaviour:
configon a reachable mirrorconfigcallrestorerestorewith no cfgBUILDKITEunsetbash -nclean on all four scripts; pre-commit (including shellcheck) clean.AI assistance was used for this change. Not a duplicate: #65599 is merged, and this is the follow-up its own review asked for.