From a93cb921d838128aa0baab4ab42f3ac6cf97ec4b Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 17 May 2014 11:14:37 -0700 Subject: [PATCH 1/2] refactor(build_library): Add a function for enabling systemd units. --- build_library/build_image_util.sh | 13 +++++++++++++ build_library/dev_image_util.sh | 4 +--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index c1d3ccb120..90cf6ad05d 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -104,6 +104,19 @@ emerge_to_image() { sudo -E ROOT="${root_fs_dir}" env-update } +# Usage: systemd_enable /root default.target something.service +# Or: systemd_enable /root default.target some@.service some@thing.service +systemd_enable() { + local root_fs_dir="$1" + local target="$2" + local unit_file="$3" + local unit_alias="${4:-$3}" + local wants_dir="${root_fs_dir}/usr/lib/systemd/system/${target}.wants" + + sudo mkdir -p "${wants_dir}" + sudo ln -sf "../${unit_file}" "${wants_dir}/${unit_alias}" +} + start_image() { local image_name="$1" local disk_layout="$2" diff --git a/build_library/dev_image_util.sh b/build_library/dev_image_util.sh index cc376d8d85..ec8bddc794 100755 --- a/build_library/dev_image_util.sh +++ b/build_library/dev_image_util.sh @@ -94,9 +94,7 @@ EOF # Remount the system partition read-write by default. # The remount services are provided by coreos-base/coreos-init - local fs_wants="${root_fs_dir}/usr/lib/systemd/system/local-fs.target.wants" - sudo mkdir -p "${fs_wants}" - sudo ln -s ../remount-usr.service "${fs_wants}" + systemd_enable "${root_fs_dir}" "local-fs.target" "remount-usr.service" finish_image "${disk_layout}" "${root_fs_dir}" "${update_group}" } From 822644fc5460165c2597c284d8cfd8d6a102881d Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 17 May 2014 11:31:09 -0700 Subject: [PATCH 2/2] feat(build_image): Add support for injecting a cloud config The new --developer_data option can be used to specify a path to a cloud config to bundle into the image. If none is provided but a shared user password (for core) is set then generate a config to set that password. This lets us use the same mechanism for setting the default password for both disk and PXE images. --- build_image | 19 +++++++++++++++++++ build_library/build_image_util.sh | 8 ++++++++ build_library/vm_image_util.sh | 12 ------------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/build_image b/build_image index 39ed8446b5..5e21637fda 100755 --- a/build_image +++ b/build_image @@ -38,6 +38,8 @@ DEFINE_string group "${DEFAULT_GROUP}" \ "The update group." DEFINE_boolean generate_update "${FLAGS_FALSE}" \ "Generate update payload. (prod only)" +DEFINE_string developer_data "" \ + "Insert a custom cloudinit file into the image." # include upload options . "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1 @@ -131,6 +133,23 @@ mkdir -p "${BUILD_DIR}" DISK_LAYOUT="${FLAGS_disk_layout:-base}" +if [[ -n "${FLAGS_developer_data}" ]]; then + if [[ ! -f "${FLAGS_developer_data}" ]]; then + die_notrace "Developer data is not a file: ${FLAGS_developer_data}" + fi + info "Using developer cloudinit data: ${FLAGS_developer_data}" +elif [[ -s /etc/shared_user_passwd.txt ]]; then + FLAGS_developer_data="${BUILD_DIR}/developer_data" + info "Generating developer cloudinit with shared user password." + cat >"${FLAGS_developer_data}" <"${VM_TMP_DIR}/extra" else - # Use OEM cloud-config to setup the core user's password - if [[ -s /etc/shared_user_passwd.txt ]]; then - sudo mkdir -p "${cpio_target}/usr/share/oem" - sudo_clobber "${cpio_target}/usr/share/oem/cloud-config.yml" <"${VM_TMP_DIR}/extra" fi