Skip to content

container: resolve containers using skopeo [RHEL-56367] - #2346

Merged
thozza merged 12 commits into
osbuild:mainfrom
achilleas-k:drop-dep/containers-image
May 21, 2026
Merged

thozza merged 12 commits into
osbuild:mainfrom
achilleas-k:drop-dep/containers-image

Conversation

@achilleas-k

Copy link
Copy Markdown
Member

This is the first part towards removing our dependency on the containers/image Go library by shelling out to tools like skopeo and podman. Ideally, we would only rely on skopeo, but one specific use case uses podman and I think we can drop it. More details on this in the code and relevant commit.

The referenced ticket requests removing our dependence on GnuPG. There are workarounds to using a different backend, but the current approach aligns with something I've wanted for a while so this is an opportunity to resolve multiple issues at once. When we finally remove the containers dependencies, we will be able to drop our dependency on the following development packages:

  • gpgme-devel
  • btrfs-progs-devel (or, in the case of RHEL and CentOS, the exclude_graphdriver_btrfs build flag).
  • device-mapper-devel

This will simplify our code and dependency chain by essentially "outsourcing" the work to skopeo. Note that skopeo is already an indirect dependency through osbuild as it's used for the org.osbuild.skopeo source for containers.

I've been working on this on and off for a few weeks now and I was hoping to have it done a while ago. The big part that remains is the container upload command and internal functionality. I decided to open the PR with the current state to get some reviews and perhaps merge this while I work on the rest.

@achilleas-k

Copy link
Copy Markdown
Member Author

@kingsleyzissou Added you as a reviewer since you've worked on the local manifest resolution.

@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch from c57363b to d66d2f0 Compare May 19, 2026 16:14
@achilleas-k

Copy link
Copy Markdown
Member Author

I missed the test failures when running locally because they only happen with -race.

Also I didn't consider that adding our test containers to all-customizations would fail because we only have x86_64 and aarch64 versions.

@achilleas-k

Copy link
Copy Markdown
Member Author

Oh, this is interesting:

🔴 filesystem: fail: failed to read active mountpoints: failed to run lsblk: exit status 1 (exit 1, stderr: lsblk: unknown column: MOUNTPOINTS,FSTYPE)

Another case where we changed a test but didn't run it because of caching.

This is a RHEL 8 failure.

@achilleas-k

Copy link
Copy Markdown
Member Author

Oh, this is interesting:

🔴 filesystem: fail: failed to read active mountpoints: failed to run lsblk: exit status 1 (exit 1, stderr: lsblk: unknown column: MOUNTPOINTS,FSTYPE)

Another case where we changed a test but didn't run it because of caching.

This is a RHEL 8 failure.

Getting fixed in #2344.

@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch from d66d2f0 to 570875f Compare May 20, 2026 15:32
@achilleas-k

Copy link
Copy Markdown
Member Author

New failure seems to only happen when I run the tests in a container

@achilleas-k

Copy link
Copy Markdown
Member Author

New failure seems to only happen when I run the tests in a container

The good news is they're not resolver-related. The new tests that were introduced in the first commit fail to run inside a container. I'll need to fix them up.

@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch from 570875f to 20edd8e Compare May 20, 2026 19:22
@achilleas-k

achilleas-k commented May 20, 2026 •

Copy link
Copy Markdown
Member Author

Still need to fix the container situation for s390x and ppc64le but the rest should be good.

@achilleas-k
achilleas-k requested a review from thozza as a code owner May 20, 2026 21:10
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch 2 times, most recently from e401262 to bda416e Compare May 20, 2026 21:38
GetDefaultAuthFile():
- Determines the auth file path to use for connecting to container
  registries.
- Skip any test that limits the read permissions on files when running
  as root.  The behaviour can't be tested because root can always read
  the files.

ApplyDefaultDomainPath():
- Applies the default domain and path to bare container references.

SetArchitectureChoice():
- Sets the container client's internal architecture and variant, mapping
  common names to their container equivalents.

GetManifest():
- Retrieves manifests lists or image manifests from a container registry
  or local storage.  Two tests are added, one that uses a registry and
  the other using local storage.
- The test that requires local storage is run using the
  --force-local-resolver option only, along with the existing similar
  tests.
The values on the container.Spec itself are plain strings, so let's pass
the actual values that will be used.

