Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions bootstrap_sdk
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ EOF
catalyst_stage_default 4
}

# Switch to HTTP because early boostrap stages do not have SSL support.
GENTOO_MIRRORS=$(portageq envvar GENTOO_MIRRORS)
GENTOO_MIRRORS="${GENTOO_MIRRORS//https:\/\//http://}"
export GENTOO_MIRRORS

catalyst_init "$@"
ROOT_OVERLAY=${TEMPDIR}/stage4_overlay

Expand Down
2 changes: 1 addition & 1 deletion bootstrap_sdk_container
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fi

# bootstrap_sdk needs FLATCAR_SDK_VERSION set to the seed version
failed=''
./run_sdk_container "${cleanup[@]}" -V "$seed_version" -v "$target_version" \
./run_sdk_container "${cleanup[@]}" -V "$seed_version" -v "$target_version" -e "${!RCLONE_S3_*}" \
sudo -E ./bootstrap_sdk "${bootstrap_args[@]}" || failed=x

# Update versionfile to the actual SDK version
Expand Down
9 changes: 5 additions & 4 deletions build_library/catalyst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ sharedir="/usr/share/catalyst"
storedir="$CATALYST_ROOT"
distdir="$DISTDIR"
envscript="$TEMPDIR/catalystrc"
envvars=[$(printf '"%s", ' $(< sdk_lib/env_rclone.txt))]
Comment thread
chewi marked this conversation as resolved.
Resolved
port_logdir="$CATALYST_ROOT/log"
repo_basedir="/mnt/host/source/src/third_party"
repo_name="gentoo"
EOF
}

