kexec-tools/tests/scripts/build-image.sh
Kairui Song 2457f22baf selftest: Add basic infrastructure to build test image
The Makefile In tests/ could help build a VM image using Fedora cloud
image as base image, or, user can specify a base image using
BASE_IMAGE=<path/to/file>. The current repo will be packeged and
installed in the image, so the image could be used as a test image to
test kexec-tools.

The image building is splited into two steps:
The first step, it either convert the base image to qcow2 or create
a snapshot on it, and install basic packages (dracut, grubby, ...)
and do basic setups (setup crashkernel=, disable selinux, ...).
See tests/scripts/build-scripts/base-image.sh for detail.

The second step, it creates a snapshot on top of the image produced by
the previous step, and install the packaged kexec-tools of current
repo.  See tests/scripts/build-scripts/test-base-image.sh for detail.

In this way, if repo's content is changes, `make` will detect it and
only rebuild the second snapshot which speed up the rebuild by a lot.

The image will be located as tests/output/test-base-image, and in qcow2
format. And default user/password is set to root/fedora.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
2020-09-17 10:42:34 +08:00

58 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
if [ $# -lt 2 ]; then
echo "Usage: $(basename $0) <base-image> <output-image> <build-script> [<build-script-args>]
Build a new <output-image> on top of <base-image>, and install
contents defined in <build-script>. <args> are directly passed
to <build-script>.
If <base-image> is raw, will copy it and create <output-image>
in qcow2 format.
If <base-image> is qcow2, will create <output-image> as a snapshot
on top of <base-image>"
exit 1
fi
BASEDIR=$(realpath $(dirname "$0"))
. $BASEDIR/image-init-lib.sh
# Base image to build from
BASE_IMAGE=$1 && shift
if [[ ! -e $BASE_IMAGE ]]; then
perror_exit "Base image '$BASE_IMAGE' not found"
else
BASE_IMAGE=$(realpath "$BASE_IMAGE")
fi
OUTPUT_IMAGE=$1 && shift
if [[ ! -d $(dirname $OUTPUT_IMAGE) ]]; then
perror_exit "Path '$(dirname $OUTPUT_IMAGE)' doesn't exists"
fi
INST_SCRIPT=$1 && shift
create_image_from_base_image $BASE_IMAGE $OUTPUT_IMAGE.building
mount_image $OUTPUT_IMAGE.building
img_inst() {
inst_in_image $OUTPUT_IMAGE.building $@
}
img_inst_pkg() {
inst_pkg_in_image $OUTPUT_IMAGE.building $@
}
img_run_cmd() {
run_in_image $OUTPUT_IMAGE.building "$@"
}
img_add_qemu_cmd() {
QEMU_CMD+="$@"
}
[ -e "$INST_SCRIPT" ] && source $INST_SCRIPT
mv $OUTPUT_IMAGE.building $OUTPUT_IMAGE