Repository navigation
Mirror distfiles to Cloudflare on the fly when S3 credentials are present #4404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+156
−61
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e02fd56
ci-automation/release.sh: Replace rclone config file with env variables
chewi 4f8c536
ci-automation/release.sh: Update rclone from 1.71.1 to 1.76.0
chewi 7a9ee69
bootstrap_sdk: Use HTTPS rather than HTTP for the Portage mirrors
chewi 044d109
update_chroot: Change wget User-Agent string to not include a URL
chewi 052753f
Mirror distfiles to Cloudflare on the fly when S3 creds are present
chewi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
| eval "set -- $1" | ||
| "${@}" | ||
|
|
||
| # Don't mirror restricted distfiles. This doesn't check mirror+ overrides, but | ||
| # Flatcar will almost certainly never encounter one. | ||
| for value in ${RESTRICT}; do | ||
| [[ ${value} == mirror ]] && exit | ||
| done | ||
|
|
||
| if [[ ${1-} != wget ]]; then | ||
| echo "* Fetched with a tool other than wget. Cannot mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| while [[ 0 -lt $# ]]; do | ||
| case $1 in | ||
| --output-document=*) | ||
|
chewi marked this conversation as resolved.
Resolved
|
||
| file=${1#*=}; shift ;; | ||
| --output-document|-O) | ||
| file=${2-}; shift 2 ;; | ||
| -*) | ||
| shift ;; | ||
| *) | ||
| url=$1; shift ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ ${file-} != /*.__download__ || ${url-} != *://* ]]; then | ||
| echo "* Could not parse wget arguments. Cannot mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| if [[ ${url} == */layout.conf ]]; then | ||
| # distfiles layout configuration shouldn't be mirrored. | ||
| exit | ||
| fi | ||
|
|
||
| # GENTOO_MIRRORS is filtered by Portage. We cannot get the real value if it has | ||
| # been overridden, so don't do that when the S3 credentials are set. | ||
| GENTOO_MIRRORS=$(unset PORTAGE_REPOSITORIES; portageq envvar GENTOO_MIRRORS) | ||
| GENTOO_MIRRORS=${GENTOO_MIRRORS%% *} | ||
|
|
||
| # This shouldn't happen, but if it does, it would cost money, so double check. | ||
| if [[ ${GENTOO_MIRRORS} != https://mirror.release.flatcar-linux.net ]]; then | ||
| echo "* GENTOO_MIRRORS has been modified. Cannot mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| if [[ ${url} == "${GENTOO_MIRRORS}"/distfiles/* ]]; then | ||
| # Already mirrored. | ||
| exit | ||
| fi | ||
|
|
||
| if ! [[ | ||
| ${RCLONE_S3_PROVIDER-} == Cloudflare && \ | ||
| ${RCLONE_S3_ACCESS_KEY_ID-} && \ | ||
| ${RCLONE_S3_SECRET_ACCESS_KEY-} && \ | ||
| ${RCLONE_S3_ENDPOINT-} \ | ||
| ]]; then | ||
| echo "* Cloudflare credentials not present. Cannot mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| basename=${file##*/} | ||
| basename=${basename%.__download__} | ||
|
|
||
| # Upstream Gentoo uses the filename-hash layout, but this has little benefit | ||
| # over the flat layout when hosted on Cloudflare R2. However, the content-hash | ||
| # layout handles different versions of files with the same filename, which could | ||
| # be useful when maintaining several Flatcar release channels. | ||
| path=$(python3 - "${EBUILD%/*}" "${basename}" <<-'EOF' | ||
| import sys | ||
| from portage.manifest import Manifest | ||
| from portage.package.ebuild.fetch import ContentHashLayout, DistfileName | ||
|
|
||
| dir, file = sys.argv[1:] | ||
| digests = Manifest(dir).getTypeDigests("DIST")[file] | ||
| filename = DistfileName(file, digests=digests) | ||
| print(ContentHashLayout("BLAKE2B", "8").get_path(filename)) | ||
| EOF | ||
| ) || : | ||
|
|
||
| if [[ -z ${path} ]]; then | ||
| echo "* Could not determine content-hash path for ${basename}. Cannot mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| # The last part of the path should be the BLAKE2B digest. | ||
| if ! b2sum --check --status <<< "${path##*/} *${file}"; then | ||
| echo "* Checksum mismatch for ${basename}. Refusing to mirror." >&2 | ||
| exit | ||
| fi | ||
|
|
||
| echo "* Attempting to mirror ${basename} ..." >&2 | ||
|
|
||
| curl \ | ||
| --location \ | ||
| --fail-with-body \ | ||
| --aws-sigv4 "aws:amz:auto:s3" \ | ||
| --variable %RCLONE_S3_ACCESS_KEY_ID \ | ||
| --variable %RCLONE_S3_SECRET_ACCESS_KEY \ | ||
| --expand-user "{{RCLONE_S3_ACCESS_KEY_ID}}:{{RCLONE_S3_SECRET_ACCESS_KEY}}" \ | ||
| --upload-file "${file}" \ | ||
| "${RCLONE_S3_ENDPOINT}/flatcar/mirror/distfiles/${path}" >&2 || : | ||
|
|
||
| echo >&2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| RCLONE_S3_ACCESS_KEY_ID | ||
| RCLONE_S3_ENDPOINT | ||
| RCLONE_S3_PROVIDER | ||
| RCLONE_S3_SECRET_ACCESS_KEY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.