From 299785a7b813aff0dbf1a5356506f64e937b63b0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 1 Nov 2022 13:01:14 -0400 Subject: [PATCH] Add manifest data for diskless images --- imgutil/imgutil | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index c5f2bb91..c23cfc39 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -16,6 +16,16 @@ import subprocess import sys import tempfile import time +import yaml +path = os.path.dirname(os.path.realpath(__file__)) +path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) +if path.startswith('/opt'): + sys.path.append(path) + +try: + import confluent.osimage as osimage +except ImportError: + osimage = None libc = ctypes.CDLL(ctypes.util.find_library('c')) CLONE_NEWNS = 0x00020000 @@ -194,8 +204,14 @@ def capture_remote(args): confdir = '/opt/confluent/lib/osdeploy/{}-diskless'.format(oscat) os.symlink('{}/initramfs/addons.cpio'.format(confdir), os.path.join(outdir, 'boot/initramfs/addons.cpio')) - if os.path.exists('{}/profiles/default'.format(confdir)): - copy_tree('{}/profiles/default'.format(confdir), outdir) + indir = '{}/profiles/default'.format(confdir) + if os.path.exists(indir): + copy_tree(indir, outdir) + hmap = osimage.get_hashes(outdir) + with open('{0}/manifest.yaml'.format(outdir), 'w') as yout: + yout.write('# This manifest enables rebase to know original source of profile data and if any customizations have been done\n') + manifestdata = {'distdir': indir, 'disthashes': hmap} + yout.write(yaml.dump(manifestdata, default_flow_style=False)) label = '{0} {1} ({2})'.format(finfo['name'], finfo['version'], profname) with open(os.path.join(outdir, 'profile.yaml'), 'w') as profileout: profileout.write('label: {}\n'.format(label)) @@ -1239,8 +1255,14 @@ def pack_image(args): confdir = '/opt/confluent/lib/osdeploy/{}-diskless'.format(oscat) os.symlink('{}/initramfs/addons.cpio'.format(confdir), os.path.join(outdir, 'boot/initramfs/addons.cpio')) - if os.path.exists('{}/profiles/default'.format(confdir)): - copy_tree('{}/profiles/default'.format(confdir), outdir) + indir = '{}/profiles/default'.format(confdir) + if os.path.exists(indir): + copy_tree(indir, outdir) + hmap = osimage.get_hashes(outdir) + with open('{0}/manifest.yaml'.format(outdir), 'w') as yout: + yout.write('# This manifest enables rebase to know original source of profile data and if any customizations have been done\n') + manifestdata = {'distdir': indir, 'disthashes': hmap} + yout.write(yaml.dump(manifestdata, default_flow_style=False)) tryupdate = True try: pwd.getpwnam('confluent')