Merge pull request #21 from philips/building-of-production-coreos-images

Building of production coreos images
This commit is contained in:
Brandon Philips 2013-07-05 14:13:52 -07:00
commit 2ca214d738
5 changed files with 41 additions and 341 deletions

View File

@ -1,196 +0,0 @@
#!/bin/bash
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Script to build a bootable keyfob-based chromeos system image from within
# a chromiumos setup. This assumes that all needed packages have been built into
# the given target's root with binary packages turned on. This script will
# build the Chrome OS image using only pre-built binary packages.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
# Developer-visible flags.
DEFINE_string board "${DEFAULT_BOARD}" \
"The board to build an image for."
DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/containers" \
"Directory in which to place image result directories (named by version)"
FLAGS_HELP="USAGE: build_image [flags] [list of images to build].
This script is used to build a CoreOS container. CoreOS comes in many
different forms. This scripts can be used to build the following:
base - Pristine Chromium OS image. As similar to Chrome OS as possible.
dev - Developer image. Like base but with additional developer packages.
test - Like dev, but with additional test specific packages and can be easily
used for automated testing using scripts like run_remote_tests, etc.
Examples:
build_image --board=<board> dev test - builds developer and test images.
build_image --board=<board> factory_install - builds a factory install shim.
...
"
show_help_if_requested "$@"
# The following options are advanced options, only available to those willing
# to read the source code. They are not shown in help output, since they are
# not needed for the typical developer workflow.
DEFINE_integer build_attempt 1 \
"The build attempt for this image build."
DEFINE_integer jobs -1 \
"How many packages to build in parallel at maximum."
DEFINE_boolean replace ${FLAGS_FALSE} \
"Overwrite existing output, if any."
DEFINE_string symlink "latest" \
"Symlink name to use for this image."
DEFINE_string version "" \
"Overrides version number in name to this version."
# Parse command line.
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
# N.B. Ordering matters for some of the libraries below, because
# some of the files contain initialization used by later files.
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/base_container_util.sh" || exit 1
parse_build_image_args
for overlay in $(cros_list_overlays --board "$BOARD"); do
setup_sh="${overlay}/scripts/board_specific_setup.sh"
if [[ -e ${setup_sh} ]]; then
source "${setup_sh}"
fi
done
# TODO: <prebuild hook>
BASE_PACKAGE="coreos-base/coreos"
# Tweak flags, configure extra USE flags, and set base packages for the factory
# install shim.
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
# TODO: Build a separated ebuild for the install shim to reduce size.
INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}"
# Add the cros_factory_install boot arg.
FLAGS_boot_args="${FLAGS_boot_args} cros_factory_install"
BASE_PACKAGE="coreos-base/chromeos-installshim"
export USE="${USE} initramfs vfat tpm i2cdev"
# On ARM, fbconsole is required to fix a display driver bug.
if [ "${ARCH}" = "arm" ] ; then
export USE="${USE} fbconsole"
fi
fi
if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
# Disable module restrictions on factory test image to allow for
# external third party drivers in /usr/local.
FLAGS_boot_args="${FLAGS_boot_args} lsm.module_locking=0"
fi
# TODO: </prebuild hook>
# If we are creating a developer image, also create a pristine image with a
# different name.
PRISTINE_IMAGE_NAME=
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}
else
PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
fi
DEVKEYSDIR="/usr/share/vboot/devkeys"
eclean-$BOARD -d packages
if [[ ${skip_blacklist_check} -ne 1 ]]; then
check_blacklist
fi
# Check that the build root is sane.
if [[ ${skip_test_build_root} -ne 1 ]]; then
"${BUILD_LIBRARY_DIR}/test_build_root" --root="${BOARD_ROOT}"
fi
# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
# ToDo(msb): remove this hack.
PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
# Handle existing directory.
if [[ -e "${BUILD_DIR}" ]]; then
if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
sudo rm -rf "${BUILD_DIR}"
else
error "Directory ${BUILD_DIR} already exists."
error "Use --build_attempt option to specify an unused attempt."
error "Or use --replace if you want to overwrite this directory."
die "Unwilling to overwrite ${BUILD_DIR}."
fi
fi
# Create the output directory and temporary mount points.
mkdir -p "${BUILD_DIR}"
# Create the base image.
create_base_container ${PRISTINE_IMAGE_NAME} ${FLAGS_enable_rootfs_verification} \
${FLAGS_enable_bootcache}
# Running board-specific setup if any exists.
if type board_setup &>/dev/null; then
board_setup "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}"
fi
# Create a developer image if an image that is based on it is requested.
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \
${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME}
fi
# Generating AU generator zip file to run outside chroot
generate_au_zip || echo "Failed generating AU zip file - ignoring Error..."
# Create a named symlink.
LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}"
ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME}
echo "Done. Image(s) created in ${BUILD_DIR}"
# Print out the images we generated.
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then
echo "Non-developer Chromium OS container created as ${PRISTINE_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then
echo "Developer container created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
echo "Factory test container created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
echo "Test container created as ${CHROMEOS_TEST_IMAGE_NAME}"
fi
command_completed
cat << EOF
systemd-nspawn -b -D ${OUTSIDE_OUTPUT_DIR}
EOF

