diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 307adfc1a7..f1bee8b502 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -220,9 +220,11 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { var m = []string{} if err := json.Unmarshal([]byte(query.Dockerfile), &m); err != nil { // it's not json, assume just a string - m = []string{filepath.Join(contextDirectory, query.Dockerfile)} + m = []string{query.Dockerfile} + } + for _, containerfile := range m { + containerFiles = append(containerFiles, filepath.Join(contextDirectory, filepath.Clean(filepath.FromSlash(containerfile)))) } - containerFiles = m dockerFileSet = true } } diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index b58153a5a8..32f42a62a3 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -637,14 +637,14 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { defer gw.Close() defer tw.Close() seen := make(map[devino]string) - for _, src := range sources { - s, err := filepath.Abs(src) + for i, src := range sources { + source, err := filepath.Abs(src) if err != nil { logrus.Errorf("Cannot stat one of source context: %v", err) merr = multierror.Append(merr, err) return } - err = filepath.WalkDir(s, func(path string, d fs.DirEntry, err error) error { + err = filepath.WalkDir(source, func(path string, dentry fs.DirEntry, err error) error { if err != nil { return err } @@ -652,9 +652,9 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { separator := string(filepath.Separator) // check if what we are given is an empty dir, if so then continue w/ it. Else return. // if we are given a file or a symlink, we do not want to exclude it. - if s == path { + if source == path { separator = "" - if d.IsDir() { + if dentry.IsDir() { var p *os.File p, err = os.Open(path) if err != nil { @@ -669,8 +669,15 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { } } } - name := filepath.ToSlash(strings.TrimPrefix(path, s+separator)) - + var name string + if i == 0 { + name = filepath.ToSlash(strings.TrimPrefix(path, source+separator)) + } else { + if !dentry.Type().IsRegular() { + return fmt.Errorf("path %s must be a regular file", path) + } + name = filepath.ToSlash(path) + } excluded, err := pm.Matches(name) //nolint:staticcheck if err != nil { return fmt.Errorf("checking if %q is excluded: %w", name, err) @@ -682,8 +689,8 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { return nil } switch { - case d.Type().IsRegular(): // add file item - info, err := d.Info() + case dentry.Type().IsRegular(): // add file item + info, err := dentry.Info() if err != nil { return err } @@ -722,8 +729,8 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { seen[di] = name } return err - case d.IsDir(): // add folders - info, err := d.Info() + case dentry.IsDir(): // add folders + info, err := dentry.Info() if err != nil { return err } @@ -736,12 +743,12 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { if lerr := tw.WriteHeader(hdr); lerr != nil { return lerr } - case d.Type()&os.ModeSymlink != 0: // add symlinks as it, not content + case dentry.Type()&os.ModeSymlink != 0: // add symlinks as it, not content link, err := os.Readlink(path) if err != nil { return err } - info, err := d.Info() + info, err := dentry.Info() if err != nil { return err } diff --git a/test/apiv2/python/requirements.txt b/test/apiv2/python/requirements.txt index d9cfc687a0..6ee2fb1928 100644 --- a/test/apiv2/python/requirements.txt +++ b/test/apiv2/python/requirements.txt @@ -2,4 +2,4 @@ requests-mock~=1.9.3 requests~=2.20.0 setuptools~=50.3.2 python-dateutil~=2.8.1 -PyYAML~=5.4.1 +PyYAML==6.0.1 diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 22e5d419d0..b783007ae4 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -390,14 +390,9 @@ RUN exit 5`, ALPINE) if IsRemote() { podmanTest.StopRemoteService() podmanTest.StartRemoteService() - } else { - Skip("Only valid at remote test, case works fine for regular podman and buildah") } - cwd, err := os.Getwd() - Expect(err).ToNot(HaveOccurred()) - // Write target and fake files - targetSubPath := filepath.Join(cwd, "emptydir") + targetSubPath := filepath.Join(podmanTest.TempDir, "emptydir") if _, err = os.Stat(targetSubPath); err != nil { if os.IsNotExist(err) { err = os.Mkdir(targetSubPath, 0755) @@ -406,13 +401,13 @@ RUN exit 5`, ALPINE) } containerfile := fmt.Sprintf(`FROM %s -COPY /* /dir`, ALPINE) +COPY /emptydir/* /dir`, ALPINE) - containerfilePath := filepath.Join(cwd, "ContainerfilePathToCopier") + containerfilePath := filepath.Join(podmanTest.TempDir, "ContainerfilePathToCopier") err = os.WriteFile(containerfilePath, []byte(containerfile), 0644) Expect(err).ToNot(HaveOccurred()) - session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "ContainerfilePathToCopier", targetSubPath}) + session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "ContainerfilePathToCopier", podmanTest.TempDir}) session.WaitWithDefaultTimeout() // NOTE: Docker and buildah both should error when `COPY /* /dir` is done on emptydir // as context. However buildkit simply ignores this so when buildah also starts ignoring @@ -621,7 +616,6 @@ subdir**` Expect(session).To(Exit(0)) output := session.OutputToString() - Expect(output).NotTo(ContainSubstring("Containerfile")) Expect(output).To(ContainSubstring("/testfilter/expected")) Expect(output).NotTo(ContainSubstring("subdir")) }) diff --git a/test/python/requirements.txt b/test/python/requirements.txt index f177f76fc2..c1e9096c52 100644 --- a/test/python/requirements.txt +++ b/test/python/requirements.txt @@ -3,4 +3,4 @@ requests-mock~=1.9.3 requests~=2.20.0 setuptools~=50.3.2 python-dateutil~=2.8.1 -PyYAML~=5.4.1 +PyYAML==6.0.1