From 0793a58343a49b2ed30d3da2d10dd5f14cc13f1a Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 17 Mar 2022 10:40:55 -0400 Subject: Deduplicate between Volumes and Mounts in compat API Docker Compose v2.0 passes mount specifications in two different places: Volumes (just the destination) and Mounts (full info provided - source, destination, etc). This was causing Podman to refuse to create containers, as the destination was used twice. Deduplicate between Mounts and Volumes, preferring volumes, to resolve this. Fixes #11822 Signed-off-by: Matthew Heon --- cmd/podman/common/create_opts.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index b110b3d85..e5a2a0da3 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -97,12 +97,21 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c } // mounts type=tmpfs/bind,source=...,target=...=,opt=val + volSources := make(map[string]bool) + volDestinations := make(map[string]bool) mounts := make([]string, 0, len(cc.HostConfig.Mounts)) var builder strings.Builder for _, m := range cc.HostConfig.Mounts { addField(&builder, "type", string(m.Type)) addField(&builder, "source", m.Source) addField(&builder, "target", m.Target) + + // Store source/dest so we don't add duplicates if a volume is + // also mentioned in cc.Volumes. + // Which Docker Compose v2.0 does, for unclear reasons... + volSources[m.Source] = true + volDestinations[m.Target] = true + if m.ReadOnly { addField(&builder, "ro", "true") } @@ -328,8 +337,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c } // volumes - volSources := make(map[string]bool) - volDestinations := make(map[string]bool) for _, vol := range cc.HostConfig.Binds { cliOpts.Volume = append(cliOpts.Volume, vol) // Extract the destination so we don't add duplicate mounts in @@ -348,6 +355,8 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c // format of `-v` so we can just append them in there. // Unfortunately, these may be duplicates of existing mounts in Binds. // So... We need to catch that. + // This also handles volumes duplicated between cc.HostConfig.Mounts and + // cc.Volumes, as seen in compose v2.0. for vol := range cc.Volumes { if _, ok := volDestinations[filepath.Clean(vol)]; ok { continue -- cgit v1.2.3-54-g00ecf From bde3ca8c363bfbd0f50fe9c787960836212e0167 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 17 Mar 2022 14:15:32 -0400 Subject: Add tests with Docker Compose v2 Add a pair of new Cirrus test suites using Compose v2 instead of Compose v1 (as is currently packaged in Fedora). They work identically, and run the same tests, as the Compose v1 tests, but with the new v2 binary instead. [NO NEW TESTS NEEDED] This adds an entire Cirrus suite... Signed-off-by: Matthew Heon --- .cirrus.yml | 11 +++++++++-- contrib/cirrus/runner.sh | 4 ++++ contrib/cirrus/setup_environment.sh | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 7e523c4ae..0752901ab 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -429,7 +429,7 @@ apiv2_test_task: compose_test_task: - name: "compose test on $DISTRO_NV ($PRIV_NAME)" + name: "$TEST_FLAVOR test on $DISTRO_NV ($PRIV_NAME)" alias: compose_test only_if: *not_build skip: *tags @@ -438,11 +438,18 @@ compose_test_task: gce_instance: *standardvm env: <<: *stdenvars - TEST_FLAVOR: compose matrix: - env: + TEST_FLAVOR: compose PRIV_NAME: root - env: + TEST_FLAVOR: compose + PRIV_NAME: rootless + - env: + TEST_FLAVOR: compose_v2 + PRIV_NAME: root + - env: + TEST_FLAVOR: compose_v2 PRIV_NAME: rootless clone_script: *noop # Comes from cache gopath_cache: *ro_gopath_cache diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh index d1d87ad04..1bff07203 100755 --- a/contrib/cirrus/runner.sh +++ b/contrib/cirrus/runner.sh @@ -63,6 +63,10 @@ function _run_compose() { ./test/compose/test-compose |& logformatter } +function _run_compose_v2() { + ./test/compose/test-compose |& logformatter +} + function _run_int() { dotest integration } diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh index 696560166..864c78484 100755 --- a/contrib/cirrus/setup_environment.sh +++ b/contrib/cirrus/setup_environment.sh @@ -272,6 +272,11 @@ case "$TEST_FLAVOR" in ;; build) make clean ;; unit) ;; + compose_v2) + dnf -y remove docker-compose + curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + ;& # Continue with next item apiv2) msg "Installing previously downloaded/cached packages" dnf install -y $PACKAGE_DOWNLOAD_DIR/python3*.rpm -- cgit v1.2.3-54-g00ecf From 4b359e4598ec795b8eff3dfebae52b17c195c22b Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 17 Mar 2022 15:16:13 -0400 Subject: Set names in compose tests based on version Compose v2 uses dashes as separators instead of hyphens. This broke some tests that relied upon container names. Set the name conditionally to make it safe for both. Signed-off-by: Matthew Heon --- test/compose/ipam_set_ip/tests.sh | 6 +++++- test/compose/two_networks/tests.sh | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/compose/ipam_set_ip/tests.sh b/test/compose/ipam_set_ip/tests.sh index ecaf3167e..b9e761ea2 100644 --- a/test/compose/ipam_set_ip/tests.sh +++ b/test/compose/ipam_set_ip/tests.sh @@ -1,4 +1,8 @@ # -*- bash -*- -podman container inspect ipam_set_ip_test_1 --format '{{ .NetworkSettings.Networks.ipam_set_ip_net1.IPAddress }}' +ctr_name="ipam_set_ip_test_1" +if [ "$TEST_FLAVOR" = "compose_v2" ]; then + ctr_name="ipam_set_ip-test-1" +fi +podman container inspect "$ctr_name" --format '{{ .NetworkSettings.Networks.ipam_set_ip_net1.IPAddress }}' like "$output" "10.123.0.253" "$testname : ip address is set" diff --git a/test/compose/two_networks/tests.sh b/test/compose/two_networks/tests.sh index 1cc88aa5f..af0d1fbe3 100644 --- a/test/compose/two_networks/tests.sh +++ b/test/compose/two_networks/tests.sh @@ -1,7 +1,11 @@ # -*- bash -*- -podman container inspect two_networks_con1_1 --format '{{len .NetworkSettings.Networks}}' +ctr_name="two_networks_con1_1" +if [ "$TEST_FLAVOR" = "compose_v2" ]; then + ctr_name="two_networks-con1-1" +fi +podman container inspect "$ctr_name" --format '{{len .NetworkSettings.Networks}}' is "$output" "2" "$testname : Container is connected to both networks" -podman container inspect two_networks_con1_1 --format '{{.NetworkSettings.Networks}}' +podman container inspect "$ctr_name" --format '{{.NetworkSettings.Networks}}' like "$output" "two_networks_net1" "$testname : First network name exists" like "$output" "two_networks_net2" "$testname : Second network name exists" -- cgit v1.2.3-54-g00ecf