| tAdd support for cloud-based VM images. - libdevuansdk - common library for devuan's simple distro kits |
| git clone https://git.parazyd.org/libdevuansdk |
| Log |
| Files |
| Refs |
| Submodules |
| README |
| LICENSE |
| --- |
| commit 589d62ca0eb8d72149d3c8a54c310a5255ad47dd |
| parent c922031a0cb2eade8922cf3c2d40dff2b13cd54c |
| Author: parazyd |
| Date: Mon, 8 Oct 2018 12:36:15 +0200
Add support for cloud-based VM images.
Diffstat:
M zlibs/helpers | 1 +
M zlibs/vm | 39 +++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
--- |
| diff --git a/zlibs/helpers b/zlibs/helpers |
| t@@ -81,6 +81,7 @@ build_vagrant_dist() {
vm_umount_${imageformat} || { zerr; wrapup }
vm_vbox_setup || { zerr; wrapup }
vm_vagrant_package || { zerr; wrapup }
+ vm_init_cloud || { zerr; wrapup }
vm_pack_dist || { zerr; wrapup }
}
|
| diff --git a/zlibs/vm b/zlibs/vm |
| t@@ -169,6 +169,39 @@ EOF
popd
}
+vm_init_cloud() {
+ fn vm_init_cloud
+ req=(workdir strapdir imageformat loopdevice)
+ ckreq || return 1
+
+ [ -n "$makecloud" ] || return
+ [ "$imageformat" = qcow2 ] || {
+ die "imageformat is not qcow2"
+ zerr
+ }
+
+ notice "Creating a cloud-based image"
+ pushd "$workdir"
+ cp -v "base.qcow2" "base-cloud.qcow2"
+
+ notice "Connecting qemu-nbd and mounting"
+ sudo mkdir -p "$strapdir"
+ sudo qemu-nbd --connect=${loopdevice} base-cloud.qcow2 || zerr
+ sudo mount ${loopdevice}p1 $strapdir || zerr
+
+ notice "Installing cloud-init"
+ cat </dev/null
+#!/bin/sh
+
+apt-get update
+apt-get --yes --force-yes install cloud-init
+apt-get clean
+EOF
+ chroot-script -d initcloud || zerr
+ vm_umount_${imageformat} || zerr
+ popd
+}
+
vm_pack_dist() {
fn vm_pack_dist
req=(workdir imageformat)
t@@ -180,6 +213,9 @@ vm_pack_dist() {
mv $workdir/base.${imageformat} $R/dist/${vm_name}.${imageformat}
cp $workdir/base.vdi $R/dist/${vm_name}.vdi
+ [ -n "$makecloud" ] && \
+ mv base-cloud.${imageformat} $R/dist/${vm_name}-cloud.${imageformat}
+
act "calculating sha256 sums..."
silly
sha256sum $R/dist/${vm_name}.box > \
t@@ -188,6 +224,9 @@ vm_pack_dist() {
$R/dist/${vm_name}.${imageformat}.sha
sha256sum $R/dist/${vm_name}.vdi > \
$R/dist/${vm_name}.vdi.sha
+ [ -n "$makecloud" ] && \
+ sha256sum $R/dist/${vm_name}-cloud.${imageformat} > \
+ $R/dist/${vm_name}-cloud.${imageformat}.sha
notice "cleaning up virtualbox leftovers"
pushd "$workdir" |