1// Copyright 2023 Google LLC 2// 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5package main 6 7import ( 8 "context" 9 "flag" 10 "fmt" 11 "path/filepath" 12 13 sk_exec "go.skia.org/infra/go/exec" 14 "go.skia.org/infra/task_driver/go/lib/os_steps" 15 "go.skia.org/infra/task_driver/go/td" 16 "go.skia.org/skia/infra/bots/task_drivers/common" 17) 18 19var ( 20 // Required properties for this task. 21 projectId = flag.String("project_id", "", "ID of the Google Cloud project.") 22 taskId = flag.String("task_id", "", "ID of this task.") 23 taskName = flag.String("task_name", "", "Name of the task.") 24 pathInSkia = flag.String("path_in_skia", "example/external_client", "The directory from which to run the Bazel commands in Docker") 25 workdir = flag.String("workdir", ".", "Working directory, the root directory of a full Skia checkout") 26 27 // Optional flags. 28 local = flag.Bool("local", false, "True if running locally (as opposed to on the CI/CQ)") 29 output = flag.String("o", "", "If provided, dump a JSON blob of step data to the given file. Prints to stdout if '-' is given.") 30) 31 32const ( 33 // Made from //skia/infra/gcc/Debian11/Dockerfile 34 dockerImage = "gcr.io/skia-public/gcc-debian11@sha256:1117ea368f43e45e0f543f74c8e3bf7ff6932df54ddaa4ba1fe6131209110d3d" 35 // pathToScript is the path inside the mounted docker container for the script 36 pathToScript = "/SRC/infra/bots/task_drivers/external_client/bazel_build_with_docker.sh" 37) 38 39func main() { 40 bazelFlags := common.MakeBazelFlags(common.MakeBazelFlagsOpts{ 41 Label: true, 42 }) 43 44 // StartRun calls flag.Parse() 45 ctx := td.StartRun(projectId, taskId, taskName, output, local) 46 defer td.EndRun(ctx) 47 48 bazelFlags.Validate(ctx) 49 50 wd, err := os_steps.Abs(ctx, *workdir) 51 if err != nil { 52 td.Fatal(ctx, err) 53 } 54 skiaDir := filepath.Join(wd, "skia") 55 56 if err := runDocker(ctx, skiaDir, *pathInSkia, *bazelFlags.Label); err != nil { 57 td.Fatal(ctx, err) 58 } 59} 60 61func runDocker(ctx context.Context, checkoutDir, subpath, target string) error { 62 step := fmt.Sprintf("Running Bazel from inside Docker to build %s", target) 63 return td.Do(ctx, td.Props(step), func(ctx context.Context) error { 64 runCmd := &sk_exec.Command{ 65 Name: "docker", 66 Args: []string{ 67 "run", 68 "--shm-size=4gb", // more RAM for Bazel and compilation/linking 69 fmt.Sprintf("--mount=type=bind,source=%s,target=/SRC", checkoutDir), 70 dockerImage, 71 pathToScript, 72 subpath, 73 target, 74 }, 75 LogStdout: true, 76 LogStderr: true, 77 } 78 _, err := sk_exec.RunCommand(ctx, runCmd) 79 if err != nil { 80 return err 81 } 82 return nil 83 }) 84} 85