From d9aff9b41e0f9b9096c51b6988577b086a807ed6 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 26 Feb 2024 15:20:49 +0100 Subject: [PATCH] podman compose: only trim path suffix when ssh protocol For a unix socket we should not trim this at all. The problem exists for ssh only so make sure we only do this when a ssh URL is given. Signed-off-by: Paul Holzinger --- cmd/podman/compose.go | 7 +++++-- test/system/850-compose.bats | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/podman/compose.go b/cmd/podman/compose.go index f90e5acfe5..cd764e5c61 100644 --- a/cmd/podman/compose.go +++ b/cmd/podman/compose.go @@ -132,10 +132,13 @@ func composeDockerHost() (string, error) { // If the default connection does not point to a `podman // machine`, we cannot use a local path and need to use SSH. if !conf.MachineMode { - // Compose doesn't like paths, so we optimistically + // Docker Compose v1 doesn't like paths for ssh, so we optimistically // assume the presence of a Docker socket on the remote // machine which is the case for podman machines. - return strings.TrimSuffix(conf.URI, parsedConnection.Path), nil + if parsedConnection.Scheme == "ssh" { + return strings.TrimSuffix(conf.URI, parsedConnection.Path), nil + } + return conf.URI, nil } uri, err := getMachineConn(conf.URI, parsedConnection) if err != nil { diff --git a/test/system/850-compose.bats b/test/system/850-compose.bats index 91e6afc267..8d967ad2d8 100644 --- a/test/system/850-compose.bats +++ b/test/system/850-compose.bats @@ -55,10 +55,20 @@ EOF CONTAINERS_CONF_OVERRIDE=$compose_conf run_podman 42 compose fail # Make sure the three env variables are set (and parsed) + op='=~' + url=".*/podman.sock" + # if we run remote with --url check the url arg is honored + if [[ "$PODMAN" =~ "--url" ]]; then + # get the url from the podman string + url="${PODMAN##*--url }" + url="${url%% *}" + op='=' + fi + # podman-remote test might run with --url so unset this because the socket will be used otherwise CONTAINERS_CONF_OVERRIDE=$compose_conf run_podman compose env - is "${lines[0]}" ".*/podman.sock" - is "${lines[1]}" "0" - is "${lines[2]}" "" + assert "${lines[0]}" $op "$url" "line 1 of 3 (DOCKER_HOST)" + assert "${lines[1]}" = "0" "line 2 of 3 (DOCKER_BUILDKIT)" + assert "${lines[2]}" = "" "line 3 of 3 (DOCKER_CONFIG)" DOCKER_HOST="$random_data" DOCKER_CONFIG="$random_data" CONTAINERS_CONF_OVERRIDE=$compose_conf run_podman compose env is "${lines[0]}" "$random_data"