Skip to content

Commit e44b946

Browse files
committed
build_image: Deduplicate --extract_update and --generate_update options
The --extract_update option used to do exactly that, just extract the USR-A partition for updates and no more. Now it does the same thing as --generate_update, except it names the file flatcar_test_update.gz rather than flatcar_production_update.gz. --generate_update is never actually used because official update payloads are manually generated with the generate_payload script later on. Resolve this confusion by deduplicating the common code between them. Any update payload produced during this stage of the build is only useful for testing, so change --generate_update to always create flatcar_test_update.gz. --generate_update now implies --extract_update and both are enabled by default. Signed-off-by: James Le Cuirot <[email protected]>
1 parent f028bad commit e44b946

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

build_image

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ DEFINE_string disk_layout "" \
4141
"The disk layout type to use for this image."
4242
DEFINE_string group "${DEFAULT_GROUP}" \
4343
"The update group."
44-
DEFINE_boolean generate_update "${FLAGS_FALSE}" \
45-
"Generate update payload. (prod only)"
4644
DEFINE_boolean extract_update "${FLAGS_TRUE}" \
47-
"Extract the /usr partition for generating updates."
45+
"Extract the /usr partition for generating updates. Only valid for the prod image."
46+
DEFINE_boolean generate_update "${FLAGS_TRUE}" \
47+
"Generate update payload for testing. The update is signed with a dev key. The kernel is signed with a dev key (unofficial builds) or not at all (official builds). Only valid for the prod image. Implies --extract_update."
4848
DEFINE_string developer_data "" \
4949
"Insert a custom cloudinit file into the image."
5050
DEFINE_string devcontainer_binhost "${DEFAULT_DEVCONTAINER_BINHOST}" \
@@ -139,6 +139,11 @@ fi
139139
# Create the output directory and temporary mount points.
140140
mkdir -p "${BUILD_DIR}"
141141

142+
# --generate_update implies --extract_update.
143+
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then
144+
FLAGS_extract_update=${FLAGS_TRUE}
145+
fi
146+
142147
DISK_LAYOUT="${FLAGS_disk_layout:-base}"
143148
CONTAINER_LAYOUT="${FLAGS_disk_layout:-container}"
144149

@@ -169,11 +174,12 @@ fi
169174
if [[ "${PROD_IMAGE}" -eq 1 ]]; then
170175
IMAGE_BUILD_TYPE="prod"
171176
create_prod_image ${FLATCAR_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group} ${FLAGS_base_pkg} ${FLAGS_base_sysexts}
172-
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then
173-
generate_update "${FLATCAR_PRODUCTION_IMAGE_NAME}" ${DISK_LAYOUT}
174-
elif [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then
177+
if [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then
175178
extract_update "${FLATCAR_PRODUCTION_IMAGE_NAME}" "${DISK_LAYOUT}"
176179
fi
180+
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then
181+
generate_update "${FLATCAR_PRODUCTION_IMAGE_NAME}" "${DISK_LAYOUT}"
182+
fi
177183
if [[ "${PROD_TAR}" -eq 1 ]]; then
178184
create_prod_tar ${FLATCAR_PRODUCTION_IMAGE_NAME}
179185
fi
@@ -182,9 +188,7 @@ if [[ "${SYSEXT}" -eq 1 ]]; then
182188
create_prod_sysexts "${FLATCAR_PRODUCTION_IMAGE_NAME}"
183189
fi
184190

185-
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]] || \
186-
[[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]
187-
then
191+
if [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then
188192
zip_update_tools
189193
fi
190194

build_library/build_image_util.sh

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,57 +61,43 @@ delete_prompt() {
6161
extract_update() {
6262
local image_name="$1"
6363
local disk_layout="$2"
64-
local update_path="${BUILD_DIR}/${image_name%_image.bin}_update.bin"
64+
local update="${BUILD_DIR}/${image_name%_image.bin}_update.bin"
6565

6666
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
67-
extract "${BUILD_DIR}/${image_name}" "USR-A" "${update_path}"
67+
extract "${BUILD_DIR}/${image_name}" "USR-A" "${update}"
6868

6969
# Compress image
70-
files_to_evaluate+=( "${update_path}" )
70+
files_to_evaluate+=( "${update}" )
7171
compress_disk_images files_to_evaluate
72-
73-
# For production as well as dev builds we generate a dev-key-signed update
74-
# payload for running tests (the signature won't be accepted by production systems).
75-
local update_test="${BUILD_DIR}/flatcar_test_update.gz"
76-
delta_generator \
77-
-private_key "/usr/share/update_engine/update-payload-key.key.pem" \
78-
-new_image "${update_path}" \
79-
-new_kernel "${BUILD_DIR}/${image_name%.bin}.vmlinuz" \
80-
-out_file "${update_test}"
81-
}
82-
83-
zip_update_tools() {
84-
# There isn't a 'dev' variant of this zip, so always call it production.
85-
local update_zip="flatcar_production_update.zip"
86-
87-
info "Generating update tools zip"
88-
# Make sure some vars this script needs are exported
89-
export REPO_MANIFESTS_DIR SCRIPTS_DIR
90-
"${BUILD_LIBRARY_DIR}/generate_au_zip.py" \
91-
--arch "$(get_sdk_arch)" --output-dir "${BUILD_DIR}" --zip-name "${update_zip}"
9272
}
9373

9474
generate_update() {
9575
local image_name="$1"
9676
local disk_layout="$2"
9777
local image_kernel="${BUILD_DIR}/${image_name%.bin}.vmlinuz"
98-
local update_prefix="${image_name%_image.bin}_update"
99-
local update="${BUILD_DIR}/${update_prefix}"
78+
local update="${BUILD_DIR}/${image_name%_image.bin}_update.bin"
10079
local devkey="/usr/share/update_engine/update-payload-key.key.pem"
10180

81+
# Extract the partition if it isn't extracted already.
82+
[[ -s ${update} ]] || extract_update "${image_name}" "${disk_layout}"
83+
10284
echo "Generating update payload, signed with a dev key"
103-
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
104-
extract "${BUILD_DIR}/${image_name}" "USR-A" "${update}.bin"
10585
delta_generator \
10686
-private_key "${devkey}" \
107-
-new_image "${update}.bin" \
87+
-new_image "${update}" \
10888
-new_kernel "${image_kernel}" \
109-
-out_file "${update}.gz"
89+
-out_file "${BUILD_DIR}/flatcar_test_update.gz"
90+
}
11091

111-
# Compress image
112-
declare -a files_to_evaluate
113-
files_to_evaluate+=( "${update}.bin" )
114-
compress_disk_images files_to_evaluate
92+
zip_update_tools() {
93+
# There isn't a 'dev' variant of this zip, so always call it production.
94+
local update_zip="flatcar_production_update.zip"
95+
96+
info "Generating update tools zip"
97+
# Make sure some vars this script needs are exported
98+
local -x REPO_MANIFESTS_DIR SCRIPTS_DIR
99+
"${BUILD_LIBRARY_DIR}/generate_au_zip.py" \
100+
--arch "$(get_sdk_arch)" --output-dir "${BUILD_DIR}" --zip-name "${update_zip}"
115101
}
116102

117103
# ldconfig cannot generate caches for non-native arches.

0 commit comments

Comments
 (0)