Skip to content

Mirror distfiles to Cloudflare on the fly when S3 credentials are present - #4404

Merged
chewi merged 5 commits into
mainfrom
chewi/distfiles-mirror
Nov 27, 2026
Merged

chewi merged 5 commits into
mainfrom
chewi/distfiles-mirror

Conversation

@chewi

@chewi chewi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Care is taken to not include the credentials in command line arguments or write them to files.

If mirroring fails for any reason, such as the credentials not being present because it's not CI, the script exits non-fatally. We don't want it to break builds.

The requested URL is checked to ensure we don't upload something that we just downloaded from the same mirror. That would be slow and expensive.

The downloaded file is checked against the Manifest file (BLAKE2B only) before Portage does its own check to ensure we don't mirror a corrupted file.

I tried to implement this as a Portage phase hook so that it would only upload after Portage had checked against the Manifest, but I bumped into the network sandbox. It was also awkward for other reasons.

Unlike before, files for the different Portage repositories are mirrored together under the same distfiles directory. There is no benefit in separating them, and this would incur a performance cost because Portage would sometimes have to check more than one location to find the file.

Flatcar previously mirrored using the traditional flat layout with all the files in a single directory. Gentoo now uses the filename-hash layout, but this has little benefit over the flat layout when hosted on Cloudflare R2. However, I have chosen the content-hash layout because it handles different versions of files with the same filename, which could be useful when maintaining several Flatcar release channels. The hosted files are named with their digest rather than their regular filename, but this shouldn't be an issue, as Portage does the translation. This requires a distfiles/layout.conf file to be placed on the mirror. For future reference, it looks like this:

[structure]
0=content-hash BLAKE2B 8

I have also:

  • Replaced the rclone config file with separate environment variables.
  • Updated the rclone Docker image to the latest version.
  • Unforced HTTP (vs HTTPS) for the distfiles mirrors.
  • Changed the User-Agent string to not include a URL.

See flatcar/jenkins-os#493 for the jenkins-os changes. I will only need to backport the rclone config file change to the other channels.

How to use

Build in CI with the chewi/rclone-env jenkins-os branch.

Testing done

I've done lots of builds locally and in CI, including this successful SDK build. The mirror is now fully populated for main.

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update) -- N/A
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

@chewi chewi self-assigned this Nov 25, 2026
@chewi
chewi requested a review from a team as a code owner November 25, 2026 22:48
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:48

This comment was marked as resolved.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
The 10 year old comment claims HTTPS didn't work when bootstrapping. If
that was ever really true, it isn't true now. Our mirrors don't
currently work, so many downloads will fall back to GitHub, which always
redirects you to HTTPS.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
Including a URL apparently makes you more likely to be blocked, as this
is typically done by bots. Gentoo has made the same change.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
@chewi
chewi force-pushed the chewi/distfiles-mirror branch from 338847b to 115c703 Compare November 25, 2026 23:08
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:08
Copilot stopped reviewing on behalf of chewi due to an error November 25, 2026 23:08

This comment was marked as resolved.

@chewi
chewi force-pushed the chewi/distfiles-mirror branch from 115c703 to 57f33b3 Compare November 25, 2026 23:19
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:19
@chewi

chewi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

🔵 Needs a closer look

The wget --output-document=... branch scopes the filename assignment to shift, leaving file unset and causing a parse error instead of mirroring the downloaded distfile.

There was a missing semicolon. I didn't notice because we use -O rather than --output-document. Fixed.

Copilot AI 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.

🔵 Needs a closer look

An unguarded portageq failure triggers set -e after a successful download, causing optional mirror configuration lookup to fail the wrapper.

No open issues 🎉

Review effort: Balanced

@chewi

chewi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🔵 Needs a closer look

An unguarded portageq failure triggers set -e after a successful download, causing optional mirror configuration lookup to fail the wrapper.

That really shouldn't fail. I'd rather stop at that point.

Comment thread build_library/portage/bin/fetch-wrapper Resolved
Comment thread build_library/portage/bin/fetch-wrapper Resolved
Comment thread build_library/catalyst.sh Resolved
Care is taken to not include the credentials in command line arguments
or write them to files.

If mirroring fails for any reason, such as the credentials not being
present because it's not CI, the script exits non-fatally. We don't want
it to break builds.

The requested URL is checked to ensure we don't upload something that we
just downloaded from the same mirror. That would be slow and expensive.

The downloaded file is checked against the Manifest file (BLAKE2B only)
before Portage does its own check to ensure we don't mirror a corrupted
file.

I tried to implement this as a Portage phase hook so that it would only
upload after Portage had checked against the Manifest, but I bumped into
the network sandbox. It was also awkward for other reasons.

Unlike before, files for the different Portage repositories are mirrored
together under the same distfiles directory. There is no benefit in
separating them, and this would incur a performance cost because Portage
would sometimes have to check more than one location to find the file.

Flatcar previously mirrored using the traditional flat layout with all
the files in a single directory. Gentoo now uses the filename-hash
layout, but this has little benefit over the flat layout when hosted on
Cloudflare R2. However, I have chosen the content-hash layout because it
handles different versions of files with the same filename, which could
be useful when maintaining several Flatcar release channels. The hosted
files are named with their digest rather than their regular filename,
but this shouldn't be an issue, as Portage does the translation. This
requires a distfiles/layout.conf file to be placed on the mirror. For
future reference, it looks like this:

    [structure]
    0=content-hash BLAKE2B 8

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
@chewi
chewi force-pushed the chewi/distfiles-mirror branch from 57f33b3 to 052753f Compare November 26, 2026 15:54
Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:54

Copilot AI 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.

🔵 Needs a closer look

An unguarded optional portageq lookup can trigger set -e and report fetch failure despite a successful wget download when mirroring credentials are absent.

No open issues 🎉

Review effort: Balanced

@chewi
chewi merged commit db54392 into main Nov 27, 2026
2 of 3 checks passed
@chewi
chewi deleted the chewi/distfiles-mirror branch November 27, 2026 22:50

This branch is waiting to be deployed

1 waiting deployment
development — 052753fe Waiting Nov 26, 2026 by chewi via Wait for approval #6192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants