Skip to content

Commit 8ba5168

Browse files
authored
Merge pull request #11 from apenella/fix-relativepath-tar-context-path
Fix relativepath tar context path
2 parents 0c7d8d7 + 6348b50 commit 8ba5168

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

examples/build-path-context/build.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func main() {
1818
var dockerCli *client.Client
1919

2020
imageDefinitionPath := filepath.Join(".", "files")
21-
2221
registry := "registry"
2322
namespace := "namespace"
2423
imageName := strings.Join([]string{registry, namespace, "ubuntu"}, "/")
@@ -34,7 +33,7 @@ func main() {
3433

3534
dockerBuildOptions := &build.DockerBuildOptions{
3635
ImageName: imageName,
37-
Dockerfile: "Dockerfile",
36+
Dockerfile: filepath.Join("Dockerfile"),
3837
Tags: []string{strings.Join([]string{imageName, "tag1"}, ":")},
3938
DockerBuildContext: dockerBuildContext,
4039
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
FROM ubuntu
22

3-
RUN apt-get update \
4-
&& apt-get upgrade -y
5-
3+
COPY etc/config/file.cfg /tmp

examples/build-path-context/files/etc/config/file.cfg

Whitespace-only changes.

pkg/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const (
1717
// DefaultDockerfile is the default filename for Dockerfile
18-
DefaultDockerfile = "Dockerfile"
18+
DefaultDockerfile string = "Dockerfile"
1919
)
2020

2121
// DockerBuilderCmd

pkg/common/tar/tar.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"os"
99
"path/filepath"
10-
"strings"
1110
)
1211

1312
// Tar return an tar io.Reader from the gived directory. It returns an error when the file is not a directory.
@@ -44,8 +43,11 @@ func Tar(path *os.File) (io.Reader, error) {
4443
if err != nil {
4544
return errors.New("(common::tar::Tar::Walk) Error creating '" + file + "' header. " + err.Error())
4645
}
47-
// update the name to correctly reflect the desired destination when untaring
48-
header.Name = strings.TrimPrefix(strings.Replace(file, path.Name(), "", -1), string(filepath.Separator))
46+
relativePath, err := filepath.Rel(path.Name(), file)
47+
if err != nil {
48+
return errors.New("(common::tar::Tar::Walk) A relative path on'" + file + "' could not be made from '" + path.Name() + "'. " + err.Error())
49+
}
50+
header.Name = relativePath
4951

5052
// write the header
5153
if err := tw.WriteHeader(header); err != nil {
@@ -55,7 +57,7 @@ func Tar(path *os.File) (io.Reader, error) {
5557
// open files for taring
5658
f, err := os.Open(file)
5759
if err != nil {
58-
return err
60+
return errors.New("(common::tar::Tar::Walk) Error opening '" + file + "'. " + err.Error())
5961
}
6062

6163
if _, err := io.Copy(tw, f); err != nil {
@@ -68,7 +70,7 @@ func Tar(path *os.File) (io.Reader, error) {
6870
return nil
6971
})
7072
if err != nil {
71-
return nil, errors.New("(common::tar::Tar) Error explorint '" + path.Name() + "'. " + err.Error())
73+
return nil, errors.New("(common::tar::Tar) Error exploring '" + path.Name() + "'. " + err.Error())
7274
}
7375

7476
return bytes.NewReader(tarBuff.Bytes()), nil

0 commit comments

Comments
 (0)