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.
This commit is contained in:
Michael Marineau 2014-05-17 11:31:09 -07:00
parent a93cb921d8
commit 822644fc54
3 changed files with 27 additions and 12 deletions

View File

@ -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}" <<EOF
#cloud-config
users:
- name: core
passwd: $(</etc/shared_user_passwd.txt)
EOF
fi
if [[ "${DEV_IMAGE}" -eq 1 ]]; then
create_dev_image ${COREOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group}
upload_image "${BUILD_DIR}/${COREOS_DEVELOPER_IMAGE_NAME}"

View File

@ -171,6 +171,14 @@ finish_image() {
--esp_dir="${root_fs_dir}"/boot/efi \
--boot_args="${FLAGS_boot_args}"
if [[ -n "${FLAGS_developer_data}" ]]; then
local data_path="/usr/share/coreos/developer_data"
local unit_path="usr-share-coreos-developer_data"
sudo cp "${FLAGS_developer_data}" "${root_fs_dir}/${data_path}"
systemd_enable "${root_fs_dir}" user-config.target \
"user-cloudinit@.path" "user-cloudinit@${unit_path}.path"
fi
# Zero all fs free space to make it more compressible so auto-update
# payloads become smaller, not fatal since it won't work on linux < 3.2
sudo fstrim "${root_fs_dir}" || true

View File

@ -373,18 +373,6 @@ _write_cpio_common() {
# Inject /usr/.noupdate into squashfs to disable update_engine
echo "/usr/.noupdate f 444 root root echo -n" >"${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" <<EOF
#cloud-config
users:
- name: core
passwd: $(</etc/shared_user_passwd.txt)
EOF
fi
# Inject /usr/.noupdate into squashfs to disable update_engine
echo "/.noupdate f 444 root root echo -n" >"${VM_TMP_DIR}/extra"
fi