From e0654150d07a4974b6b587918e400066eea3936f Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 15 May 2023 16:18:21 -0400 Subject: [PATCH 1/2] Support podman --remote when Containerfile is not in context directory Fixes: https://github.com/containers/podman/issues/18239 [NO NEW TESTS NEEDED] @test "podman build -f test" in test/system/070-build.bats Will test this. This was passing when run on a local system since the remote end was using the clients path to read the Containerfile The issue is it would not work in a podman machine since the Containerfile would/should be a different path. Signed-off-by: Daniel J Walsh Signed-off-by: Matt Heon --- pkg/api/handlers/compat/images_build.go | 6 +++-- pkg/bindings/images/build.go | 33 +++++++++++++++---------- test/e2e/build_test.go | 14 +++-------- 3 files changed, 28 insertions(+), 25 deletions(-) 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/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")) }) From 523d49d9771ca66ff81e4ea837b9c81342f4721b Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Mon, 24 Jul 2023 11:38:53 -0400 Subject: [PATCH 2/2] [v4.4.1-rhel] Fix AttributeError: cython_sources Apparent Cython regression causing a warning and traceback when installing PyYAML with pip: Ref. Upstream issue 601: https://github.com/yaml/pyyaml/issues/ Ref. warning message: ``` ******************************************************************************** The license_file parameter is deprecated, use license_files instead. By 2023-Oct-30, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details. ******************************************************************************** ``` Ref. traceback snippet: ``` Traceback (most recent call last): File "/var/tmp/go/src/github.com/containers/podman/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in main() ...cut... File "", line 201, in get_source_files File "/tmp/pip-build-env-yiijk0jv/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__ raise AttributeError(attr) AttributeError: cython_sources ``` Signed-off-by: Chris Evich Signed-off-by: Matt Heon --- test/apiv2/python/requirements.txt | 2 +- test/python/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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