Skip to content

Commit

Permalink
Merge pull request containers#20476 from rhatdan/build
Browse files Browse the repository at this point in the history
podman build --remote URI Dockerfile should not be treated as file
  • Loading branch information
openshift-ci[bot] authored Oct 31, 2023
2 parents 1146f2c + a1577ec commit 3776446
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3776446

Please sign in to comment.