From ea2d3173a8f82051d9a33162901ec96f859b3fcb Mon Sep 17 00:00:00 2001 From: Luke Yang Date: Mon, 25 Sep 2023 11:48:10 -0400 Subject: [PATCH] container: Add support for the `dir` transport This patch allows container image deployment stored in a local directory in addition to the supported remote OCI registry, OCI archive tarball, and local container storage. For example, the following command is now supported: sudo ostree container image deploy --imgref ostree-unverified-image:dir:/var/home/core/fcos --sysroot /var/home/core/sysroot --stateroot fedora-coreos The reason for making this change relates to the effort to create an FCOS qemu image from a container image input using OSBuild. OSBuild stores container image sources in a local directory in order to solve another bug and, thus, should not be changed. Therefore, to allow OSBuild to deploy from a container image, this patch is needed. --- lib/src/cli.rs | 1 + lib/src/container/mod.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index d791f512..4a994ca3 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -320,6 +320,7 @@ pub(crate) enum ContainerImageOpts { /// Source image reference, e.g. ostree-remote-image:someremote:registry:quay.io/exampleos/exampleos@sha256:abcd... /// This conflicts with `--image`. + /// This conflicts with `--image`. Supports `registry:`, `docker://`, `oci:`, `oci-archive:`, `containers-storage:`, and `dir:` #[clap(long, required_unless_present = "image")] imgref: Option, diff --git a/lib/src/container/mod.rs b/lib/src/container/mod.rs index 54c6f965..bc172d39 100644 --- a/lib/src/container/mod.rs +++ b/lib/src/container/mod.rs @@ -58,6 +58,8 @@ pub enum Transport { OciArchive, /// Local container storage (`containers-storage:`) ContainerStorage, + /// Local directory (`dir:`) + Dir, } /// Combination of a remote image reference and transport. @@ -104,6 +106,7 @@ impl TryFrom<&str> for Transport { Self::OCI_STR => Self::OciDir, Self::OCI_ARCHIVE_STR => Self::OciArchive, Self::CONTAINERS_STORAGE_STR => Self::ContainerStorage, + Self::LOCAL_DIRECTORY_STR => Self::Dir, o => return Err(anyhow!("Unknown transport '{}'", o)), }) } @@ -113,6 +116,7 @@ impl Transport { const OCI_STR: &str = "oci"; const OCI_ARCHIVE_STR: &str = "oci-archive"; const CONTAINERS_STORAGE_STR: &str = "containers-storage"; + const LOCAL_DIRECTORY_STR: &str = "dir"; const REGISTRY_STR: &str = "registry"; /// Retrieve an identifier that can then be re-parsed from [`Transport::try_from::<&str>`]. @@ -122,6 +126,7 @@ impl Transport { Transport::OciDir => Self::OCI_STR, Transport::OciArchive => Self::OCI_ARCHIVE_STR, Transport::ContainerStorage => Self::CONTAINERS_STORAGE_STR, + Transport::Dir => Self::LOCAL_DIRECTORY_STR, } } } @@ -242,6 +247,7 @@ impl std::fmt::Display for Transport { Self::OciArchive => "oci-archive:", Self::OciDir => "oci:", Self::ContainerStorage => "containers-storage:", + Self::Dir => "dir:", }; f.write_str(s) } @@ -514,6 +520,10 @@ mod tests { let ir: ImageReference = "oci:somedir".try_into().unwrap(); assert_eq!(ir.transport, Transport::OciDir); assert_eq!(ir.name, "somedir"); + + let ir: ImageReference = "dir:/some/dir/blah".try_into().unwrap(); + assert_eq!(ir.transport, Transport::Dir); + assert_eq!(ir.name, "/some/dir/blah"); } #[test]