catalystrc() {
local load=$((NUM_JOBS * 2))
cat <<EOF
export TERM='${TERM}'
portageq envvar -v {FETCH,RESUME}COMMAND | sed 's:^:export :'
local load=$((NUM_JOBS * 2))
cat <<EOF
export MAKEOPTS='--jobs=${NUM_JOBS} --load-average=${load}'
export EMERGE_DEFAULT_OPTS="--verbose \$MAKEOPTS"
export PORTAGE_USERNAME=portage
export PORTAGE_GRPNAME=portage
export GENTOO_MIRRORS='$(portageq envvar GENTOO_MIRRORS)'
export FETCH_WRAPPER="/etc/portage/bin/fetch-wrapper"
export ac_cv_posix_semaphores_enabled=yes
EOF
}
Expand Down
109 changes: 109 additions & 0 deletions build_library/portage/bin/fetch-wrapper
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=*)
Comment thread
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
4 changes: 3 additions & 1 deletion ci-automation/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#
# 4. A file ../scripts.patch to apply with "git am -3" for the scripts repo.
#
# 5. RCLONE_S3_*. Environment variables. Credentials for mirroring Portage distfiles. See rclone's documentation.
#
# OUTPUT:
#
# 1. Exported container image "flatcar-packages-[ARCH]-[VERSION].tar.gz" with binary packages
Expand Down Expand Up @@ -91,7 +93,7 @@ function _packages_build_impl() {
# Build packages; store packages in container
failed=''
./run_sdk_container -x ./ci-cleanup.sh -n "${packages_container}" -v "${vernum}" \
-C "${sdk_image}" \
-C "${sdk_image}" -e "${!RCLONE_S3_*}" \
./build_packages --board="${arch}-usr" || failed=x

# Copy the build logs to a directory accessible for us.
Expand Down
57 changes: 16 additions & 41 deletions ci-automation/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,41 +156,26 @@ function copy_from_bincache_to_bucket() {
local arch="${2}"
local version="${3}"

rclone_configuration_file="$(mktemp)"
chmod 600 "${rclone_configuration_file}"

(
trap "rm -f ${rclone_configuration_file}" EXIT
echo "${RCLONE_CONFIGURATION_FILE}" | base64 --decode > "${rclone_configuration_file}"

echo "Copying the images from bincache to CloudFlare bucket"
docker run --rm --net host \
-v "${rclone_configuration_file}:/opt/rclone.conf:ro" \
docker.io/rclone/rclone:1.71.1 \
--config "/opt/rclone.conf" \
echo "Copying the images from bincache to Cloudflare bucket"
docker run --rm --net host --env-file="sdk_lib/env_rclone.txt" \
Comment thread
chewi marked this conversation as resolved.
Resolved
docker.io/rclone/rclone:1.76.0 \
sync \
--http-url "https://${BUILDCACHE_SERVER}/images/${arch}/${version}" :http: "r2:flatcar/${channel}/${arch}-usr/${version}" || { echo "ERROR: Skipping images copy to bucket due to failure" ; }
--http-url "https://${BUILDCACHE_SERVER}/images/${arch}/${version}" :http: ":s3:flatcar/${channel}/${arch}-usr/${version}" || { echo "ERROR: Skipping images copy to bucket due to failure" ; }

echo "Copying the binary packages from bincache to CloudFlare bucket"
docker run --rm --net host \
-v "${rclone_configuration_file}:/opt/rclone.conf:ro" \
docker.io/rclone/rclone:1.71.1 \
--config "/opt/rclone.conf" \
echo "Copying the binary packages from bincache to Cloudflare bucket"
docker run --rm --net host --env-file="sdk_lib/env_rclone.txt" \
docker.io/rclone/rclone:1.76.0 \
sync \
--http-url "https://${BUILDCACHE_SERVER}/boards/${arch}-usr/${version}" :http: "r2:flatcar/mirror/boards/${arch}-usr/${version}" || { echo "ERROR: Skipping binary packages copy to bucket due to failure" ; }
--http-url "https://${BUILDCACHE_SERVER}/boards/${arch}-usr/${version}" :http: ":s3:flatcar/mirror/boards/${arch}-usr/${version}" || { echo "ERROR: Skipping binary packages copy to bucket due to failure" ; }

# Only copy once the 'containers' artifacts
if [ "${arch}" = "amd64" ]; then
echo "Copying SDK and packages containers from bincache to CloudFlare bucket"
docker run --rm --net host \
-v "${rclone_configuration_file}:/opt/rclone.conf:ro" \
docker.io/rclone/rclone:1.71.1 \
--config "/opt/rclone.conf" \
echo "Copying SDK and packages containers from bincache to Cloudflare bucket"
docker run --rm --net host --env-file="sdk_lib/env_rclone.txt" \
docker.io/rclone/rclone:1.76.0 \
sync \
--http-url "https://${BUILDCACHE_SERVER}/containers/${version}" :http: "r2:flatcar/mirror/containers/${version}" || { echo "ERROR: Skipping containers copy (SDK / packages) to bucket due to failure" ; }
--http-url "https://${BUILDCACHE_SERVER}/containers/${version}" :http: ":s3:flatcar/mirror/containers/${version}" || { echo "ERROR: Skipping containers copy (SDK / packages) to bucket due to failure" ; }
fi

)
}

function publish_sdk() {
Expand All @@ -215,21 +200,11 @@ function publish_sdk() {
docker push "${sdk_container_common_registry}/flatcar-sdk-${a}:${docker_sdk_vernum}"
done

rclone_configuration_file="$(mktemp)"
chmod 600 "${rclone_configuration_file}"

(
trap "rm -f ${rclone_configuration_file}" EXIT
echo "${RCLONE_CONFIGURATION_FILE}" | base64 --decode > "${rclone_configuration_file}"

echo "Copying the SDK from bincache to CloudFlare bucket"
docker run --rm --net host \
-v "${rclone_configuration_file}:/opt/rclone.conf:ro" \
docker.io/rclone/rclone:1.71.1 \
--config "/opt/rclone.conf" \
echo "Copying the SDK from bincache to Cloudflare bucket"
docker run --rm --net host --env-file="sdk_lib/env_rclone.txt" \
docker.io/rclone/rclone:1.76.0 \
sync \
--http-url "https://${BUILDCACHE_SERVER}/sdk/amd64/${docker_sdk_vernum}" :http: "r2:flatcar/mirror/sdk/amd64/${docker_sdk_vernum}" || { echo "ERROR: Skipping SDK copy to bucket due to failure" ; }
)
--http-url "https://${BUILDCACHE_SERVER}/sdk/amd64/${docker_sdk_vernum}" :http: ":s3:flatcar/mirror/sdk/amd64/${docker_sdk_vernum}" || { echo "ERROR: Skipping SDK copy to bucket due to failure" ; }
}

function _release_build_impl() {
Expand Down
2 changes: 2 additions & 0 deletions ci-automation/sdk_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
# 8. SEED_TARBALL. Environment variable. Overrides the default seed tarball
# from the given seed SDK. A Gentoo stage3 tarball URL can be used here.
#
# 9. RCLONE_S3_*. Environment variables. Credentials for mirroring Portage distfiles. See rclone's documentation.
#
# OUTPUT:
#
# 1. SDK tarball (gentoo catalyst output) of the new SDK, pushed to buildcache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ USE="${USE} bindist"
ACCEPT_LICENSE="${ACCEPT_LICENSE} no-source-code
linux-fw-redistributable freedist intel-ucode NVIDIA-2023 NVIDIA-2025"

# Favor our own mirrors over Gentoo's
GENTOO_MIRRORS="
https://mirror.release.flatcar-linux.net/coreos/
http://distfiles.gentoo.org/
"
# Flatcar's mirror has sources from all recent CI builds. Ideally, we wouldn't
# include Gentoo's mirror because we don't want to spam them with requests for
# Flatcar-only sources, but their own gitweb instance is the upstream source for
# many packages and is currently very unreliable. Other mirrors presumably
# manage to download these after several tries. *DO NOT* add extra whitespace
# here. If this is modified, you *MUST* update the fetch-wrapper script.
GENTOO_MIRRORS="https://mirror.release.flatcar-linux.net https://distfiles.gentoo.org"

# The following files are modified by make_chroot, and we do not want to
# clobber them. All other config files should not be protected, so we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
CROS_BUILD_BOARD_TREE="${SYSROOT}/build"
CROS_ADDONS_TREE="/mnt/host/source/src/third_party/coreos-overlay/coreos"

# Ensure sensitive credentials used for mirroring don't make it into the build
# environment where they could be stolen. fetch-wrapper is unaffected by this.
unset "${!RCLONE_S3_@}"

# Are we merging for the board sysroot, or for the SDK, or for
# the images? Returns a string in a passed variable:
#
Expand Down
2 changes: 1 addition & 1 deletion sdk_lib/Dockerfile.sdk-import
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ COPY --chown=sdk:sdk . /mnt/host/source/src/scripts
RUN chown sdk:sdk /mnt/host/source

RUN --mount=type=bind,target=/mnt/host/source/src/scripts \
cat /mnt/host/source/src/scripts/sdk_lib/env_{pass,keep}.txt | \
cat /mnt/host/source/src/scripts/sdk_lib/env_{pass,keep,rclone}.txt | \
sed -e '1i Defaults env_keep += " \\' -e 's:$: \\:' -e '$a "' | \
install -m0440 /dev/stdin /etc/sudoers.d/90_env_keep

Expand Down
4 changes: 4 additions & 0 deletions sdk_lib/env_rclone.txt
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
2 changes: 1 addition & 1 deletion setup_board
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ sudo_clobber "${BOARD_ETC}/portage/make.conf" <<EOF
# Settings derived from the host environment
CBUILD="$(portageq envvar CHOST)"
HOSTCC="$(portageq envvar CHOST)-gcc"
$(portageq envvar -v DISTDIR GLSA_DIR MAKEOPTS PORTAGE_USERNAME FETCHCOMMAND RESUMECOMMAND | sed 's:\$:\\$:g')
$(portageq envvar -v DISTDIR FETCH_WRAPPER GLSA_DIR MAKEOPTS PORTAGE_USERNAME FETCHCOMMAND RESUMECOMMAND | sed 's:\$:\\$:g')

# Board specific settings
CHOST="${BOARD_CHOST}"
Expand Down
5 changes: 3 additions & 2 deletions update_chroot
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ PORT_LOGDIR="/var/log/portage"
PORTAGE_BINHOST="$PORTAGE_BINHOST"
PORTAGE_USERNAME="${PORTAGE_USERNAME}"
MAKEOPTS="--jobs=${NUM_JOBS} --load-average=$((NUM_JOBS * 2))"
FETCHCOMMAND='wget -t 3 -T 60 --passive-ftp -U "Portage (Flatcar SDK ${FLATCAR_SDK_VERSION}, https://www.flatcar.org) distfile-fetch" -O "\\\${DISTDIR}/\\\${FILE}" "\\\${URI}"'
RESUMECOMMAND='wget -c -t 3 -T 60 --passive-ftp -U "Portage (Flatcar SDK ${FLATCAR_SDK_VERSION}, https://www.flatcar.org) distfile-fetch" -O "\\\${DISTDIR}/\\\${FILE}" "\\\${URI}"'
FETCHCOMMAND='wget -t 3 -T 60 --passive-ftp -U "Portage (Flatcar SDK ${FLATCAR_SDK_VERSION}, flatcar.org) distfile-fetch" -O "\\\${DISTDIR}/\\\${FILE}" "\\\${URI}"'
RESUMECOMMAND='wget -c -t 3 -T 60 --passive-ftp -U "Portage (Flatcar SDK ${FLATCAR_SDK_VERSION}, flatcar.org) distfile-fetch" -O "\\\${DISTDIR}/\\\${FILE}" "\\\${URI}"'
FETCH_WRAPPER="${BUILD_LIBRARY_DIR}/portage/bin/fetch-wrapper"

# Generally there isn't any need to add packages to @world by default.
# You can use --select to override this.
Expand Down