View File

@ -35,22 +35,18 @@ DEFINE_string enable_serial "" \
"Enable serial port for printks. Example values: ttyS0"
FLAGS_HELP="USAGE: build_image [flags] [list of images to build].
This script is used to build a Chromium OS image. Chromium OS comes in many
This script is used to build a CoreOS image. CoreOS comes in many
different forms. This scripts can be used to build the following:
base - Pristine Chromium OS image. As similar to Chrome OS as possible.
base - Pristine CoreOS image for generating update payloads or a dev/prod image.
prod - Production image for CoreOS. This image is for booting.
dev - Developer image. Like base but with additional developer packages.
test - Like dev, but with additional test specific packages and can be easily
used for automated testing using scripts like run_remote_tests, etc.
factory_test - Like test but with extra packages and modifications used to
test images in a factory setting. Cannot be built along with a test image.
factory_install - Install shim for bootstrapping the factory test process.
Cannot be built along with any other image.
Examples:
build_image --board=<board> dev test - builds developer and test images.
build_image --board=<board> factory_install - builds a factory install shim.
...
"
show_help_if_requested "$@"
@ -110,44 +106,9 @@ for overlay in $(cros_list_overlays --board "$BOARD"); do
fi
done
# TODO: <prebuild hook>
BASE_PACKAGE="coreos-base/coreos"
# Tweak flags, configure extra USE flags, and set base packages for the factory
# install shim.
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
# TODO: Build a separated ebuild for the install shim to reduce size.
INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}"
# Add the cros_factory_install boot arg.
FLAGS_boot_args="${FLAGS_boot_args} cros_factory_install"
BASE_PACKAGE="coreos-base/chromeos-installshim"
export USE="${USE} initramfs vfat tpm i2cdev"
# On ARM, fbconsole is required to fix a display driver bug.
if [ "${ARCH}" = "arm" ] ; then
export USE="${USE} fbconsole"
fi
fi
if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
# Disable module restrictions on factory test image to allow for
# external third party drivers in /usr/local.
FLAGS_boot_args="${FLAGS_boot_args} lsm.module_locking=0"
fi
# TODO: </prebuild hook>
# If we are creating a developer image, also create a pristine image with a
# different name.
PRISTINE_IMAGE_NAME=
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}
else
PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
fi
PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
DEVKEYSDIR="/usr/share/vboot/devkeys"
@ -193,21 +154,22 @@ fi
# Create a developer image if an image that is based on it is requested.
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \
${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
${CHROMEOS_TEST_IMAGE_NAME}; then
copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME}
install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME}
fi
if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then
copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${COREOS_PRODUCTION_IMAGE_NAME}
${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \
${COREOS_PRODUCTION_IMAGE_NAME}
fi
# From a developer image create a test|factory_test image.
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME}
mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME}
fi
if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \
${CHROMEOS_FACTORY_TEST_IMAGE_NAME}
mod_image_for_test ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}
fi
# Generating AU generator zip file to run outside chroot
generate_au_zip || echo "Failed generating AU zip file - ignoring Error..."
@ -218,28 +180,34 @@ ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME}
echo "Done. Image(s) created in ${BUILD_DIR}"
print_image_to_vm() {
flags=
if [ $# = 1 ]; then
flags="--${1}_image"
fi
cat << EOF
To convert it to a VMWare image, use:
./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD} ${flags}
EOF
}
# Print out the images we generated.
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then
echo "Non-developer Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then
echo "CoreOS Production image created as ${COREOS_PRODUCTION_IMAGE_NAME}"
print_image_to_vm "prod"
fi
if should_build_image ${CHROMEOS_FACTORY_SHIM_NAME}; then
echo "Chromium OS Factory install shim created as ${PRISTINE_IMAGE_NAME}"
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then
echo "Non-developer CoreOS image created as ${PRISTINE_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then
echo "Developer image created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
echo "Factory test image created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
fi
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
echo "Test image created as ${CHROMEOS_TEST_IMAGE_NAME}"
print_image_to_vm "test"
fi
command_completed
cat << EOF
To copy the image to a USB key, use:
./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR}
To convert it to a VMWare image, use:
./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}
EOF

