Skip to content

Commit

Permalink
[ci_runner] Modify Linux workflows to download the binary from the ca…
Browse files Browse the repository at this point in the history
…che, rather than using the binary provisioned on the executors (buildbuddy-io#6795)
  • Loading branch information
maggie-lou committed Jun 14, 2024
1 parent fb2cab7 commit c73ac89
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
2 changes: 2 additions & 0 deletions enterprise/server/remote_execution/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func (r *taskRunner) DownloadInputs(ctx context.Context, ioStats *repb.IOStats)
if err != nil {
return err
}
// TODO(Maggie): Do not do this on Linux after we start uploading/downloading
// the binary from the cache
if r.PlatformProperties.WorkflowID != "" {
if err := r.Workspace.AddCIRunner(ctx); err != nil {
return err
Expand Down
15 changes: 8 additions & 7 deletions enterprise/server/test/integration/workflow/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ func setup(t *testing.T, gp interfaces.GitProvider) (*rbetest.Env, interfaces.Wo
var workflowService interfaces.WorkflowService

bbServer := env.AddBuildBuddyServerWithOptions(&rbetest.BuildBuddyServerOptions{
EnvModifier: func(env *testenv.TestEnv) {
env.SetRepoDownloader(repo_downloader.NewRepoDownloader())
env.SetGitProviders([]interfaces.GitProvider{gp})
workflowService = service.NewWorkflowService(env)
env.SetWorkflowService(workflowService)
iss := invocation_search_service.NewInvocationSearchService(env, env.GetDBHandle(), env.GetOLAPDBHandle())
env.SetInvocationSearchService(iss)
EnvModifier: func(e *testenv.TestEnv) {
e.SetRepoDownloader(repo_downloader.NewRepoDownloader())
e.SetGitProviders([]interfaces.GitProvider{gp})
workflowService = service.NewWorkflowService(e)
e.SetWorkflowService(workflowService)
iss := invocation_search_service.NewInvocationSearchService(e, e.GetDBHandle(), e.GetOLAPDBHandle())
e.SetInvocationSearchService(iss)
e.SetByteStreamClient(env.GetByteStreamClient())
},
})

Expand Down
1 change: 1 addition & 0 deletions enterprise/server/workflow/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
srcs = ["service.go"],
importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/workflow/service",
deps = [
"//enterprise/server/cmd/ci_runner/bundle",
"//enterprise/server/remote_execution/operation",
"//enterprise/server/remote_execution/platform",
"//enterprise/server/webhooks/webhook_data",
Expand Down
43 changes: 32 additions & 11 deletions enterprise/server/workflow/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
"gopkg.in/yaml.v2"

ci_runner_bundle "github.com/buildbuddy-io/buildbuddy/enterprise/server/cmd/ci_runner/bundle"
ctxpb "github.com/buildbuddy-io/buildbuddy/proto/context"
inspb "github.com/buildbuddy-io/buildbuddy/proto/invocation_status"
repb "github.com/buildbuddy-io/buildbuddy/proto/remote_execution"
Expand Down Expand Up @@ -1071,10 +1072,7 @@ func (ws *workflowService) createActionForWorkflow(ctx context.Context, wf *tabl
if cache == nil {
return nil, status.UnavailableError("No cache configured.")
}
inputRootDigest, err := digest.ComputeForMessage(&repb.Directory{}, repb.DigestFunction_SHA256)
if err != nil {
return nil, err
}

envVars := []*repb.Command_EnvironmentVariable{
{Name: "CI", Value: "true"},
{Name: "GIT_COMMIT", Value: wd.SHA},
Expand Down Expand Up @@ -1162,14 +1160,37 @@ func (ws *workflowService) createActionForWorkflow(ctx context.Context, wf *tabl
}
}

// NOTE: By default, the executor is responsible for ensuring the
// buildbuddy_ci_runner binary exists at the workspace root when it sees
// the `workflow-id` platform property.
inputRootDigest, err := digest.ComputeForMessage(&repb.Directory{}, repb.DigestFunction_SHA256)
if err != nil {
return nil, err
}
if (os == "" || os == platform.LinuxOperatingSystemName) && (workflowAction.Arch == "" || workflowAction.Arch == "amd64") {
// Because the apps are built for linux/amd64, in these cases we can have the apps
// upload the ci_runner binary to the cache to ensure the executors are using
// the most up-to-date version of the binary
runnerBinDigest, err := cachetools.UploadBlobToCAS(ctx, ws.env.GetByteStreamClient(), instanceName, repb.DigestFunction_SHA256, ci_runner_bundle.CiRunnerBytes)
if err != nil {
return nil, status.WrapError(err, "upload runner bin")
}
runnerName := filepath.Base(ci_runner_bundle.RunnerName)
dir := &repb.Directory{
Files: []*repb.FileNode{{
Name: runnerName,
Digest: runnerBinDigest,
IsExecutable: true,
}},
}
inputRootDigest, err = cachetools.UploadProtoToCAS(ctx, cache, instanceName, repb.DigestFunction_SHA256, dir)
if err != nil {
return nil, status.WrapError(err, "upload input root")
}
}

args := []string{
// NOTE: The executor is responsible for making sure this
// buildbuddy_ci_runner binary exists at the workspace root. It does so
// whenever it sees the `workflow-id` platform property.
//
// Also be cautious when adding new flags. See
// https://github.com/buildbuddy-io/buildbuddy-internal/issues/3101
"./buildbuddy_ci_runner",
"./" + ci_runner_bundle.RunnerName,
"--invocation_id=" + invocationID,
"--action_name=" + workflowAction.Name,
"--bes_backend=" + events_api_url.String(),
Expand Down

0 comments on commit c73ac89

Please sign in to comment.