From 5f76ec03a7a0ff41a97f312ec2882e2de46bdc22 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 1 Mar 2023 16:48:15 +0100 Subject: [PATCH] inputs/containers: change archive format to dir The format so far was assumed to be `docker-archive` if the container was coming from a source and `oci-archive` if it was coming from a pipeline. The source format will now be changed to `dir` instead of `docker-archive`. The pipeline format remains `oci-archive`. With the new archive format being `dir`, the source can't be linked into the build root and is bind mounted instead with the use of a MountGuard created with the instance of the service, and torn down when the service is stopped. The _data field is removed from the map functions. It was unused and these functions aren't part of the abstract class so they don't need to have consistent signatures. Update the skopeo stage with support for the newly supported `dir` format. --- inputs/org.osbuild.containers | 27 +++++++++++++++++++-------- stages/org.osbuild.skopeo | 4 ++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/inputs/org.osbuild.containers b/inputs/org.osbuild.containers index c50006c7..d1e642ed 100755 --- a/inputs/org.osbuild.containers +++ b/inputs/org.osbuild.containers @@ -21,6 +21,7 @@ import os import sys from osbuild import inputs +from osbuild.util.mnt import MountGuard SCHEMA = r""" "definitions": { @@ -159,15 +160,22 @@ SCHEMA = r""" class ContainersInput(inputs.InputService): - @staticmethod - def map_source_ref(source, ref, _data, target): - cache_dir = os.path.join(source, ref) - os.link(os.path.join(cache_dir, "container-image.tar"), os.path.join(target, ref)) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.mg = MountGuard() - return ref, "docker-archive" + def map_source_ref(self, source, ref, target): + source_archive = os.path.join(source, ref, "image") + dest = os.path.join(target, ref) + + # bind mount the input directory to the destination + os.makedirs(dest) + self.mg.mount(source_archive, dest) + + return ref, "dir" @staticmethod - def map_pipeline_ref(store, ref, _data, target): + def map_pipeline_ref(store, ref, target): # prepare the mount point os.makedirs(target, exist_ok=True) print("target", target) @@ -188,9 +196,9 @@ class ContainersInput(inputs.InputService): for ref, data in refs.items(): if origin == "org.osbuild.source": - ref, container_format = self.map_source_ref(source, ref, data, target) + ref, container_format = self.map_source_ref(source, ref, target) else: - ref, container_format = self.map_pipeline_ref(store, ref, data, target) + ref, container_format = self.map_pipeline_ref(store, ref, target) images[ref] = { "format": container_format, @@ -206,6 +214,9 @@ class ContainersInput(inputs.InputService): } return reply + def unmap(self): + self.mg.umount() + def main(): service = ContainersInput.from_args(sys.argv[1:]) diff --git a/stages/org.osbuild.skopeo b/stages/org.osbuild.skopeo index 0ed5e027..33233715 100755 --- a/stages/org.osbuild.skopeo +++ b/stages/org.osbuild.skopeo @@ -85,8 +85,8 @@ def main(inputs, output, options): linkname = os.path.join(tmpdir, "image.tar") os.symlink(source, linkname) - if container_format == "docker-archive": - source = f"docker-archive:{linkname}" + if container_format == "dir": + source = f"dir:{linkname}" elif container_format == "oci-archive": source = f"oci-archive:{linkname}" else: