Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: add --source-imgref #263

Merged
merged 3 commits into from
Jan 17, 2024
Merged

Conversation

ondrejbudai
Copy link
Contributor

@ondrejbudai ondrejbudai commented Jan 16, 2024

blockdev: fix recognizing parent loop devices

lsblk returns TYPE == loop for loop devices, modify the code
so loop devices are correctly recognized.


install: make the source digest optional

This is a prep work for the following commit. It will implement pulling
the container image from an explicitly given container reference. Thus,
there's no need to always fetch the digest because the caller is being
explicit about the container image, so let's make the field optional.


install: add --source-imgref

bootc install and install-to-filesystem currently rely on the fact that they
run inside a podman container. That's quite inconvenient for using bootc
for osbuild, because osbuild already run everything in a container.
While having a container in a container is surely possible, it gets quite
messy.

Instead of going this route, this commit implements a new --source-imgref
argument. --source-imgref accepts a container image reference (the same one
that skopeo uses). When --source-imgref is used, bootc doesn't escape the
container to fetch the container image from host's container storage. Instead,
the container image given by --source-imgref is used.

Even when running in this mode, bootc needs to run in a container created from
the same container image that is passed using --source-imgref. However, this
isn't a problem to do in osbuild. This really just removes the need for bootc
to escape the container to the host mount namespace.

@github-actions github-actions bot added the area/install Issues related to `bootc install` label Jan 16, 2024
@ondrejbudai ondrejbudai force-pushed the source-arg branch 4 times, most recently from c96d517 to 276c68a Compare January 16, 2024 22:52
Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for this! Overall mostly LGTM, just some nits and optionals.

@@ -197,7 +197,7 @@ pub(crate) fn find_parent_devices(device: &str) -> Result<Vec<String>> {
let kind = dev
.get("TYPE")
.with_context(|| format!("device in hierarchy of {device} missing TYPE"))?;
if kind == "disk" {
if kind == "disk" || kind == "loop" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. It would probably make sense to try to use a shared crate for dealing with block devices at some point.

}

/// Given an image ID, return its manifest digest
pub(crate) fn oci_archive_digest(imageref: &str) -> Result<String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't specific to oci archives right? If we want it to be, let's make this a &Utf8Path, and then explicitly specify dir: below say.

If we want to keep it general...we also already use https://docs.rs/containers-image-proxy/latest/containers_image_proxy/ which is a handy Rust client for talking to skopeo, but I don't really in the end have a problem with being practical and just forking it either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Forgot to mention, see below where we could also probably drop this code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped (see below).

} else {
let td = tempfile::tempdir_in("/var/tmp")?;
let path: &Utf8Path = td.path().try_into().unwrap();
let r = copy_to_oci(&state.source.imageref, path)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Unrelated to this change, but I would probably be fine just hard dropping this hacky "copy to oci" code that I don't think we need anymore since c9s has a new enough skopeo and that's fine from my PoV)

Totally optional of course...just reminded by the seeing the code again here. If you want I can also do a prep PR removing it (or feel free to yourself), it seems like it would simplify this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up doing this in #265 - but I still don't have a really strong opinion - we can merge this before that one if you prefer too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections from my side. #265 has a failing test suite currently, though. I think that rebasing #265 on top of this PR might be easier, so I prefer landing this one first. I must admit that it's a tad bit selfish view, though. 👼


#[context("Gathering source info from an external source")]
pub(crate) fn from_imageref(imageref: &str) -> Result<Self> {
let digest = crate::skopeo::oci_archive_digest(imageref)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today, the ostree-container stack very much handles just being passed a non-digested pull spec; we'll do the digest resolution there. An alternative here is to make digest an Option<T> instead. I have a mild preference for this, but I'm also fine with the code as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I understood your comment correctly. I made digest an Option<T>. This loses a bit of "null-safety" (handled gracefully, ofc), but it allowed me to drop the whole skopeo crate. I have a backup of the old code if we change our midns.

cgwalters added a commit to cgwalters/bootc that referenced this pull request Jan 17, 2024
Let's just hard require a skopeo that can fetch from `containers-storage`.
Motivated by containers#263 which
was moving this code around.

Signed-off-by: Colin Walters <walters@verbum.org>
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see docs on that as well. Which containers-transports are supported? I feel that the name --source is so generic that different users/personas will have a very different interpretation/feeling for that a source may be.

lsblk returns TYPE == loop for loop devices, modify the code
so loop devices are correctly recognized.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jan 17, 2024
This is a prep work for the following commit. It will implement pulling
the container image from an explicitly given container reference. Thus,
there's no need to always fetch the digest because the caller is being
explicit about the container image, so let's make the field optional.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
@ondrejbudai
Copy link
Contributor Author

I'd love to see docs on that as well. Which containers-transports are supported? I feel that the name --source is so generic that different users/personas will have a very different interpretation/feeling for that a source may be.

I renamed --source to --source-imgref, and added some documentation about it. Does it work for you?

@ondrejbudai ondrejbudai changed the title install: add --source install: add --source-imgref Jan 17, 2024
cgwalters
cgwalters previously approved these changes Jan 17, 2024
Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one final nit, feel free to merge after addressing!

docs/install.md Show resolved Hide resolved
/// it takes the container image to install from the podman's container registry.
/// If --source-imgref is given, bootc uses it as the installation source, instead of the behaviour explained
/// in the previous paragraph. See skopeo(1) for accepted formats.
#[clap(long, hide = true)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But documenting seems to clash with hide = true. Either it's something we support ~forever or it's a hidden thing that could be removed in theory. I guess given the state, we should probably lift hide = true right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed hide = true.

docs/install.md Outdated Show resolved Hide resolved
bootc install and install-to-filesystem currently rely on the fact that they
run inside a podman container. That's quite inconvenient for using bootc
for osbuild, because osbuild already run everything in a container.
While having a container in a container is surely possible, it gets quite
messy.

Instead of going this route, this commit implements a new --source-imgref
argument. --source-imgref accepts a container image reference (the same one
that skopeo uses). When --source-imgref is used, bootc doesn't escape the
container to fetch the container image from host's container storage. Instead,
the container image given by --source-imgref is used.

Even when running in this mode, bootc needs to run in a container created from
the same container image that is passed using --source-imgref. However, this
isn't a problem to do in osbuild. This really just removes the need for bootc
to escape the container to the host mount namespace.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
@cgwalters cgwalters merged commit 0910876 into containers:main Jan 17, 2024
11 checks passed
@ondrejbudai ondrejbudai deleted the source-arg branch January 17, 2024 13:28
@ondrejbudai ondrejbudai restored the source-arg branch January 17, 2024 13:28
cgwalters added a commit to cgwalters/bootc that referenced this pull request Jan 17, 2024
Let's just hard require a skopeo that can fetch from `containers-storage`.
Motivated by containers#263 which
was moving this code around.

Signed-off-by: Colin Walters <walters@verbum.org>
cgwalters added a commit to cgwalters/bootc that referenced this pull request Jan 17, 2024
Let's just hard require a skopeo that can fetch from `containers-storage`.
Motivated by containers#263 which
was moving this code around.

Signed-off-by: Colin Walters <walters@verbum.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/install Issues related to `bootc install` documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants