mirror of https://github.com/docker/cli.git
Merge pull request #3243 from thaJeztah/fix_build_context
build: fix AddDockerfileToBuildContext not de-referencing tar header template
This commit is contained in:
commit
b4dde3a130
|
@ -378,26 +378,32 @@ func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
hdrTmpl := &tar.Header{
|
|
||||||
Mode: 0600,
|
|
||||||
Uid: 0,
|
|
||||||
Gid: 0,
|
|
||||||
ModTime: now,
|
|
||||||
Typeflag: tar.TypeReg,
|
|
||||||
AccessTime: now,
|
|
||||||
ChangeTime: now,
|
|
||||||
}
|
|
||||||
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
|
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
|
||||||
|
|
||||||
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
|
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
|
||||||
// Add the dockerfile with a random filename
|
// Add the dockerfile with a random filename
|
||||||
randomName: func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
|
randomName: func(_ string, _ *tar.Header, _ io.Reader) (*tar.Header, []byte, error) {
|
||||||
return hdrTmpl, file, nil
|
header := &tar.Header{
|
||||||
|
Name: randomName,
|
||||||
|
Mode: 0600,
|
||||||
|
ModTime: now,
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
AccessTime: now,
|
||||||
|
ChangeTime: now,
|
||||||
|
}
|
||||||
|
return header, file, nil
|
||||||
},
|
},
|
||||||
// Update .dockerignore to include the random filename
|
// Update .dockerignore to include the random filename
|
||||||
".dockerignore": func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
|
".dockerignore": func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
|
||||||
if h == nil {
|
if h == nil {
|
||||||
h = hdrTmpl
|
h = &tar.Header{
|
||||||
|
Name: ".dockerignore",
|
||||||
|
Mode: 0600,
|
||||||
|
ModTime: now,
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
AccessTime: now,
|
||||||
|
ChangeTime: now,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
|
|
Loading…
Reference in New Issue