build_image: use dev and prod profile variants

Instead of gluing in a special PROD_INSTALL_MASK for all images use
profiles to configure the differences between the base build root,
production images, and developer images. This offers much more
flexibility and is needed for providing a full dev environment in
developer images.
This commit is contained in:
Michael Marineau 2014-07-19 17:17:28 -07:00
parent 4d3c198161
commit a28a8966e4
3 changed files with 24 additions and 15 deletions

View File

@ -98,23 +98,26 @@ generate_update() {
# to the basic emerge command.
emerge_to_image() {
local root_fs_dir="$1"; shift
local mask="${INSTALL_MASK:-$(portageq-$BOARD envvar PROD_INSTALL_MASK)}"
test -n "$mask" || die "PROD_INSTALL_MASK not defined"
local emerge_cmd
emerge_cmd="emerge-$BOARD"
emerge_cmd+=" --root-deps=rdeps --usepkgonly -v"
if [[ $FLAGS_jobs -ne -1 ]]; then
emerge_cmd+=" --jobs=$FLAGS_jobs"
fi
sudo -E INSTALL_MASK="$mask" ${emerge_cmd} --root="${root_fs_dir}" "$@"
sudo -E ROOT="${root_fs_dir}" \
PORTAGE_CONFIGROOT="${BUILD_DIR}"/configroot \
emerge --root-deps=rdeps --usepkgonly --jobs=$FLAGS_jobs -v "$@"
# Make sure profile.env and ld.so.cache has been generated
sudo -E ROOT="${root_fs_dir}" env-update
}
# Switch to the dev or prod sub-profile
set_image_profile() {
local suffix="$1"
local profile="${BUILD_DIR}/configroot/etc/portage/make.profile"
if [[ ! -d "${profile}/${suffix}" ]]; then
die "Not a valid profile: ${profile}/${suffix}"
fi
local realpath=$(readlink -f "${profile}/${suffix}")
ln -snf "${realpath}" "${profile}"
}
# Usage: systemd_enable /root default.target something.service
# Or: systemd_enable /root default.target some@.service some@thing.service
systemd_enable() {
@ -156,6 +159,10 @@ start_image() {
local disk_img="${BUILD_DIR}/${image_name}"
mkdir -p "${BUILD_DIR}"/configroot/etc/portage
ln -s "${BOARD_ROOT}"/etc/portage/* \
"${BUILD_DIR}"/configroot/etc/portage/
info "Using image type ${disk_layout}"
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
format "${disk_img}"
@ -165,8 +172,7 @@ start_image() {
trap "cleanup_mounts '${root_fs_dir}' && delete_prompt" EXIT
# First thing first, install baselayout to create a working filesystem.
emerge-${BOARD} --root="${root_fs_dir}" \
--usepkgonly --oneshot --quiet --nodeps sys-apps/baselayout
emerge_to_image "${root_fs_dir}" --nodeps --oneshot sys-apps/baselayout
# FIXME(marineam): Work around glibc setting EROOT=$ROOT
# https://bugs.gentoo.org/show_bug.cgi?id=473728#c12
@ -222,6 +228,7 @@ finish_image() {
sudo fstrim "${root_fs_dir}/usr" || true
fi
rm -rf "${BUILD_DIR}"/configroot
cleanup_mounts "${root_fs_dir}"
trap - EXIT
}

View File

@ -71,6 +71,7 @@ create_dev_image() {
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}"
set_image_profile dev
emerge_to_image "${root_fs_dir}" coreos-base/coreos-dev
write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}"

View File

@ -7,8 +7,8 @@
# In prod images we only need the shared libraries.
emerge_prod_gcc() {
local root_fs_dir="$1"; shift
local mask="${INSTALL_MASK:-$(portageq-$BOARD envvar PROD_INSTALL_MASK)}"
test -n "$mask" || die "PROD_INSTALL_MASK not defined"
local mask="${INSTALL_MASK:-$(portageq-$BOARD envvar INSTALL_MASK)}"
test -n "$mask" || die "INSTALL_MASK not defined"
mask="${mask}
/usr/bin
@ -38,6 +38,7 @@ create_prod_image() {
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}"
# Install minimal GCC (libs only) and then everything else
set_image_profile prod
emerge_prod_gcc "${root_fs_dir}"
emerge_to_image "${root_fs_dir}" coreos-base/coreos
write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}"