Skip to content

[ci] Mirror bazel's downloads on the agent, and keep the config - #65605

Merged
elliot-barn merged 3 commits into
masterfrom
elliot-barn/bazel-downloader-agent
Aug 20, 2026
Merged

elliot-barn merged 3 commits into
masterfrom
elliot-barn/bazel-downloader-agent

Conversation

@elliot-barn

Copy link
Copy Markdown
Collaborator

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:

  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 #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:

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: #65599 is merged, and this is the follow-up its own review asked for.

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]>
@elliot-barn
elliot-barn requested review from a team as code owners August 19, 2026 23:48

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread ci/install_pypi_proxy.sh Resolved

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +24 to +26
_rayci_bazel_downloader_cfg_path() {
echo "${HOME}/.rayci_bazel_downloader.cfg"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
_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"
}

Comment on lines +45 to +49
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#*://}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This suggestion addresses two potential issues:

  1. If RAYCI_PYPI_MIRROR_URL or the passed mirror argument contains a trailing slash (e.g., https://mirror.ci.ray.io/), the extracted host will 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 from mirror before extracting the host.
  2. It handles the potential failure of _rayci_bazel_downloader_cfg_path if HOME is unset or empty, failing open by returning 0.
Suggested change
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#*://}"

Comment on lines +84 to +85
local cfg
cfg="$(_rayci_bazel_downloader_cfg_path)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Handle the potential failure of _rayci_bazel_downloader_cfg_path if HOME is unset or empty, failing open by returning 0.

Suggested change
local cfg
cfg="$(_rayci_bazel_downloader_cfg_path)"
local cfg
cfg="$(_rayci_bazel_downloader_cfg_path)" || return 0

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]>
@elliot-barn elliot-barn added the go add ONLY when ready to merge, run all tests label Aug 20, 2026
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]>
@elliot-barn
elliot-barn merged commit c3ba9b8 into master Aug 20, 2026
5 of 6 checks passed
@elliot-barn
elliot-barn deleted the elliot-barn/bazel-downloader-agent branch August 20, 2026 00:53
elliot-barn added a commit to ray-project/rayci that referenced this pull request Aug 20, 2026
## 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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants