Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get tmp Directory from os env in kaniko local context storing #1285

Merged
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
7 changes: 4 additions & 3 deletions pkg/skaffold/build/kaniko/sources/localdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type LocalDir struct {

// Setup for LocalDir creates a tarball of the buildcontext and stores it in /tmp
func (g *LocalDir) Setup(ctx context.Context, out io.Writer, artifact *latest.Artifact, initialTag string) (string, error) {
g.tarPath = filepath.Join("/tmp", fmt.Sprintf("context-%s.tar.gz", initialTag))
g.tarPath = filepath.Join(os.TempDir(), fmt.Sprintf("context-%s.tar.gz", initialTag))
color.Default.Fprintln(out, "Storing build context at", g.tarPath)

f, err := os.Create(g.tarPath)
Expand Down Expand Up @@ -105,12 +105,13 @@ func (g *LocalDir) ModifyPod(ctx context.Context, p *v1.Pod) error {
return errors.Wrap(err, "waiting for pod to initialize")
}
// Copy over the buildcontext tarball into the init container
copy := exec.CommandContext(ctx, "kubectl", "cp", g.tarPath, fmt.Sprintf("%s:/%s", p.Name, g.tarPath), "-c", initContainer, "-n", p.Namespace)
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the tarCopyPath variable, since copying to g.tarPath should accomplish the same thing, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@priyawadhwa It doesn't work in windows unfortunately. That is the reason I had to use tarCopyPath .

g.tarPath = os.TempDir() in windows ~ C:\Users<user-id>\AppData\Local\Temp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha, sounds good!

if err := util.RunCmd(copy); err != nil {
return errors.Wrap(err, "copying buildcontext into init container")
}
// Next, extract the buildcontext to the empty dir
extract := exec.CommandContext(ctx, "kubectl", "exec", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "tar", "-xzf", g.tarPath, "-C", constants.DefaultKanikoEmptyDirMountPath)
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")
}
Expand Down