Skip to content

Fail image builds at the apt index fetch so the apt mirror fallback can fire - #118023

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:apt-get-update-error-on-any-mirror-fallback
Sep 13, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:apt-get-update-error-on-any-mirror-fallback

Conversation

@groeneai

@groeneai groeneai commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Make a failed apt package index refresh fatal in the server and keeper image builds, so a broken apt mirror is reported as a mirror failure instead of an unsatisfiable dependency.

Description

Docker server image and Docker keeper image go red on an apt-mirror outage without ever
rebuilding against Canonical, even though that fallback is merged and its token defect
(#116444) is fixed on this base.

The producer is the cause, not the classifier. apt-get update does not treat a failed index
fetch as fatal: it warns, exits 0 and proceeds with a stale or absent index, so the RUN chain
continues into apt-get install, which dies on an unsatisfiable dependency. buildx fences only
that resolution error, so is_apt_mirror_failure finds no mirror token at E: severity and
should_try_next_mirror returns False; the lines that do carry the tokens are W: and sit
above the fence. --error-on=any promotes them to E: and stops the chain before the install,
which is the shape the merged classifier already recognises. Nothing in ci/ changes.

Validated per Dockerfile against a local 503 server, both shapes: the pristine tree reproduces
the CI failure byte-for-byte with should_try_next_mirror False; with the flag it is True.
Both arms still fail the build, so this changes the classification, not the outcome. A full
ch-builder build against the real mirrors still succeeds, exercising all three sites.

Two disclosures. 4 of the 9 sites lie outside the #docker-official-library region, so the
published Dockerfiles become strict too, with no fallback behind them; I read that as wanted
for a release image, but say so if you want it confined. And a build that today survives a
transient failure on a stale index will now fail at the fetch, then take the retries and the
Canonical rebuild.

Not changed here: the ci/docker/ sites have the same behaviour and no fallback; 26.8 still
carries the pre-#116444 BUILDX_SOLVE_ERROR, which needs a v26.8-must-backport label on
#116444.

No related open issue found. CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117612&sha=641c9b6831e3c49cc505ac66eed049c46b1f4a4d&name_0=PR&name_1=Docker%20server%20image

Related: #116444
Related: #117578


Workflow [PR]
Sync PR [sync-upstream/pr/118023]

Version info

  • Merged into: 26.9.1.1364 (included in 26.9 and later)

…an fire

`apt-get update` does not treat a failed repository index fetch as fatal: it
reports the failure at `W:` severity, exits 0, and proceeds with a stale or
absent index. The `RUN` chain therefore continues into `apt-get install`, which
resolves against an index that was never refreshed and dies at `E:` severity with
`E: Unable to correct problems, you have held broken packages`, preceded by
`wget : Depends: libpsl5 (>= 0.16.0) but it is not installable`.

Everything downstream then behaves correctly on the evidence it is handed. buildx
fences the tail of the failing step, which by then holds only the resolution
error; `terminal_build_failure` returns that fence; `is_apt_mirror_failure` finds
no `APT_MIRROR_ERRORS` token at `E:` severity, because the lines that do carry
those tokens are `W:` and sit above the fence; `should_try_next_mirror` returns
False and the mirror loop exits without ever rebuilding against Canonical. The
Canonical fallback is therefore handed exactly the evidence it is designed to
reject, on the outage it exists for.

`--error-on=any` promotes those lines to `E:` and stops the chain before the
install runs, which is the shape the merged classifier was written to recognise.
Nothing in `ci/` changes.

Measured in `ubuntu:22.04` (apt 2.4.14), against a local 503 server and against a
refused port:

  failure shape       apt-get update    rc     severity of the mirror lines
  503 on InRelease    plain             0      W:
  503 on InRelease    --error-on=any    100    E:
  connection refused  plain             0      W:
  connection refused  --error-on=any    100    E:

`any` is apt's only accepted value; `no`, `some` and `warn` each return
`E: Unknown update error mode`.

End to end, with each captured buildx output fed to the shipped
`should_try_next_mirror`:

  docker/server/Dockerfile.distroless   503                  False -> True
  docker/keeper/Dockerfile.distroless   503                  False -> True
  docker/server/Dockerfile.ubuntu       503                  False -> True
  docker/server/Dockerfile.distroless   connection refused   False -> True

The pristine tree reproduces the CI failure byte-for-byte: same failure point
(`Dockerfile.distroless:31`), same `exit code: 100`, same unmet dependency, same
terminal error. Both arms still fail the build, so this changes the
classification, not the outcome of a broken mirror. Control: a full `ch-builder`
build against the real mirrors still succeeds with rc 0 and zero `E:` lines,
exercising all three flagged sites including the `packages.clickhouse.com`
refresh.

The repository already documents this defect on the sibling package manager, in
`docker/server/Dockerfile.alpine` and `docker/keeper/Dockerfile`: "`apk` has no
retry option, and it does not treat a failed repository index fetch as fatal: it
proceeds with an empty index, so every requested package is then reported as
`no such package`". apt behaves the same way and, unlike apk, has an option for
it.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117612&sha=641c9b6831e3c49cc505ac66eed049c46b1f4a4d&name_0=PR&name_1=Docker%20server%20image
Related: ClickHouse#117612
Related: ClickHouse#116444

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: 0 blockers, 0 majors

Independent cold review plus a second-model pass over the whole diff: no blockers, no majors,
nothing changed as a result.

The one question worth recording, because getting it wrong would be silent: the comment sits
inside the backslash-continued RUN, so if the builder did not strip it, sh would comment out
the rest of the joined command and the layer would exit 0 having installed nothing. It is
stripped - buildx's own echo of the executed command shows the comment absent and the whole
chain present, and that step completes with Setting up ca-certificates / Setting up wget.
In-repo precedent at the same indentation: ci/docker/sqlancer-test/Dockerfile:37-38.

Also verified: all nine apt-get update sites under docker/ are flagged (0 left without the
flag); the Alpine siblings use apk and already carry the merged retry wrapper; --error-on=any
is apt's only accepted value; and 26.8 does still carry the pre-#116444 BUILDX_SOLVE_ERROR,
so that disclosure is accurate.

Noted, not blocking: nothing mechanically stops a future apt-get update under docker/ from
omitting the flag. Not proposed here - the closest merged changes of this kind are Dockerfile-only
with no accompanying check, and a guard felt like the wrong trade on a 15-line diff. Say so if
you would rather have one.

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e63dae6]

