From b87e634839d8d12f3d7b8791675faccda3c53291 Mon Sep 17 00:00:00 2001 From: Ridai Govinda Pombo Date: Thu, 16 Jul 2020 17:32:12 -0300 Subject: [PATCH] WIP --- runtime/containers.go | 26 ++++++++++++++++++-------- runtime/runtime.go | 1 + workspace/build_target.go | 16 ++++++---------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/runtime/containers.go b/runtime/containers.go index b3bc0487..fd32524c 100644 --- a/runtime/containers.go +++ b/runtime/containers.go @@ -163,16 +163,26 @@ func (t *ContainerTarget) DownloadFile(ctx context.Context, url string) (string, // TODO: upload if locally found localFile, err := downloadFileWithCache(ctx, url) + if err != nil { + return "", err + } + if !strings.Contains(url, "/") { + return "", fmt.Errorf("downloading URL %s: bad URL?", url) + } + + const injectPath = "/var/tmp/yb-inject/" + err = t.MkdirAsNeeded(ctx, injectPath) + if err != nil { + return "", err + } + parts := strings.Split(url, "/") filename := parts[len(parts)-1] - outputFilename := fmt.Sprintf("/tmp/%s", filename) + outputFilename := injectPath + filename - if err == nil { - // Downloaded locally, inject - log.Infof("Injecting locally cached file %s as %s", localFile, outputFilename) - // NOTE something in Narwhall is setting the wrong permissions in /tmp, it should be 1777 - err = narwhal.UploadFile(ctx, narwhal.DockerClient(), t.Container.Id, outputFilename, localFile) - } + // Downloaded locally, inject + log.Infof("Injecting locally cached file %s as %s", localFile, outputFilename) + err = narwhal.UploadFile(ctx, narwhal.DockerClient(), t.Container.Id, outputFilename, localFile) // If download or injection failed, fallback if err != nil { @@ -180,7 +190,7 @@ func (t *ContainerTarget) DownloadFile(ctx context.Context, url string) (string, log.Infof("Will download via curl in container") p := Process{ Command: fmt.Sprintf("curl %s -o %s", url, outputFilename), - Directory: "/tmp", + Directory: injectPath, Interactive: false, } diff --git a/runtime/runtime.go b/runtime/runtime.go index edd0281a..34dea8f4 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -64,6 +64,7 @@ type Process struct { Interactive bool Directory string Environment []string + AsRoot bool Output io.Writer } diff --git a/workspace/build_target.go b/workspace/build_target.go index aae59eb6..103d34ce 100644 --- a/workspace/build_target.go +++ b/workspace/build_target.go @@ -156,7 +156,10 @@ func (bt BuildTarget) Build(ctx context.Context, runtimeCtx *runtime.Runtime, ou "insteadOf = https://bitbucket.org/", } gitConfig := strings.Join(configlines, "\n") - builder.WriteFileContents(ctx, gitConfig, "/root/.gitconfig") + err = builder.WriteFileContents(ctx, gitConfig, "/root/.gitconfig") + if err != nil { + return stepTimes, err + } // TODO: Don't run this multiple times // Map SSH agent into the container @@ -171,20 +174,17 @@ func (bt BuildTarget) Build(ctx context.Context, runtimeCtx *runtime.Runtime, ou builder.SetEnv("SSH_AUTH_SOCK", "/ssh_agent") forwardPath, err := builder.DownloadFile(ctx, "https://yourbase-artifacts.s3-us-west-2.amazonaws.com/sockforward") - // Manual fix for the time being, still searching why this is happening, suspicious of how narwhal.archiveFile processes tar headers :think: - err = builder.Run(ctx, runtime.Process{Output: output, Command: "chmod 1777 /tmp"}) if err != nil { return stepTimes, err } - err = builder.Run(ctx, runtime.Process{Output: output, Command: fmt.Sprintf("chmod ugo+x %s", forwardPath)}) + err = builder.Run(ctx, runtime.Process{Output: output, Command: fmt.Sprintf("chmod a+x %s", forwardPath)}) if err != nil { return stepTimes, err } forwardCmd := fmt.Sprintf("%s /ssh_agent %s", forwardPath, hostAddr) go func() { if err := builder.Run(ctx, runtime.Process{Output: output, Command: forwardCmd}); err != nil { - log.Errorf("starting ssh_agent: %v", err) - return + log.Errorf("Starting ssh_agent: %v", err) } }() } @@ -201,10 +201,6 @@ func (bt BuildTarget) Build(ctx context.Context, runtimeCtx *runtime.Runtime, ou } stepTimes = append(stepTimes, tweakTimer) - if err != nil { - return stepTimes, err - } - } depContainerStartTime := time.Now()