Skip to content

Commit

Permalink
Workflows: Make container image configurable (#3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany authored Jan 18, 2023
1 parent a28fe0d commit 36bcf87
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions enterprise/server/cmd/ci_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -694,6 +695,9 @@ func (ar *actionRunner) Run(ctx context.Context, ws *workspace) error {
CommitSha: *commitSHA,
TargetRepoUrl: *targetRepoURL,
TargetBranch: *targetBranch,
Os: runtime.GOOS,
Arch: runtime.GOARCH,
ContainerImage: ar.action.ContainerImage,
}
wfcEvent := &bespb.BuildEvent{
Id: &bespb.BuildEventId{Id: &bespb.BuildEventId_WorkflowConfigured{WorkflowConfigured: &bespb.BuildEventId_WorkflowConfiguredId{}}},
Expand Down
1 change: 1 addition & 0 deletions enterprise/server/workflow/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Action struct {
Triggers *Triggers `yaml:"triggers"`
OS string `yaml:"os"`
Arch string `yaml:"arch"`
ContainerImage string `yaml:"container_image"`
ResourceRequests ResourceRequests `yaml:"resource_requests"`
User string `yaml:"user"`
GitCleanExclude []string `yaml:"git_clean_exclude"`
Expand Down
27 changes: 21 additions & 6 deletions enterprise/server/workflow/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import (
var (
enableFirecracker = flag.Bool("remote_execution.workflows_enable_firecracker", false, "Whether to enable firecracker for Linux workflow actions.")
workflowsPoolName = flag.String("remote_execution.workflows_pool_name", "", "The executor pool to use for workflow actions. Defaults to the default executor pool if not specified.")
workflowsDefaultImage = flag.String("remote_execution.workflows_default_image", "", "The default docker image to use for running workflows.")
workflowsDefaultImage = flag.String("remote_execution.workflows_default_image", platform.DockerPrefix+platform.Ubuntu18_04WorkflowsImage, "The default container-image property to use for workflows. Must include docker:// prefix if applicable.")
workflowsCIRunnerDebug = flag.Bool("remote_execution.workflows_ci_runner_debug", false, "Whether to run the CI runner in debug mode.")
workflowsCIRunnerBazelCommand = flag.String("remote_execution.workflows_ci_runner_bazel_command", "", "Bazel command to be used by the CI runner.")
workflowsLinuxComputeUnits = flag.Int("remote_execution.workflows_linux_compute_units", 3, "Number of BuildBuddy compute units (BCU) to reserve for Linux workflow actions.")
Expand Down Expand Up @@ -650,7 +650,7 @@ func (ws *workflowService) createActionForWorkflow(ctx context.Context, wf *tabl
// Use the CI runner image if the OS supports containerized actions.
if os == "" || os == platform.LinuxOperatingSystemName {
computeUnits = *workflowsLinuxComputeUnits
containerImage = ws.workflowsImage()
containerImage = ws.containerImage(workflowAction)
if *enableFirecracker {
isolationType = string(platform.FirecrackerContainerType)
// When using Firecracker, write all outputs to the scratch disk, which
Expand Down Expand Up @@ -744,11 +744,26 @@ func (ws *workflowService) WorkflowsPoolName() string {
return platform.DefaultPoolValue
}

func (ws *workflowService) workflowsImage() string {
if remote_execution_config.RemoteExecutionEnabled() && *workflowsDefaultImage != "" {
return *workflowsDefaultImage
func (ws *workflowService) containerImage(action *config.Action) string {
if action.ContainerImage != "" {
return ws.resolveImageAliases(action.ContainerImage)
}
return platform.DockerPrefix + platform.Ubuntu18_04WorkflowsImage
return *workflowsDefaultImage
}

func (ws *workflowService) resolveImageAliases(value string) string {
// Let people write "container_image: ubuntu-<VERSION>" as a shorthand for
// "latest ubuntu <VERSION> image".
if value == "ubuntu-18.04" {
return platform.DockerPrefix + platform.Ubuntu18_04WorkflowsImage
}
if value == "ubuntu-20.04" {
return platform.DockerPrefix + platform.Ubuntu20_04WorkflowsImage
}

// Otherwise, interpret container_image the same way we treat it for RBE
// actions.
return value
}

func (ws *workflowService) ciRunnerDebugMode() bool {
Expand Down
11 changes: 11 additions & 0 deletions proto/build_event_stream.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,17 @@ message WorkflowConfigured {
// The branch into which the pushed branch is being merged (for PRs),
// or the pushed_branch (for push events).
string target_branch = 10;

// The OS on which the workflow is running.
// Adheres to the same naming convention as GOOS in golang.
string os = 11;

// The CPU architecture on which the workflow is running.
// Adheres to the same naming convention as GOARCH in golang.
string arch = 12;

// Container image spec for the workflow, if applicable.
string container_image = 13;
}

// Event describing a workflow command that completed.
Expand Down

0 comments on commit 36bcf87

Please sign in to comment.