From a1577ec7b05ba70b6c4579afebfa953c73e79a37 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 24 Oct 2023 20:15:47 -0400 Subject: [PATCH] podman build --remote URI Dockerfile shoud not be treated as file Podman build --remote is translating https://path as if it was a file path. This change will leave it as a URL so it can be parsed on the server side. Fixed: https://github.com/containers/podman/issues/20475 Signed-off-by: Daniel J Walsh --- pkg/api/handlers/compat/images_build.go | 8 +++++++- pkg/bindings/images/build.go | 5 +++++ test/system/070-build.bats | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 40741f56c6e7..dffd33dcfce6 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -224,8 +224,14 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { // it's not json, assume just a string m = []string{query.Dockerfile} } + for _, containerfile := range m { - containerFiles = append(containerFiles, filepath.Join(contextDirectory, filepath.Clean(filepath.FromSlash(containerfile)))) + // Add path to containerfile iff it is not URL + if !(strings.HasPrefix(containerfile, "http://") || strings.HasPrefix(containerfile, "https://")) { + containerfile = filepath.Join(contextDirectory, + filepath.Clean(filepath.FromSlash(containerfile))) + } + containerFiles = append(containerFiles, containerfile) } dockerFileSet = true } diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 22244885fcb2..9ba899344ab3 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -431,6 +431,11 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO dontexcludes := []string{"!Dockerfile", "!Containerfile", "!.dockerignore", "!.containerignore"} for _, c := range containerFiles { + // Don not add path to containerfile if it is a URL + if strings.HasPrefix(c, "http://") || strings.HasPrefix(c, "https://") { + newContainerFiles = append(newContainerFiles, c) + continue + } if c == "/dev/stdin" { content, err := io.ReadAll(os.Stdin) if err != nil { diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 22cb13d17d59..1b1efe950ddc 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -1135,6 +1135,12 @@ EOF run_podman rmi -f build_test } +@test "podman build --file=https" { + run_podman build -t build_test --file=https://raw.githubusercontent.com/containers/podman/main/test/build/from-scratch/Dockerfile $PODMAN_TMPDIR + + run_podman rmi -f build_test +} + function teardown() { # A timeout or other error in 'build' can leave behind stale images # that podman can't even see and which will cascade into subsequent