diff options
author | Christian Breunig <christian@breunig.cc> | 2023-11-26 20:12:29 +0100 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2023-11-26 20:13:28 +0100 |
commit | 499e8e1cbb90e24acf80d383a69e138cd745807c (patch) | |
tree | a4e117b6a5442190d5391e480fa6ee049775bb78 | |
parent | 0411ec870eb25931efb3e42e68d5212fbb9e9844 (diff) | |
download | vyos-build-499e8e1cbb90e24acf80d383a69e138cd745807c.tar.gz vyos-build-499e8e1cbb90e24acf80d383a69e138cd745807c.zip |
Makefile: T2640: add helper to convert ISO to OCI image to start a container
Use either "make oci" or call the script manually:
$ scripts/iso-to-oci build/live-image-amd64.hybrid.iso
I: mount ISO build/live-image-amd64.hybrid.iso
I: extracting squashfs content
I: generate OCI container image vyos-1.5-strongswan-202311241125.tar
I: to import the previously generated OCI image to your local images run:
docker import vyos-1.5-strongswan-202311241125.tar vyos:1.5-strongswan-202311241125 --change 'CMD [/sbin/init]'
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | scripts/iso-to-oci | 63 |
3 files changed, 69 insertions, 0 deletions
@@ -7,3 +7,4 @@ packages/* !packages/*/ testinstall*.img *.qcow2 +*.tar @@ -59,6 +59,11 @@ testraid: checkiso qemu-live: checkiso scripts/check-qemu-install --qemu-cmd build/live-image-amd64.hybrid.iso +.PHONE: oci +.ONESHELL: +oci: checkiso + scripts/iso-to-oci build/live-image-amd64.hybrid.iso + .PHONY: clean .ONESHELL: clean: diff --git a/scripts/iso-to-oci b/scripts/iso-to-oci new file mode 100755 index 00000000..c9396290 --- /dev/null +++ b/scripts/iso-to-oci @@ -0,0 +1,63 @@ +#!/bin/bash + +function cleanup() { + if [[ -d $ROOTFS ]]; then + rm -rf $ROOTFS + fi + if [[ -d $UNSQUASHFS ]]; then + rm -rf $UNSQUASHFS + fi +} + +if [[ $(/usr/bin/id -u) -ne 0 ]]; then + echo "Not running as root" + exit +fi + +if [ "$#" -ne 1 ]; then + echo "Illegal number of parameters" +fi + +ISO=$1 +ROOTFS=rootfs +UNSQUASHFS=unsquashfs + +# ensure clean working directory +cleanup + +mkdir $ROOTFS $UNSQUASHFS +echo "I: mount ISO $ISO" +mount -t iso9660 -o loop $ISO $ROOTFS/ >/dev/null 2>&1 + +# create directory, unpack squashfs filesystem, get ISO version +# and unmount ISO +echo "I: extracting squashfs content" +unsquashfs -follow -dest $UNSQUASHFS/ $ROOTFS/live/filesystem.squashfs >/dev/null 2>&1 +VERSION=$(jq --raw-output .version $ROOTFS/version.json) +umount $ROOTFS/ + +# fix locales for correct system configuration loading +sed -i 's/^LANG=.*$/LANG=C.UTF-8/' $UNSQUASHFS/etc/default/locale + +# optional step: Decrease docker image size by deleting not necessary files for container +rm -rf $UNSQUASHFS/boot/*.img +rm -rf $UNSQUASHFS/boot/*vyos* +rm -rf $UNSQUASHFS/boot/vmlinuz +rm -rf $UNSQUASHFS/lib/firmware/ +rm -rf $UNSQUASHFS/usr/lib/x86_64-linux-gnu/libwireshark.so* +rm -rf $UNSQUASHFS/lib/modules/*amd64-vyos +rm -rf $UNSQUASHFS/root/.gnupg + +# create a symbolic link to the configuration +ln -s /opt/vyatta/etc/config $UNSQUASHFS/config + +# create docker image +echo "I: generate OCI container image vyos-$VERSION.tar" +tar -C unsquashfs -c . -f vyos-$VERSION.tar + +echo "I: to import the previously generated OCI image to your local images run:" +echo "" +echo " docker import vyos-$VERSION.tar vyos:$VERSION --change 'CMD ["/sbin/init"]'" +echo "" + +cleanup |