View File

@ -36,6 +36,9 @@ get_images_to_build() {
for image_to_build in $*; do
# Shflags leaves "'"s around ARGV.
case ${image_to_build} in
\'prod\' )
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${COREOS_PRODUCTION_IMAGE_NAME}"
;;
\'base\' )
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_BASE_IMAGE_NAME}"
;;
@ -45,13 +48,6 @@ get_images_to_build() {
\'test\' )
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_TEST_IMAGE_NAME}"
;;
\'factory_test\' )
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
;;
\'factory_install\' )
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} \
${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}"
;;
* )
die "${image_to_build} is not an image specification."
;;
@ -69,25 +65,6 @@ get_images_to_build() {
# Look at flags to determine which image types we should build.
parse_build_image_args() {
get_images_to_build ${FLAGS_ARGV}
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then
die_notrace "Cannot build both the test and factory_test images."
fi
fi
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME} \
${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} \
${CHROMEOS_FACTORY_TEST_IMAGE_NAME} &&
should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
die_notrace \
"Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \
"image."
fi
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
# For factory, force rootfs verification and bootcache off
FLAGS_enable_rootfs_verification=${FLAGS_FALSE}
FLAGS_enable_bootcache=${FLAGS_FALSE}
FLAGS_bootcache_use_board_default=${FLAGS_FALSE}
fi
}
check_blacklist() {

View File

@ -400,16 +400,13 @@ CHROMEOS_IMAGE_NAME="chromiumos_image.bin"
CHROMEOS_DEVELOPER_IMAGE_NAME="chromiumos_image.bin"
CHROMEOS_RECOVERY_IMAGE_NAME="recovery_image.bin"
CHROMEOS_TEST_IMAGE_NAME="chromiumos_test_image.bin"
CHROMEOS_FACTORY_TEST_IMAGE_NAME="chromiumos_factory_image.bin"
CHROMEOS_FACTORY_INSTALL_SHIM_NAME="factory_install_shim.bin"
COREOS_BASE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
COREOS_IMAGE_NAME=${CHROMEOS_IMAGE_NAME}
COREOS_DEVELOPER_IMAGE_NAME=${CHROMEOS_DEVELOPER_IMAGE_NAME}
COREOS_PRODUCTION_IMAGE_NAME="coreos_production_image.bin"
COREOS_RECOVERY_IMAGE_NAME=${CHROMEOS_RECOVERY_IMAGE_NAME}
COREOS_TEST_IMAGE_NAME=${CHROMEOS_TEST_IMAGE_NAME}
COREOS_FACTORY_TEST_IMAGE_NAME=${CHROMEOS_FACTORY_TEST_IMAGE_NAME}
COREOS_FACTORY_INSTALL_SHIM_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}
# Install make for portage ebuilds. Used by build_image and gmergefs.
# TODO: Is /usr/local/autotest-chrome still used by anyone?
@ -453,51 +450,6 @@ DEFAULT_INSTALL_MASK="
test_*.ko
"
# Mask for factory test image (build_image --factory)
FACTORY_TEST_INSTALL_MASK="
${COMMON_INSTALL_MASK}
*/.svn
*/CVS
/usr/local/autotest/[^c]*
/usr/local/autotest/conmux
/usr/local/autotest/client/deps/chrome_test
/usr/local/autotest/client/deps/piglit
/usr/local/autotest/client/deps/pyauto_dep
/usr/local/autotest/client/deps/realtimecomm_*
/usr/local/autotest/client/site_tests/graphics_WebGLConformance
/usr/local/autotest/client/site_tests/platform_ToolchainOptions
/usr/local/autotest/client/site_tests/realtimecomm_GTalk*
/usr/local/autotest/client/tests
/usr/local/factory/bundle
"
# Mask for factory install shim (build_image factory_install)
FACTORY_SHIM_INSTALL_MASK="
${DEFAULT_INSTALL_MASK}
/opt/[^g]*
/opt/google/chrome
/opt/google/o3d
/opt/google/talkplugin
/usr/lib/dri
/usr/lib/python2.6/test
/usr/lib64/dri
/usr/local/autotest-pkgs
/usr/share/X11
/usr/share/chewing
/usr/share/chromeos-assets
/usr/share/fonts
/usr/share/ibus-pinyin
/usr/share/libhangul
/usr/share/locale
/usr/share/m17n
/usr/share/mime
/usr/share/oem
/usr/share/pyzy
/usr/share/sounds
/usr/share/tts
/usr/share/zoneinfo
"
# -----------------------------------------------------------------------------
# Functions

