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, } 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 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 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 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