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{
|
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
|
||||||
|
|
||||||
|
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
|
||||||
|
// Add the dockerfile with a random filename
|
||||||
|
randomName: func(_ string, _ *tar.Header, _ io.Reader) (*tar.Header, []byte, error) {
|
||||||
|
header := &tar.Header{
|
||||||
|
Name: randomName,
|
||||||
Mode: 0600,
|
Mode: 0600,
|
||||||
Uid: 0,
|
|
||||||
Gid: 0,
|
|
||||||
ModTime: now,
|
ModTime: now,
|
||||||
Typeflag: tar.TypeReg,
|
Typeflag: tar.TypeReg,
|
||||||
AccessTime: now,
|
AccessTime: now,
|
||||||
ChangeTime: now,
|
ChangeTime: now,
|
||||||
}
|
}
|
||||||
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
|
return header, file, nil
|
||||||
|
|
||||||
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
|
|
||||||
// Add the dockerfile with a random filename
|
|
||||||
randomName: func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
|
|
||||||
return hdrTmpl, 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