flatcar-scripts/bootstrap_sdk
Marga Manterola e04156a0f1
bootstrap_sdk: build and upload SDK toolchain pkgs
Before, we were relying on the toolchains job to build and upload
packages that were part of the SDK. With this change, all packages that
should be part of the SDK are built and uploaded by the SDK job. The
toolchains job only builds toolchain packages specific for the release.

This change includes several adjustments done to both the SDK and the
toolchains jobs to make this work:
 * Make the SDK job build all cross toolchains, including Rust
 * Stop building Rust in the toolchains job and use the one in the SDK
   instead.
 * In toolchain_util.sh: detect when the symlink folder for crossdev
   packages is missing and run crossdev to create it during
   update_chroot setup.
 * Make it possible to build the SDK starting from stage 4 instead of
   stage 1, to make the SDK building faster for PR branches / nightlies
   (full build should still be done for releases / weeklies).
2020-06-29 15:18:55 +05:30

116 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This uses Gentoo's catalyst for very thoroughly building images from
# scratch. Using images based on this will eliminate some of the hackery
# in make_chroot.sh for building up the sdk from a stock stage3 tarball.
#
# For reference the procedure it performs is this:
#
# 1. snapshot: Grab a snapshot of portage-stable. Note that overalys are
# not snapshotted.
# 2. stage1: Using a "seed" tarball as a build environment, build a
# minimal root file system into a clean directory using ROOT=...
# and USE=-* The restricted USE flags are key be small and avoid
# circular dependencies.
# 3. stage2: Run portage-stable/scripts/bootstrap.sh
# This rebuilds the toolchain. Probably not strictly necessary most of
# the time but does super-duper-promise that the toolchain isn't linked
# to or otherwise influenced by whatever was in the "seed" tarball.
# 4. stage3: Run emerge -e system to rebuild everything using the fresh
# toolchain using the normal USE flags provided by the profile. This
# will also pull in assorted base system packages that weren't included
# in the minimal environment stage1 created.
# 5. stage4: Install any extra packages or other desired tweaks. For the
# sdk we just install all the packages normally make_chroot.sh does.
#
# Usage: bootstrap_sdk [stage1 stage2 etc]
# By default all four stages will be built using the latest stage4 as a seed.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
TYPE="flatcar-sdk"
. "${BUILD_LIBRARY_DIR}/catalyst.sh" || exit 1
# include upload options
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1
ROOT_OVERLAY=${TEMPDIR}/stage4_overlay
## Define the stage4 config template
catalyst_stage4() {
cat <<EOF
target: stage4
pkgcache_path: $BINPKGS
stage4/packages: coreos-devel/sdk-depends
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_sdk.sh
stage4/root_overlay: ${ROOT_OVERLAY}
stage4/empty: /etc/portage/repos.conf /root /usr/portage /var/cache/edb
stage4/rm: /etc/machine-id /etc/resolv.conf
EOF
catalyst_stage_default
}
# 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 "$@"
check_gsutil_opts
if [[ "$STAGES" =~ stage4 ]]; then
info "Setting release to ${FLATCAR_VERSION}"
rm -rf "${ROOT_OVERLAY}"
# need to setup the lib->lib64 symlink correctly
libdir=$(get_sdk_libdir)
mkdir -p "${ROOT_OVERLAY}/usr/${libdir}"
if [[ "${libdir}" != lib ]]; then
ln -s "${libdir}" "${ROOT_OVERLAY}/usr/lib"
fi
"${BUILD_LIBRARY_DIR}/set_lsb_release" \
--root "${ROOT_OVERLAY}"
fi
# toolchain_util.sh is required by catalyst_sdk.sh
# To copy it, we need to create /tmp with the right permissions as it will be
# used in the exported chroot.
mkdir -p "${ROOT_OVERLAY}/tmp"
chmod 1777 "${ROOT_OVERLAY}/tmp"
cp "${BUILD_LIBRARY_DIR}/toolchain_util.sh" "${ROOT_OVERLAY}/tmp"
catalyst_build
if [[ "$STAGES" =~ stage4 ]]; then
info "Build complete! Changing output name to something more sensible."
build_name="stage4-${ARCH}-${FLAGS_version}.tar.bz2"
release_name="${TYPE}-${ARCH}-${FLAGS_version}.tar.bz2"
ln -f "$BUILDS/${build_name}" "$BUILDS/${release_name}"
ln -f "$BUILDS/${build_name}.CONTENTS" "$BUILDS/${release_name}.CONTENTS"
sed -e "s/${build_name}/${release_name}/" \
"$BUILDS/${build_name}.DIGESTS" > "$BUILDS/${release_name}.DIGESTS"
# Validate we didn't break the DIGESTS with sed
verify_digests "$BUILDS/${release_name}" "$BUILDS/${release_name}.CONTENTS"
info "SDK ready: $BUILDS/${release_name}"
def_upload_path="${UPLOAD_ROOT}/sdk/${ARCH}/${FLAGS_version}"
sign_and_upload_files "tarball" "${def_upload_path}" "" \
"$BUILDS/${release_name}" \
"$BUILDS/${release_name}.CONTENTS" "$BUILDS/${release_name}.DIGESTS"
sign_and_upload_files "packages" "${def_upload_path}" "pkgs/" \
"${BINPKGS}"/*
# Upload the SDK toolchain packages
sign_and_upload_files "cross toolchain packages" "${def_upload_path}" \
"toolchain/" "${BINPKGS}/crossdev"/*
fi
command_completed