From 9a2a35e556565dda7d2f73b0115e98d5bf94c02e Mon Sep 17 00:00:00 2001 From: Aleix Penella Date: Mon, 7 Sep 2020 09:01:46 +0200 Subject: [PATCH 1/5] set type on DefaultDockerfile const --- pkg/build/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index 8bc3e91..7084e4f 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -15,7 +15,7 @@ import ( const ( // DefaultDockerfile is the default filename for Dockerfile - DefaultDockerfile = "Dockerfile" + DefaultDockerfile string = "Dockerfile" ) // DockerBuilderCmd From 14c2adfc53559565801cedb9f5dcf091911f72ea Mon Sep 17 00:00:00 2001 From: Aleix Penella Date: Mon, 7 Sep 2020 09:04:58 +0200 Subject: [PATCH 2/5] use filepath join when define build options' dockerfile on build-path-context example --- examples/build-path-context/build.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/build-path-context/build.go b/examples/build-path-context/build.go index 6ccee9d..9909b7f 100644 --- a/examples/build-path-context/build.go +++ b/examples/build-path-context/build.go @@ -18,7 +18,6 @@ func main() { var dockerCli *client.Client imageDefinitionPath := filepath.Join(".", "files") - registry := "registry" namespace := "namespace" imageName := strings.Join([]string{registry, namespace, "ubuntu"}, "/") @@ -34,7 +33,7 @@ func main() { dockerBuildOptions := &build.DockerBuildOptions{ ImageName: imageName, - Dockerfile: "Dockerfile", + Dockerfile: filepath.Join("Dockerfile"), Tags: []string{strings.Join([]string{imageName, "tag1"}, ":")}, DockerBuildContext: dockerBuildContext, } From a3f9634bed1f11570fcdd4e3c81e55437e18a140 Mon Sep 17 00:00:00 2001 From: Aleix Penella Date: Mon, 7 Sep 2020 09:05:58 +0200 Subject: [PATCH 3/5] update dockerfile definition on build-path-context --- examples/build-path-context/files/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/build-path-context/files/Dockerfile b/examples/build-path-context/files/Dockerfile index 606be12..daa454e 100644 --- a/examples/build-path-context/files/Dockerfile +++ b/examples/build-path-context/files/Dockerfile @@ -1,5 +1,3 @@ FROM ubuntu -RUN apt-get update \ - && apt-get upgrade -y - +COPY etc/config/file.cfg /tmp From 5a2113e5fabb4fdf3120f04ca4db6db5d40add06 Mon Sep 17 00:00:00 2001 From: Aleix Penella Date: Mon, 7 Sep 2020 09:06:18 +0200 Subject: [PATCH 4/5] update dockerfile definition on build-path-context --- examples/build-path-context/files/etc/config/file.cfg | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/build-path-context/files/etc/config/file.cfg diff --git a/examples/build-path-context/files/etc/config/file.cfg b/examples/build-path-context/files/etc/config/file.cfg new file mode 100644 index 0000000..e69de29 From 6348b50e53ab84fd620b13edf3492e94adc17da2 Mon Sep 17 00:00:00 2001 From: Aleix Penella Date: Mon, 7 Sep 2020 09:08:28 +0200 Subject: [PATCH 5/5] fix file relative path extraction from basedir --- pkg/common/tar/tar.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/common/tar/tar.go b/pkg/common/tar/tar.go index 45ce5aa..a21d6cf 100644 --- a/pkg/common/tar/tar.go +++ b/pkg/common/tar/tar.go @@ -7,7 +7,6 @@ import ( "io" "os" "path/filepath" - "strings" ) // 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) { if err != nil { return errors.New("(common::tar::Tar::Walk) Error creating '" + file + "' header. " + err.Error()) } - // update the name to correctly reflect the desired destination when untaring - header.Name = strings.TrimPrefix(strings.Replace(file, path.Name(), "", -1), string(filepath.Separator)) + relativePath, err := filepath.Rel(path.Name(), file) + if err != nil { + return errors.New("(common::tar::Tar::Walk) A relative path on'" + file + "' could not be made from '" + path.Name() + "'. " + err.Error()) + } + header.Name = relativePath // write the header if err := tw.WriteHeader(header); err != nil { @@ -55,7 +57,7 @@ func Tar(path *os.File) (io.Reader, error) { // open files for taring f, err := os.Open(file) if err != nil { - return err + return errors.New("(common::tar::Tar::Walk) Error opening '" + file + "'. " + err.Error()) } if _, err := io.Copy(tw, f); err != nil { @@ -68,7 +70,7 @@ func Tar(path *os.File) (io.Reader, error) { return nil }) if err != nil { - return nil, errors.New("(common::tar::Tar) Error explorint '" + path.Name() + "'. " + err.Error()) + return nil, errors.New("(common::tar::Tar) Error exploring '" + path.Name() + "'. " + err.Error()) } return bytes.NewReader(tarBuff.Bytes()), nil