Repository navigation
container: resolve containers using skopeo [RHEL-56367] - #2346
Conversation
|
@kingsleyzissou Added you as a reviewer since you've worked on the local manifest resolution. |
c57363b to
d66d2f0
Compare
|
I missed the test failures when running locally because they only happen with Also I didn't consider that adding our test containers to |
|
Oh, this is interesting: 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. |
d66d2f0 to
570875f
Compare
|
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. |
570875f to
20edd8e
Compare
|
Still need to fix the container situation for s390x and ppc64le but the rest should be good. |
e401262 to
bda416e
Compare
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.
bda416e to
327259a
Compare
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.
b821190 to
47f9885
Compare
| } | ||
| } | ||
|
|
||
| require.Equal(expected, container.GetDefaultAuthFile()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Ohhh this is very nice
This is the first part towards removing our dependency on the
containers/imageGo 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:
exclude_graphdriver_btrfsbuild flag).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.skopeosource 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.