build_image: Add prodtar command to build a tar ball

Create a tar ball with the contents of the / and /usr partitions
to be used as follows with systemd-nspawn (via machinectl):
  machinectl import-tar flatcar-container.tar.gz flatcar-container
  machinectl start flatcar-container
  machinectl shell flatcar-container
or with docker by converting it to an OCI image:
  docker import -c "CMD /bin/bash" flatcar-container.tar.gz flatcar-container

Since the new "prodtar" command relies on the results of the "prod" command,
it bundles it so that "prod prodtar" and "prodtar" is the same.
This commit is contained in:
Kai Lüke 2020-01-29 12:59:36 +01:00
parent 8669c88085
commit b5cddc281f
No known key found for this signature in database
GPG Key ID: E5601DA3A1D902A8
2 changed files with 25 additions and 2 deletions

View File

@ -56,12 +56,13 @@ FLAGS_HELP="USAGE: build_image [flags] [list of images to build].
This script is used to build a CoreOS image. CoreOS comes in many
different forms. This scripts can be used to build the following:
prod - Production image for CoreOS. This image is for booting.
prod - Production image for CoreOS. This image is for booting (default if no argument is given).
prodtar - Production container tar ball (implies prod). This can e.g. be used to run the Flatcar production image as a container (run machinectl import-tar or docker import).
container - Developer image with single filesystem, bootable by nspawn.
Examples:
build_image --board=<board> [prod] [container] - builds developer and production images.
build_image --board=<board> [prod] [prodtar] [container] - builds developer and production images/tars.
...
"
show_help_if_requested "$@"
@ -112,10 +113,12 @@ fi
. "${BUILD_LIBRARY_DIR}/vm_image_util.sh" || exit 1
PROD_IMAGE=0
PROD_TAR=0
CONTAINER=0
for arg in "$@"; do
case "${arg}" in
prod) PROD_IMAGE=1 ;;
prodtar) PROD_IMAGE=1 PROD_TAR=1 ;;
container) CONTAINER=1 ;;
*) die_notrace "Unknown image type ${arg}" ;;
esac
@ -177,6 +180,9 @@ if [[ "${PROD_IMAGE}" -eq 1 ]]; then
elif [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then
extract_update "${FLATCAR_PRODUCTION_IMAGE_NAME}" "${DISK_LAYOUT}"
fi
if [[ "${PROD_TAR}" -eq 1 ]]; then
create_prod_tar ${FLATCAR_PRODUCTION_IMAGE_NAME}
fi
fi
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]] || \

View File

@ -149,3 +149,20 @@ EOF
fi
upload_image -d "${BUILD_DIR}/${image_name}.bz2.DIGESTS" "${to_upload[@]}"
}
create_prod_tar() {
local image_name="$1"
local image="${BUILD_DIR}/${image_name}"
local container="${BUILD_DIR}/flatcar-container.tar.gz"
local lodev="$(sudo losetup --find --show -r -P "${image}")"
local lodevbase="$(basename "${lodev}")"
sudo mkdir -p "/mnt/${lodevbase}p9"
sudo mount "${lodev}p9" "/mnt/${lodevbase}p9"
sudo mount "${lodev}p3" "/mnt/${lodevbase}p9/usr"
sudo tar --xattrs -czpf "${container}" -C "/mnt/${lodevbase}p9" .
sudo umount "/mnt/${lodevbase}p9/usr"
sudo umount "/mnt/${lodevbase}p9"
sudo rmdir "/mnt/${lodevbase}p9"
sudo losetup --detach "${lodev}"
upload_image "${container}"
}