View File

@ -25,10 +25,8 @@ DEFINE_string adjust_part "" \
"Adjustments to apply to the partition table"
DEFINE_string board "${DEFAULT_BOARD}" \
"Board for which the image was built"
DEFINE_boolean factory $FLAGS_FALSE \
"Modify the image for manufacturing testing"
DEFINE_boolean factory_install $FLAGS_FALSE \
"Modify the image for factory install shim"
DEFINE_boolean prod $FLAGS_FALSE \
"Build prod image"
# We default to TRUE so the buildbot gets its image. Note this is different
# behavior from image_to_usb.sh
@ -47,6 +45,8 @@ DEFINE_string state_image "" \
"Stateful partition image (defaults to creating new statful partition)"
DEFINE_boolean test_image "${FLAGS_FALSE}" \
"Copies normal image to ${CHROMEOS_TEST_IMAGE_NAME}, modifies it for test."
DEFINE_boolean prod_image "${FLAGS_FALSE}" \
"Copies normal image to ${COREOS_OFFICIAL_IMAGE_NAME}, modifies it for test."
DEFINE_string to "" \
"Destination folder for VM output file(s)"
DEFINE_string vbox_disk "${DEFAULT_VBOX_DISK}" \
@ -91,8 +91,8 @@ if [ -z "${FLAGS_to}" ] ; then
FLAGS_to="${FLAGS_from}"
fi
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
SRC_IMAGE="${FLAGS_from}/${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
if [ ${FLAGS_prod_image} -eq ${FLAGS_TRUE} ]; then
SRC_IMAGE="${FLAGS_from}/${COREOS_PRODUCTION_IMAGE_NAME}"
elif [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]; then
SRC_IMAGE="${FLAGS_from}/${CHROMEOS_TEST_IMAGE_NAME}"
else
@ -248,8 +248,7 @@ fi
if [ "${FLAGS_format}" == "qemu" ]; then
echo "If you have qemu-kvm installed, you can start the image by:"
echo "qemu-kvm -m ${FLAGS_mem} -curses -pidfile /tmp/kvm.pid -net nic,model=virtio \\"
echo " -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::8080-:8080,hostfwd=::8000-:8000 \\"
echo " -hda ${FLAGS_to}/${DEFAULT_QEMU_IMAGE}"
echo " -net user,hostfwd=tcp::2222-:22 -hda ${FLAGS_to}/${DEFAULT_QEMU_IMAGE}"
echo "SSH into the host with:"
echo "ssh 127.0.0.1 -p 2222"
fi