This is the first step in removing the github.com/containers/image
dependency.
The digest and imageID changes were made for consistency.
New client method that runs `skopeo inspect --raw` on a given ref.  It
reads configuration options from the client (tls-verify and authfile)
and adds the appropriate command line flags.  Returns raw bytes.
Resolve remote manifests and container configs using skopeo.

GetManifestSkopeo() is an alternative implementation of GetManifest()
but uses skopeo instead of the container library.

The current implementation does not yet support resolving local
manifests.
Make GetManifestSkopeo() easier to read by extracting some functionality
that we will probably want to reuse.

- nameFromRef(): removes the tag or image ID suffixes from a container
  ref to return the name.
- parseMediaType(): returns the media type of a json blob returned from
  querying a registry by parsing the data into a minimal structure that
  only holds the schema version and the media type itself.
Get an image manifest from local storage using skopeo.

This function is the equivalent to getImageRef() with local=true, but
using skopeo instead of relying on the containers library.
Resolve an image's ID from an image digest in the local containers
storage.  This function is needed to resolve the manifest of an image in
the local containers storage using from a manifest digest.

The function uses podman to retrieve the information of all images in
the containers storage and iterates until it finds the given digest.

This function is the equivalent to the existing
getLocalImageIDFromDigest() but avoids using the containers library.

The function uses podman since it's not possible to do the same with
skopeo.

The usefulness of this function is questionable.  It is the local
equivalent of a very common action: Resolving a ref that points to a
multi-arch manifest list into a single image ID.  However, while this
requirement is pretty much necessary for remote containers, as most refs
will point to a manifest list (image index), it should be trivial for a
user to retrieve the image ID of the exact container they want to
resolve rather than rely on the multi-arch ref in their local storage.
When creating a new container client, initialise the architecture choice
to the host architecture.
Uses our own sample containers.
Copied from the embed-containers configs.

The embed-containers configs are only used with ostree-based builds to
test workarounds for quirks with embedding containers into ostree
commits.  Adding containers to all-customizations expands the test
surface for the feature.
Remove the old GetManifest() function and rename GetManifestSkopeo() to
GetManifest().
Also remove any private functions that are no longer in use.

For consistency, also rename getLocalManifestSkopeo() to
getLocalManifest().

The existing GetManifest() tests cover all the functionality of the new
functions.
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch from bda416e to 327259a Compare May 20, 2026 21:47
Our testregistry, a toy container registry for testing, was a bit clumsy
with its map handling.  While not thread safe, the tests didn't trip up
the race detector before, presumably because the tests themselves,
through the resolver that used the container library, had different
timings or execution patterns compared to the new resolver.

This commit changes all maps in the testregistry to SyncMaps, which are
simple generic structs that hold a map and a mutex lock.  Add() and
Get() methods handle writing to and reading from the maps safely.
The original version of this script was in a commit message in osbuild
when we first created the multi-arch manifest for testing.  It's now
expanded to create containers for all 4 architectures.  It also
differentiates the contents a little bit between architectures.

The script has already been used to create the containers and they have
been pushed to the gitlab registry.

Updated imgtestlib unit tests to match new digests and IDs.
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image branch from b821190 to 47f9885 Compare May 20, 2026 22:00

@thozza thozza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

}
}

require.Equal(expected, container.GetDefaultAuthFile())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick: Personally, I find it a bit odd that the expected value is not part of the test case definition. The test case definition is more of a setup definition and the actual expected values are determined in the test runner. I mean, all of this looks reasonable, but I have a hard time double-checking what the test actually verifies. FWIW, you do not need to test the full path set in the ENV variable, you could just define the default and then a different filename for each scenario (or env variable). The temporary path is IMHO not that important if the filename is always different.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a very good point. I think another way around the issue, now that I think about it, is the test can have a global tmpdir root and the test cases can be set up after creating the tmpdir, so an element in the test matrix could be

{
    name: "authfile",
    authEnvFile: filepath.Join(tmpdir, "really-cool-authfile.json"),
},

I think that would take care of the readability while also matching full paths.

@kingsleyzissou kingsleyzissou left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ohhh this is very nice

@thozza
thozza added this pull request to the merge queue May 21, 2026
Merged via the queue into osbuild:main with commit 3371fb0 May 21, 2026
20 checks passed
@achilleas-k
achilleas-k deleted the drop-dep/containers-image branch May 21, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants