Skip to content

Commit

Permalink
Merge pull request #19632 from mheon/backport_18577_441rhel
Browse files Browse the repository at this point in the history
Backport #18577 to v4.4.1-rhel
  • Loading branch information
openshift-merge-robot authored Aug 16, 2023
2 parents ff30585 + 523d49d commit dd490ff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
6 changes: 4 additions & 2 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
33 changes: 20 additions & 13 deletions pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,24 +637,24 @@ 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
}

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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/apiv2/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 4 additions & 10 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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"))
})
Expand Down
2 changes: 1 addition & 1 deletion test/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dd490ff

Please sign in to comment.