Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridai Govinda Pombo committed Jul 16, 2020
1 parent a6ceec3 commit b87e634
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
26 changes: 18 additions & 8 deletions runtime/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,34 @@ 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 {
log.Infof("Failed to download and inject file: %v", err)
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,
}

Expand Down
1 change: 1 addition & 0 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Process struct {
Interactive bool
Directory string
Environment []string
AsRoot bool
Output io.Writer
}

Expand Down
16 changes: 6 additions & 10 deletions workspace/build_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}()
}
Expand All @@ -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()
Expand Down

0 comments on commit b87e634

Please sign in to comment.