summaryrefslogtreecommitdiff
path: root/pkg/bindings/images/build.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-06-03 11:00:04 -0400
committerMatthew Heon <mheon@redhat.com>2021-06-11 11:14:04 -0400
commit2afb5eeab672f6b10cda78f4d6bc152cf1e9a769 (patch)
treea1ec0fb70cbeae255954596c967e2a3dbaacb4e7 /pkg/bindings/images/build.go
parent6beae86f014ceb1ad2f0a33b626b7881bf17e419 (diff)
downloadpodman-2afb5eeab672f6b10cda78f4d6bc152cf1e9a769.tar.gz
podman-2afb5eeab672f6b10cda78f4d6bc152cf1e9a769.tar.bz2
podman-2afb5eeab672f6b10cda78f4d6bc152cf1e9a769.zip
podman-remote build should handle -f option properly
podman-remote build has to handle multiple different locations for the Containerfile. Currently this works in local mode but not when using podman-remote. Fixes: https://github.com/containers/podman/issues/9871 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/bindings/images/build.go')
-rw-r--r--pkg/bindings/images/build.go64
1 files changed, 42 insertions, 22 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 346d55c47..c7d432b16 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -282,10 +282,6 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
stdout = options.Out
}
- entries := make([]string, len(containerFiles))
- copy(entries, containerFiles)
- entries = append(entries, options.ContextDirectory)
-
excludes := options.Excludes
if len(excludes) == 0 {
excludes, err = parseDockerignore(options.ContextDirectory)
@@ -294,33 +290,57 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
}
}
- tarfile, err := nTar(excludes, entries...)
+ contextDir, err := filepath.Abs(options.ContextDirectory)
if err != nil {
- logrus.Errorf("cannot tar container entries %v error: %v", entries, err)
+ logrus.Errorf("cannot find absolute path of %v: %v", options.ContextDirectory, err)
return nil, err
}
- defer func() {
- if err := tarfile.Close(); err != nil {
- logrus.Errorf("%v\n", err)
+
+ tarContent := []string{options.ContextDirectory}
+ newContainerFiles := []string{}
+ for _, c := range containerFiles {
+ containerfile, err := filepath.Abs(c)
+ if err != nil {
+ logrus.Errorf("cannot find absolute path of %v: %v", c, err)
+ return nil, err
}
- }()
- containerFile, err := filepath.Abs(entries[0])
- if err != nil {
- logrus.Errorf("cannot find absolute path of %v: %v", entries[0], err)
- return nil, err
+ // Check if Containerfile is in the context directory, if so truncate the contextdirectory off path
+ // Do NOT add to tarfile
+ if strings.HasPrefix(containerfile, contextDir+string(filepath.Separator)) {
+ containerfile = strings.TrimPrefix(containerfile, contextDir+string(filepath.Separator))
+ } else {
+ // If Containerfile does not exists assume it is in context directory, do Not add to tarfile
+ if _, err := os.Lstat(containerfile); err != nil {
+ if !os.IsNotExist(err) {
+ return nil, err
+ }
+ containerfile = c
+ } else {
+ // If Containerfile does exists but is not in context directory add it to the tarfile
+ tarContent = append(tarContent, containerfile)
+ }
+ }
+ newContainerFiles = append(newContainerFiles, containerfile)
}
- contextDir, err := filepath.Abs(entries[1])
- if err != nil {
- logrus.Errorf("cannot find absolute path of %v: %v", entries[1], err)
- return nil, err
+ if len(newContainerFiles) > 0 {
+ cFileJSON, err := json.Marshal(newContainerFiles)
+ if err != nil {
+ return nil, err
+ }
+ params.Set("dockerfile", string(cFileJSON))
}
- if strings.HasPrefix(containerFile, contextDir+string(filepath.Separator)) {
- containerFile = strings.TrimPrefix(containerFile, contextDir+string(filepath.Separator))
+ tarfile, err := nTar(excludes, tarContent...)
+ if err != nil {
+ logrus.Errorf("cannot tar container entries %v error: %v", tarContent, err)
+ return nil, err
}
-
- params.Set("dockerfile", containerFile)
+ defer func() {
+ if err := tarfile.Close(); err != nil {
+ logrus.Errorf("%v\n", err)
+ }
+ }()
conn, err := bindings.GetClient(ctx)
if err != nil {