Fixed localDir build context copy on Windows
@@ -104,23 +104,25 @@ func (g *LocalDir) ModifyPod(ctx context.Context, p *v1.Pod) error {
if err := kubernetes.WaitForPodInitialized(ctx, client.CoreV1().Pods(p.Namespace), p.Name); err != nil {
return errors.Wrap(err, "waiting for pod to initialize")
}
- // Copy over the buildcontext tarball into the init container
- tarCopyPath := fmt.Sprintf("/tmp/%s", filepath.Base(g.tarPath))
- copy := exec.CommandContext(ctx, "kubectl", "cp", g.tarPath, fmt.Sprintf("%s:%s", p.Name, tarCopyPath), "-c", initContainer, "-n", p.Namespace)
- if err := util.RunCmd(copy); err != nil {
- return errors.Wrap(err, "copying buildcontext into init container")
+
+ f, err := os.Open(g.tarPath)
+ if err != nil {
+ return errors.Wrap(err, "opening context tar")
}
- // Next, extract the buildcontext to the empty dir
- extract := exec.CommandContext(ctx, "kubectl", "exec", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "tar", "-xzf", tarCopyPath, "-C", constants.DefaultKanikoEmptyDirMountPath)
- if err := util.RunCmd(extract); err != nil {
- return errors.Wrap(err, "extracting buildcontext to empty dir")
+ defer f.Close()
+
+ // Copy the context to the empty dir and extract it
+ copyAndExtract := exec.CommandContext(ctx, "kubectl", "exec", "-i", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "tar", "-xzf", "-", "-C", constants.DefaultKanikoEmptyDirMountPath)
+ copyAndExtract.Stdin = f
+ if err := util.RunCmd(copyAndExtract); err != nil {
+ return errors.Wrap(err, "copying and extracting buildcontext to empty dir")
}
// Generate a file to successfully terminate the init container
file := exec.CommandContext(ctx, "kubectl", "exec", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "touch", "/tmp/complete")
return util.RunCmd(file)
}
-// Cleanup deletes the buidcontext tarball stored on the local filesystem
+// Cleanup deletes the buildcontext tarball stored on the local filesystem
func (g *LocalDir) Cleanup(ctx context.Context) error {
return os.Remove(g.tarPath)
}
