Merge pull request #254 from marineam/dev-config

Build-time dev cloud configs
This commit is contained in:
Michael Marineau 2014-05-18 20:46:07 -07:00
commit 7372f9f6e6
4 changed files with 41 additions and 15 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
@ -134,6 +136,23 @@ mkdir -p "${BUILD_DIR}"
DISK_LAYOUT="${FLAGS_disk_layout:-base}"
CONTAINER_LAYOUT="${FLAGS_disk_layout:-container}"
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

@ -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"
@ -161,6 +174,14 @@ finish_image() {
--boot_args="${FLAGS_boot_args}"
fi
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

@ -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}"
}

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