Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/build-path-context/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}, "/")
Expand All @@ -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,
}
Expand Down
4 changes: 1 addition & 3 deletions examples/build-path-context/files/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
FROM ubuntu

RUN apt-get update \
&& apt-get upgrade -y

COPY etc/config/file.cfg /tmp
Empty file.
2 changes: 1 addition & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
// DefaultDockerfile is the default filename for Dockerfile
DefaultDockerfile = "Dockerfile"
DefaultDockerfile string = "Dockerfile"
)

// DockerBuilderCmd
Expand Down
12 changes: 7 additions & 5 deletions pkg/common/tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down