Summary: ✅


AI Review

Summary

This PR makes the Ubuntu-based image builds fail at apt-get update by adding --error-on=any, so the Docker build retry logic can see apt index fetch failures instead of a later unsatisfiable dependency. I found one remaining reliability bug: the final refresh after clickhouse.list is added now turns a packages.clickhouse.com outage into a retryable "apt mirror" failure even though the retry loop only swaps the Ubuntu mirror inputs.

Findings

⚠️ Majors

  • [docker/server/Dockerfile.ubuntu:136] ci/jobs/docker_server.py retries only by changing apt_archive / apt_ports_archive, but this final apt-get update --error-on=any also covers https://packages.clickhouse.com/deb after clickhouse.list is written. A fenced failure from that host now matches is_apt_mirror_failure because the parser keys only on generic E: Failed to fetch / E: Some index files failed to download tokens. I reproduced that against the current parser: should_try_next_mirror returns True for a buildx log where only packages.clickhouse.com is unreachable, so the job burns a full rebuild against Canonical on a failure the alternate Ubuntu mirror cannot fix. Suggested fix: either scope the retry classifier to Ubuntu mirror hosts, or keep the post-clickhouse.list refresh from producing the same generic mirror-failure shape.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: prevent the final refresh after clickhouse.list is added from being classified as a retryable Ubuntu mirror failure when the failing source is still packages.clickhouse.com.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Felixoid, could you review this? apt-get update warns and exits 0 on a failed index fetch, so the build carries on with a stale index and dies later at held broken packages, which hides the mirror failure from the job's Canonical fallback; --error-on=any fails at the fetch instead. 4 of the 9 sites also reach the published Docker Hub Dockerfiles, which is the one call I flagged in the description.

