From 48ae52c08b49bd88a954e1b02061ed4e1d2b672f Mon Sep 17 00:00:00 2001 From: James Hewitt Date: Mon, 25 Nov 2024 16:10:56 +0000 Subject: [PATCH 1/2] Add a test for forcing compression and v2s2 format This highlights a bug in common where the compression format is reset if the format is v2s2, even if its a valid compression format. Signed-off-by: James Hewitt --- test/e2e/push_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index d18e87ae0b..1b4ae01db0 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -141,6 +141,47 @@ var _ = Describe("Podman push", func() { Expect(output).To(ContainSubstring("zstd")) }) + It("push test --force-compression --format=v2s2", func() { + if podmanTest.Host.Arch == "ppc64le" { + Skip("No registry image for ppc64le") + } + if isRootless() { + err := podmanTest.RestoreArtifact(REGISTRY_IMAGE) + Expect(err).ToNot(HaveOccurred()) + } + lock := GetPortLock("5005") + defer lock.Unlock() + session := podmanTest.Podman([]string{"run", "-d", "--name", "registry", "-p", "5005:5000", REGISTRY_IMAGE, "/entrypoint.sh", "/etc/docker/registry/config.yml"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + + if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) { + Skip("Cannot start docker registry.") + } + + session = podmanTest.Podman([]string{"build", "-t", "imageone", "build/basicalpine"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + + push := podmanTest.Podman([]string{"push", "-q", "--tls-verify=false", "--force-compression=true", "--compression-format", "gzip", "--format", "v2s2", "--remove-signatures", "imageone", "localhost:5005/image"}) + push.WaitWithDefaultTimeout() + Expect(push).Should(ExitCleanly()) + + skopeoInspect := []string{"inspect", "--tls-verify=false", "--raw", "docker://localhost:5005/image:latest"} + skopeo := SystemExec("skopeo", skopeoInspect) + skopeo.WaitWithDefaultTimeout() + Expect(skopeo).Should(ExitCleanly()) + output := skopeo.OutputToString() + Expect(output).To(ContainSubstring("gzip")) + + push = podmanTest.Podman([]string{"push", "-q", "--tls-verify=false", "--force-compression=true", "--compression-format", "zstd", "--format", "v2s2", "--remove-signatures", "imageone", "localhost:5005/image"}) + push.WaitWithDefaultTimeout() + // the command is asking for an impossible thing; per containers/common#1869, we should detect + // that and fail with a precise error, but that does not exist, so we end up reporting this + // misleading text. When that is resolved, this test will need updating. + Expect(push).Should(ExitWithError(125, "cannot use ForceCompressionFormat with undefined default compression format")) + }) + It("podman push to local registry", func() { if podmanTest.Host.Arch == "ppc64le" { Skip("No registry image for ppc64le") From 43825122d4f0826ce5dd512799e2db46dab8609c Mon Sep 17 00:00:00 2001 From: James Hewitt Date: Fri, 29 Nov 2024 13:34:43 +0000 Subject: [PATCH 2/2] Switch to fixed common Signed-off-by: James Hewitt --- go.mod | 2 +- go.sum | 4 ++-- .../github.com/containers/common/libimage/push.go | 13 +++++++++++-- .../containers/common/libnetwork/types/network.go | 4 +++- .../containers/common/pkg/config/config.go | 7 +++++++ .../containers/common/pkg/config/containers.conf | 8 ++++++++ .../common/pkg/config/containers.conf-freebsd | 6 ++++++ vendor/modules.txt | 2 +- 8 files changed, 39 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 2aa308299f..9872bf8442 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/checkpoint-restore/go-criu/v7 v7.2.0 github.com/containernetworking/plugins v1.5.1 github.com/containers/buildah v1.38.1-0.20241119213149-52437ef15d33 - github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0 + github.com/containers/common v0.61.1-0.20241202111335-2d4a9a65dd81 github.com/containers/conmon v2.0.20+incompatible github.com/containers/gvisor-tap-vsock v0.8.0 github.com/containers/image/v5 v5.33.0 diff --git a/go.sum b/go.sum index 9f0d847d68..9f08e3ac3b 100644 --- a/go.sum +++ b/go.sum @@ -81,8 +81,8 @@ github.com/containernetworking/plugins v1.5.1 h1:T5ji+LPYjjgW0QM+KyrigZbLsZ8jaX+ github.com/containernetworking/plugins v1.5.1/go.mod h1:MIQfgMayGuHYs0XdNudf31cLLAC+i242hNm6KuDGqCM= github.com/containers/buildah v1.38.1-0.20241119213149-52437ef15d33 h1:Ih6KuyByK7ZGGzkS0M5rVBPLWIyeDvdL5klhsKBo8vA= github.com/containers/buildah v1.38.1-0.20241119213149-52437ef15d33/go.mod h1:RxIuKhwTpRl3ma4d4BF6QzSSeg9zNNvo/xhYJOKeDQs= -github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0 h1:Vh8IytxprODmjd4sALcSVUzhT28vT537UWsfCXcahWk= -github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0/go.mod h1:3mUU2/PxkOwvL46fmaRVj0YfBDBxNPOMctIvBHWo4Ak= +github.com/containers/common v0.61.1-0.20241202111335-2d4a9a65dd81 h1:Nw7YRDWv0ZO/AINzOeyR2KnJyfcIz1Ek3Ube/akl4U4= +github.com/containers/common v0.61.1-0.20241202111335-2d4a9a65dd81/go.mod h1:ySiyZ85+F3xk7kcQvaZo0Ii67Hma7T4JEeILEQPWEKY= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/gvisor-tap-vsock v0.8.0 h1:Z8ZEWb+Lio0d+lXexONdUWT4rm9lF91vH0g3ARnMy7o= diff --git a/vendor/github.com/containers/common/libimage/push.go b/vendor/github.com/containers/common/libimage/push.go index dc99344808..cac8fb6024 100644 --- a/vendor/github.com/containers/common/libimage/push.go +++ b/vendor/github.com/containers/common/libimage/push.go @@ -12,6 +12,7 @@ import ( dockerDaemonTransport "github.com/containers/image/v5/docker/daemon" "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/manifest" + compressiontypes "github.com/containers/image/v5/pkg/compression/types" "github.com/containers/image/v5/transports/alltransports" "github.com/sirupsen/logrus" ) @@ -86,8 +87,16 @@ func (r *Runtime) Push(ctx context.Context, source, destination string, options destRef = dockerRef } - // docker-archive and only DockerV2Schema2MediaType support Gzip compression - if options.CompressionFormat != nil && + // docker-archive and DockerV2Schema2MediaType support only Gzip compression + // If the CompressionFormat has come from containers.conf (set as a default), + // but isn't supported for this push, we want to ignore it. + // If the CompressionFormat has come from the CLI (ForceCompressionFormat + // requires CompressionFormat to be set), we want to strip the invalid value + // so that the push attempt fails. + // + // Ideally this should all happen at a much higher layer, where the code can differentiate + // between a value coming from containers.conf vs. the CLI. + if options.CompressionFormat != nil && options.CompressionFormat.Name() != compressiontypes.GzipAlgorithmName && (destRef.Transport().Name() == dockerArchiveTransport.Transport.Name() || destRef.Transport().Name() == dockerDaemonTransport.Transport.Name() || options.ManifestMIMEType == manifest.DockerV2Schema2MediaType) { diff --git a/vendor/github.com/containers/common/libnetwork/types/network.go b/vendor/github.com/containers/common/libnetwork/types/network.go index 2b941abd43..b949928dab 100644 --- a/vendor/github.com/containers/common/libnetwork/types/network.go +++ b/vendor/github.com/containers/common/libnetwork/types/network.go @@ -277,7 +277,7 @@ type PerNetworkOptions struct { type NetworkOptions struct { // ContainerID is the container id, used for iptables comments and ipam allocation. ContainerID string `json:"container_id"` - // ContainerName is the container name, used as dns name. + // ContainerName is the container name. ContainerName string `json:"container_name"` // PortMappings contains the port mappings for this container PortMappings []PortMapping `json:"port_mappings,omitempty"` @@ -287,6 +287,8 @@ type NetworkOptions struct { // List of custom DNS server for podman's DNS resolver. // Priority order will be kept as defined by user in the configuration. DNSServers []string `json:"dns_servers,omitempty"` + // ContainerHostname is the configured DNS hostname of the container. + ContainerHostname string `json:"container_hostname"` } // PortMapping is one or more ports that will be mapped into the container. diff --git a/vendor/github.com/containers/common/pkg/config/config.go b/vendor/github.com/containers/common/pkg/config/config.go index 2d6bf276af..7a625efe05 100644 --- a/vendor/github.com/containers/common/pkg/config/config.go +++ b/vendor/github.com/containers/common/pkg/config/config.go @@ -96,6 +96,13 @@ type ContainersConfig struct { // "memory.high=1073741824" sets the memory.high limit to 1GB. CgroupConf attributedstring.Slice `toml:"cgroup_conf,omitempty"` + // When no hostname is set for a container, use the container's name, with + // characters not valid for a hostname removed, as the hostname instead of + // the first 12 characters of the container's ID. Containers not running + // in a private UTS namespace will have their hostname set to the host's + // hostname regardless of this setting. + ContainerNameAsHostName bool `toml:"container_name_as_hostname,omitempty"` + // Capabilities to add to all containers. DefaultCapabilities attributedstring.Slice `toml:"default_capabilities,omitempty"` diff --git a/vendor/github.com/containers/common/pkg/config/containers.conf b/vendor/github.com/containers/common/pkg/config/containers.conf index 236b51204a..0d22bcf380 100644 --- a/vendor/github.com/containers/common/pkg/config/containers.conf +++ b/vendor/github.com/containers/common/pkg/config/containers.conf @@ -58,6 +58,14 @@ # #cgroups = "enabled" +# When no hostname is set for a container, use the container's name, with +# characters not valid for a hostname removed, as the hostname instead of +# the first 12 characters of the container's ID. Containers not running +# in a private UTS namespace will have their hostname set to the host's +# hostname regardless of this setting. +# +#container_name_as_hostname = false + # List of default capabilities for containers. If it is empty or commented out, # the default capabilities defined in the container engine will be added. # diff --git a/vendor/github.com/containers/common/pkg/config/containers.conf-freebsd b/vendor/github.com/containers/common/pkg/config/containers.conf-freebsd index 894153ed33..f5b51dd226 100644 --- a/vendor/github.com/containers/common/pkg/config/containers.conf-freebsd +++ b/vendor/github.com/containers/common/pkg/config/containers.conf-freebsd @@ -29,6 +29,12 @@ # #base_hosts_file = "" +# When no hostname is set for a container, use the container's name, with +# characters not valid for a hostname removed, as the hostname instead of +# the first 12 characters of the container's ID. +# +#container_name_as_hostname = false + # The database backend of Podman. Supported values are "" (default), "boltdb" # and "sqlite". An empty value means it will check whenever a boltdb already # exists and use it when it does, otherwise it will use sqlite as default diff --git a/vendor/modules.txt b/vendor/modules.txt index a08736dbde..c20ad3e900 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -174,7 +174,7 @@ github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/pkg/volumes github.com/containers/buildah/util -# github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0 +# github.com/containers/common v0.61.1-0.20241202111335-2d4a9a65dd81 ## explicit; go 1.22.6 github.com/containers/common/internal github.com/containers/common/internal/attributedstring