diff options
author | cdoern <cbdoer23@g.holycross.edu> | 2022-03-15 12:13:41 -0400 |
---|---|---|
committer | cdoern <cbdoer23@g.holycross.edu> | 2022-03-22 10:33:05 -0400 |
commit | 5e1e13c18c22e2cd43021cb647eda328324f6c96 (patch) | |
tree | 5b71e120fcefdde1e39e52735747ab09ee174cb4 | |
parent | e59f71d230cf5435dc569add90e22cc644e38647 (diff) | |
download | podman-5e1e13c18c22e2cd43021cb647eda328324f6c96.tar.gz podman-5e1e13c18c22e2cd43021cb647eda328324f6c96.tar.bz2 podman-5e1e13c18c22e2cd43021cb647eda328324f6c96.zip |
add contextDir to tar on remote
podman build fails on remote build when using a relative context directory.
This is because the context dir was not being added to the tar, so when remote
the compat build function would not be able to stat the contextDir.
resolves #13293
Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
-rw-r--r-- | pkg/bindings/images/build.go | 26 | ||||
-rw-r--r-- | test/e2e/build_test.go | 5 |
2 files changed, 22 insertions, 9 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index c508cb767..1ed3f19de 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -241,7 +241,9 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO params.Add("platform", platform) } } - if contextDir, err := filepath.EvalSymlinks(options.ContextDirectory); err == nil { + var err error + var contextDir string + if contextDir, err = filepath.EvalSymlinks(options.ContextDirectory); err == nil { options.ContextDirectory = contextDir } @@ -301,7 +303,6 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO var ( headers http.Header - err error ) if options.SystemContext != nil && options.SystemContext.DockerAuthConfig != nil { headers, err = auth.MakeXRegistryAuthHeader(options.SystemContext, options.SystemContext.DockerAuthConfig.Username, options.SystemContext.DockerAuthConfig.Password) @@ -325,7 +326,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } } - contextDir, err := filepath.Abs(options.ContextDirectory) + contextDir, err = filepath.Abs(options.ContextDirectory) if err != nil { logrus.Errorf("Cannot find absolute path of %v: %v", options.ContextDirectory, err) return nil, err @@ -556,16 +557,27 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { merr = multierror.Append(merr, err) return } - err = filepath.Walk(s, func(path string, info os.FileInfo, err error) error { if err != nil { return err } - if path == s { - return nil // skip root dir + // 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 info.IsDir() && s == path { + var p *os.File + p, err = os.Open(path) + if err != nil { + return err + } + defer p.Close() + _, err = p.Readdir(1) + if err != io.EOF { + return nil // non empty root dir, need to return + } else if err != nil { + logrus.Errorf("Error while reading directory %v: %v", path, err) + } } - name := filepath.ToSlash(strings.TrimPrefix(path, s+string(filepath.Separator))) excluded, err := pm.Matches(name) // nolint:staticcheck diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index c5903f037..096c98727 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -734,10 +734,11 @@ RUN ls /dev/test1`, ALPINE) err = os.Mkdir("relative", 0755) Expect(err).To(BeNil()) containerFilePath := filepath.Join("relative", "Containerfile") - fmt.Println(containerFilePath) + err = os.Mkdir("relative/build-root", 0755) + Expect(err).To(BeNil()) err = ioutil.WriteFile(containerFilePath, []byte(containerFile), 0755) Expect(err).To(BeNil()) - build := podmanTest.Podman([]string{"build", "-f", "./relative/Containerfile"}) + build := podmanTest.Podman([]string{"build", "-f", "./relative/Containerfile", "./relative/build-root"}) build.WaitWithDefaultTimeout() Expect(build).To(Exit(0)) err = os.RemoveAll("relative") |