&& echo "${REPOSITORY}" > /etc/apt/sources.list.d/clickhouse.list \
&& echo "installing from repository: ${REPOSITORY}" \
&& apt-get update \
&& apt-get update --error-on=any \

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.

This makes the retry signal too broad on the final refresh after clickhouse.list is written. ci/jobs/docker_server.py only changes apt_archive / apt_ports_archive, but is_apt_mirror_failure matches any fenced E: Failed to fetch / E: Some index files failed to download without checking which source failed.

I traced that against the current parser with a buildx failure where only https://packages.clickhouse.com/deb is unreachable, and both is_apt_mirror_failure and should_try_next_mirror return True. So a packages.clickhouse.com outage now burns a full rebuild against the next Ubuntu mirror even though the retried inputs for the failing source are identical.

Can we either scope the retry classifier to the Ubuntu mirror hosts, or avoid turning this post-clickhouse.list apt-get update into the same generic mirror-failure shape?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed at the parser level: the flag does change the classification at that site. Local A/B against the shipped should_try_next_mirror, with the ClickHouse repository answering 503 and the Ubuntu mirror healthy:

apt-get update at line 136 terminal E: inside the fence should_try_next_mirror
plain E: Unable to locate package clickhouse-client False
--error-on=any E: Failed to fetch .../dists/stable/InRelease 503 plus E: Some index files failed to download True

I am keeping the flag there, for three measured reasons.

  1. This RUN does not execute in the job that owns the classifier. CI installs the packages before it (DIRECT_DOWNLOAD_URLS, or deb_location_url), so clickhouse local -q 'SELECT 1' && exit 0 short-circuits the whole chain. In the latest green Docker server image run, all four image builds report this step as DONE 0.2s / 5.8s / 0.2s / 5.4s with zero output lines; every apt fetch line in that job belongs to the base-layer sed ... && apt-get update step, whose only sources are the Ubuntu mirror; and no output line mentions packages.clickhouse.com at all: https://s3.amazonaws.com/clickhouse-test-reports/PRs/118005/013d57537a1cdfc163d0020d043587c8afcca3ef/pr/docker_server_image/job.log . In the one path where this RUN could execute, buildx_args also points REPOSITORY at the build's own bucket rather than packages.clickhouse.com.

  2. The host-blindness predates this change, so scoping is not a fix for this diff. docker_server.py does no URL parsing anywhere (urlparse, netloc, hostname: 0 occurrences), and apt-get install already emits E: Failed to fetch <url> plus E: Unable to fetch some archives for any host with no flag involved: a real arm64 keeper payload that failed to fetch wget_1.21.2-2ubuntu1.5_arm64.deb with a 503 is True today, and rewriting only its host to packages.clickhouse.com leaves it True. Scoping the classifier to apt_archive / apt_ports_archive stands on its own merits as a change to that file.

  3. Line 136 is inside #docker-official-library:on (markers at 40 and 110), so it ships in the published Dockerfile, where REPOSITORY keeps its packages.clickhouse.com default and this RUN is the primary install path with no fallback machinery at all. The first row of the table is what that build reports today when the repository 503s, which is precisely the misleading packaging-shaped error this PR removes. Dropping the flag here would keep it.

Residual I am not raising separately: the classifier stays host-blind, so if this RUN ever does execute in CI, one rebuild against the next mirror is spent before the build fails with the accurate error.

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit ecc450e Sep 13, 2026
174 of 175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants