refactor(base_image_util): Split into two functions.

Use what was the base image build function as setup/finalize steps in
the dev and prod build functions. This eliminates duplicate code
that mounted and unmounted the filesystem images.
This commit is contained in:
Michael Marineau 2014-03-27 18:21:45 -07:00
parent 39086358bf
commit 1836d5998d
5 changed files with 34 additions and 46 deletions

View File

@ -102,8 +102,6 @@ for arg in "$@"; do
esac
done
BASE_PACKAGE="coreos-base/coreos"
eclean-$BOARD -d packages
if [[ ${skip_blacklist_check} -ne 1 ]]; then
@ -139,14 +137,12 @@ mkdir -p "${BUILD_DIR}"
DISK_LAYOUT="${FLAGS_disk_layout:-base}"
if [[ "${DEV_IMAGE}" -eq 1 ]]; then
create_base_image ${COREOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group}
install_dev_packages ${COREOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT}
create_dev_image ${COREOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group}
upload_image "${BUILD_DIR}/${COREOS_DEVELOPER_IMAGE_NAME}"
fi
if [[ "${PROD_IMAGE}" -eq 1 ]]; then
create_base_image ${COREOS_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group}
setup_prod_image ${COREOS_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT}
create_prod_image ${COREOS_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group}
upload_image "${BUILD_DIR}/${COREOS_PRODUCTION_IMAGE_NAME}"
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then
generate_update "${COREOS_PRODUCTION_IMAGE_NAME}" ${DISK_LAYOUT}

View File

@ -2,13 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
create_base_image() {
start_image() {
local image_name=$1
local disk_layout=$2
local update_group="$3"
local root_fs_dir=$3
local disk_img="${BUILD_DIR}/${image_name}"
local root_fs_dir="${BUILD_DIR}/rootfs"
info "Using image type ${disk_layout}"
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
@ -26,16 +25,12 @@ create_base_image() {
# FIXME(marineam): Work around glibc setting EROOT=$ROOT
# https://bugs.gentoo.org/show_bug.cgi?id=473728#c12
sudo mkdir -p "${root_fs_dir}/etc/ld.so.conf.d"
}
# We "emerge --root=${root_fs_dir} --root-deps=rdeps --usepkgonly" all of the
# runtime packages for chrome os. This builds up a chrome os image from
# binary packages with runtime dependencies only. We use INSTALL_MASK to
# trim the image size as much as possible.
emerge_prod_gcc --root="${root_fs_dir}"
emerge_to_image --root="${root_fs_dir}" ${BASE_PACKAGE}
# Make sure profile.env and ld.so.cache has been generated
sudo ROOT="${root_fs_dir}" env-update
finish_image() {
local disk_layout=$1
local root_fs_dir=$2
local update_group=$3
# Record directories installed to the state partition.
# Explicitly ignore entries covered by existing configs.

View File

@ -107,6 +107,7 @@ generate_update() {
# Arguments to this command are passed as addition options/arguments
# 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"
@ -122,12 +123,16 @@ emerge_to_image() {
emerge_cmd+=" --jobs=$FLAGS_jobs"
fi
sudo -E INSTALL_MASK="$mask" ${emerge_cmd} "$@"
sudo -E INSTALL_MASK="$mask" ${emerge_cmd} --root="${root_fs_dir}" "$@"
# Make sure profile.env and ld.so.cache has been generated
sudo -E ROOT="${root_fs_dir}" env-update
}
# The GCC package includes both its libraries and the compiler.
# 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"
@ -143,5 +148,5 @@ emerge_prod_gcc() {
/usr/share/gcc-data/*/*/c99
/usr/share/gcc-data/*/*/python"
INSTALL_MASK="${mask}" emerge_to_image --nodeps sys-devel/gcc "$@"
INSTALL_MASK="${mask}" emerge_to_image "${root_fs_dir}" --nodeps sys-devel/gcc "$@"
}

View File

@ -50,11 +50,10 @@ detect_dev_url() {
fi
}
# Modifies an existing image to add development packages.
# Takes as an arg the name of the image to be created.
install_dev_packages() {
create_dev_image() {
local image_name=$1
local disk_layout=$2
local update_group=$3
local devserver=$(detect_dev_url)
local auserver=""
@ -65,18 +64,16 @@ install_dev_packages() {
info "Unable do detect local dev server address."
fi
info "Adding developer packages to ${image_name}"
info "Building developer image ${image_name}"
local root_fs_dir="${BUILD_DIR}/rootfs"
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
mount "${BUILD_DIR}/${image_name}" "${root_fs_dir}"
trap "cleanup_mounts '${root_fs_dir}' && delete_prompt" EXIT
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}"
# Install developer packages described in coreos-dev.
emerge_to_image --root="${root_fs_dir}" coreos-base/coreos-dev
emerge_to_image "${root_fs_dir}" coreos-base/coreos-dev
# Make sure profile.env and ld.so.cache has been generated
sudo ROOT="${root_fs_dir}" env-update
"${BUILD_LIBRARY_DIR}/set_lsb_release" \
--root="${root_fs_dir}" \
--board="${BOARD}"
# Setup portage for emerge and gmerge
configure_dev_portage "${root_fs_dir}" "${devserver}"
@ -101,12 +98,5 @@ EOF
sudo mkdir -p "${fs_wants}"
sudo ln -s ../remount-usr.service "${fs_wants}"
# Zero all fs free space, not fatal since it won't work on linux < 3.2
sudo fstrim "${root_fs_dir}" || true
sudo fstrim "${root_fs_dir}/usr" || true
info "Developer image built and stored at ${image_name}"
cleanup_mounts "${root_fs_dir}"
trap - EXIT
finish_image "${disk_layout}" "${root_fs_dir}" "${update_group}"
}

View File

@ -3,16 +3,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
setup_prod_image() {
create_prod_image() {
local image_name="$1"
local disk_layout="$2"
local update_group="$3"
info "Configuring production image ${image_name}"
info "Building production image ${image_name}"
local root_fs_dir="${BUILD_DIR}/rootfs"
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
mount "${BUILD_DIR}/${image_name}" "${root_fs_dir}"
trap "cleanup_mounts '${root_fs_dir}' && delete_prompt" EXIT
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}"
# Install minimal GCC (libs only) and then everything else
emerge_prod_gcc "${root_fs_dir}"
emerge_to_image "${root_fs_dir}" coreos-base/coreos
# clean-ups of things we do not need
sudo rm ${root_fs_dir}/etc/csh.env
@ -38,8 +41,7 @@ EOF
sudo rm ${root_fs_dir}/etc/xinetd.d/rsyncd
sudo rmdir ${root_fs_dir}/etc/xinetd.d
cleanup_mounts "${root_fs_dir}"
trap - EXIT
finish_image "${disk_layout}" "${root_fs_dir}" "${update_group}"
# Make the filesystem un-mountable as read-write.
if [ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]; then