build-vm, image.in: add VM_SAVE_TARBALL parameter

The parameter is used to save the intermediate tarball used to
build the virtual machine image.
This commit is contained in:
Anton Midyukov 2021-05-01 00:50:47 +07:00
parent f9ef0e95f7
commit 2987fa8f61
3 changed files with 32 additions and 8 deletions

View File

@ -121,6 +121,12 @@
*** пусто (по умолчанию) либо строка (например, "alpha", "beta")
** см. image.in/Makefile
* VM_SAVE_TARBALL
** указывает, что нужно сохранить промежуточный тарбол, из которого
** создаётся образ виртуальной машины, в заданном формате
** значения: tar tar.gz tar.xz
** см. features.in/build-vm/lib/90-build-vm.mk
* VM_SIZE
** задаёт размер несжатого образа виртуальной машины в байтах
** значение: пусто (по умолчанию двойной размер чрута) или целое

View File

@ -18,6 +18,7 @@ endif
# intermediate chroot archive
VM_TARBALL := $(IMAGE_OUTDIR)/$(IMAGE_NAME).tar
VM_OUT_TARBALL := $(IMAGE_OUTDIR)/$(IMAGE_OUTNAME).tar
VM_RAWDISK := $(IMAGE_OUTDIR)/$(IMAGE_NAME).raw
VM_FSTYPE ?= ext4
VM_SIZE ?= 0
@ -28,6 +29,16 @@ VM_XZ_COMMAND ?= xz -T0
# tavolga
RECOVERY_LINE ?= Press ENTER to start
# tarball save
#SAVE_TARBALL := convert-image/tar
ifdef VM_SAVE_TAR
ifeq (,$(filter-out img img.xz qcow2 qcow2c vdi vmdk vhd,$(IMAGE_TYPE)))
ifeq (,$(filter-out tar tar.gz tar.xz,$(VM_SAVE_TAR)))
SAVE_TARBALL := convert-image/$(VM_SAVE_TAR)
endif
endif
endif
check-sudo:
@if ! type -t sudo >&/dev/null; then \
echo "** error: sudo not available, see doc/vm.txt" >&2; \
@ -39,7 +50,7 @@ check-qemu:
exit 1; \
fi
tar2fs: check-sudo prepare-tarball-qemu
tar2fs: $(SAVE_TARBALL) check-sudo prepare-tarball-qemu
@if [ -x /usr/share/mkimage-profiles/bin/tar2fs ]; then \
TOPDIR=/usr/share/mkimage-profiles; \
fi; \
@ -57,13 +68,17 @@ prepare-tarball-qemu:
tar -rf "$(VM_TARBALL)" ./.host/qemu*) ||:
convert-image/tar:
mv "$(VM_TARBALL)" "$(IMAGE_OUTPATH)"
ifdef SAVE_TARBALL
cp "$(VM_TARBALL)" "$(VM_OUT_TARBALL)"
else
mv "$(VM_TARBALL)" "$(VM_OUT_TARBALL)"
endif
convert-image/tar.gz:
$(VM_GZIP_COMMAND) < "$(VM_TARBALL)" > "$(IMAGE_OUTPATH)"
convert-image/tar.gz: convert-image/tar
$(VM_GZIP_COMMAND) "$(VM_OUT_TARBALL)"
convert-image/tar.xz:
$(VM_XZ_COMMAND) < "$(VM_TARBALL)" > "$(IMAGE_OUTPATH)"
convert-image/tar.xz: convert-image/tar
$(VM_XZ_COMMAND) "$(VM_OUT_TARBALL)"
convert-image/img: tar2fs
mv "$(VM_RAWDISK)" "$(IMAGE_OUTPATH)"

View File

@ -41,8 +41,8 @@ IMAGE_VERSION := -$(DISTRO_VERSION)
IMAGE_VER_LINK := $(IMAGE_NAME)$(IMAGE_VERSION)-latest-$(ARCH).$(IMAGE_TYPE)
endif
IMAGE_OUTFILE := \
$(IMAGE_NAME)$(IMAGE_VERSION)-$(STATUS)$(DATE)-$(ARCH).$(IMAGE_TYPE)
IMAGE_OUTNAME := $(IMAGE_NAME)$(IMAGE_VERSION)-$(STATUS)$(DATE)-$(ARCH)
IMAGE_OUTFILE := $(IMAGE_OUTNAME).$(IMAGE_TYPE)
IMAGE_OUTDIR := $(IMAGEDIR)$(IMAGE_SORTDIR:%=/%)
IMAGE_OUTPATH := $(IMAGE_OUTDIR)/$(IMAGE_OUTFILE)
IMAGE_RELPATH := $(IMAGE_SORTDIR:%=%/)$(IMAGE_OUTFILE)
@ -95,6 +95,9 @@ postprocess: | $(addprefix postprocess-,$(sort $(POSTPROCESS_TARGETS)))
echo "** error: $(IMAGE_OUTPATH) missing" >&2; \
exit 1; \
fi; \
if [ -n "$(VM_SAVE_TAR)" ]; then \
echo "** tarball saved: $(IMAGE_OUTPATH)/$(IMAGE_OUTNAME).$(VM_SAVE_TAR)" >&2; \
fi; \
echo "** image: $(IMAGE_OUTPATH) [$$OUTSIZE]" >&2 && \
echo "IMAGE_OUTPATH = $(IMAGE_OUTPATH)" && \
echo "IMAGE_OUTFILE = $(IMAGE_OUTFILE)" && \