elbepack: add support for base images#461
Conversation
This takes an image provided on command line and uploads it into qemu using the same mechanism as cdrom uploads. It doesn't take too long: a few seconds for the simple validation image. The code to actually use that upload is added in the following commit. Signed-off-by: Alexander Kanavin <alex@linutronix.de>
This is very much a demo/proof-of-concept/starting point for discussion and further improvements. Particularly there is no documentation or tests, and the code contains several hardcoded assumptions (e.g. about the image format, partitions layout, etc.) The code replace the debootstrap step with mounting and copying the content of the base image instead, if base image is found in the xml spec. I've also added two demonstration xmls, which are copies of simple validation image xml with some tweaks to allow staged image builds. Demo: $ ./elbe --stacktrace-on-error initvm submit --skip-build-bin --skip-build-sources tests/simple-validation-image-base.xml $ ./elbe --stacktrace-on-error initvm submit --skip-build-bin --skip-build-sources --base-image ./elbe-build-20260520-183738/sda.img tests/simple-validation-image-extended.xml Signed-off-by: Alexander Kanavin <alex@linutronix.de>
t-8ch
left a comment
There was a problem hiding this comment.
We'll also need a way to make the SBOMs work correctly for a layered image.
The first commit message talks about "qemu". This should be "initvm" I think.
| f = add_argument('--build-sdk', dest='build_sdk', action='store_true', default=False, | ||
| help="Also make 'initvm submit' build an SDK.")(f) | ||
|
|
||
| f = add_argument('--base-image', dest='base_image', default=None, |
There was a problem hiding this comment.
default=None is the default and can be dropped.
There was a problem hiding this comment.
Could you trim down these test images to the bare minimum to show and test the feature?
Right now it is hard to see what is necessary and what just copied.
| help="Also make 'initvm submit' build an SDK.")(f) | ||
|
|
||
| f = add_argument('--base-image', dest='base_image', default=None, | ||
| help='Use a base image instead of debootstrap')(f) |
There was a problem hiding this comment.
What do you think about making the base image usage explicit in the XML.
Maybe as a new type of debootrstrap?
<debootstrap>
<type>base-image</type>
</debootstrap>
And it should be possible to specify the base image in the XML directly, possibly to be overwritten by --base-image.
There was a problem hiding this comment.
I agree about specifying base image usage explicitly and will add that, but I'm less certain about putting the default path to it into the XML.
If it's in the XML as an absolute path, that makes XML not usable in iterative development (where base images are in timestamped directories), or anywhere outside of the exact CI environment where that path can be fulfilled. If it's a relative path, then it isn't clear relative to what the image should be, and the image name is still hardcoded and must match exactly. I feel providing it over command line is both more flexible and user-friendly (elbe would error out if the xml says base image must be used, but none was given on the command line).
I'll leave the path in xml out for now, and we can add it later if a clear use case emerges. I think it would be much more useful to allow specifying a http link to the image in the xml, so that it would download the default image (for example, published by Linutronix to customers) unless the user says otherwise.
There was a problem hiding this comment.
My idea was for the base image location in the XML to be optional.
If it makes sense for the user to specify they could do so.
But let's postpone this as you suggested, we can always add it later.
| ep.xml.set_base_image( | ||
| path.join( | ||
| ep.builddir, | ||
| 'uploaded_base_image.img')) |
There was a problem hiding this comment.
It's a copy paste of set_upload_cdrom(), which has similar odd newlines (and it's elsewhere in the file too). I'd rather be consistent with existing code.
| do(['mkdir', '-p', base_image_mount]) | ||
| with losetup(base_image_file) as loopdev: | ||
| with mount(loopdev+'p1', base_image_mount): | ||
| do(['cp', '-a', base_image_mount, self.path]) |
There was a problem hiding this comment.
./elbe --stacktrace-on-error initvm submit --skip-build-bin --skip-build-sources --base-image ./elbe-build-20260520-183738/sda.img tests/simple-validation-image-extended.xml
I strongly prefer to only allow special rootfs archives as base, and not arbitrary disk images.
For example a tar archive, similar to what ELBE can already emit. See examples/x86_64-docker.xml.
There was a problem hiding this comment.
Right, yes. Then perhaps the nomenclature (options, variables, xml entries) should not be talking about images at all, but rather root filesystems?
E.g. command line option: --base-rootfs-archive path/to/tarball
There was a problem hiding this comment.
That's quite a mouthful and I don't really like it, but I don't have something clearly better.
Maybe "base layer"?
But we can do the naming when everything else is finished and we know what was actually built.
Your choice.
There was a problem hiding this comment.
Alright, I'll stick with base images for now.
| '#!/bin/sh\nexit 101\n') | ||
| self.debootstrap(arch) | ||
| self.fresh_debootstrap = True | ||
| self.need_dumpdebootstrap = True |
There was a problem hiding this comment.
Could you move this into a helper function first?
If you have some preparatory cleanup commits I'm happy to apply those directly.
This is very much a demo/proof-of-concept/starting point for discussion and further improvements. Particularly there is no documentation or tests, and the code contains several hardcoded assumptions (e.g. about the image format, partitions layout, etc.)
The code replaces the debootstrap step with mounting and copying the content of the base image instead, if base image is found in the xml spec.
I've also added two demonstration xmls, which are copies of simple validation image xml with some tweaks to allow staged image builds.
Demo: