This Cloud Build builder runs the
When to use this builder
gcr.io/cloud-builders/go build step should be used when you want to run
go tool directly on your source, similar to how a developer uses the
tool locally to build (
go build or
go install), test (
go test), or manage
go get or
There are two supported versions of this builder, one for
alpine and one for
debian. The difference is significant since, by default, Go dynamically links
libc. Binaries built in an
alpine environment don't always work in a
ubuntu, etc) environment, or vice versa.
The specific versions are available as
gcr.io/cloud-builders/go:latest is an alias for
go tool is used, the build step first sets up a workspace.
To determine the workspace structure, this tool checks the following, in order:
$GOPATHset? Use that.
- Is there a
$PROJECT_ROOTset? Make a temporary workspace in
GOPATH=./gopath, and link the contents of the current directory into
- Does a
.gofile in the current directory have a comment like
// import "$PROJECT_ROOT"? Use the
$PROJECT_ROOTfound in the import comment instead of a provided
Once the workspace is set up, the
args to the build step are passed through to
This tool builder sets
CGO_ENABLED=0, so that all binaries are linked statically.
The binaries built by a
go install step will be available to subsequent build
If you use the
install subcommand, the binaries will end up in
- If you set
$GOPATH, the binaries will end up in
- If you rely on
./srcto indicate the workspace, the binaries will end up in
- If you use
//importcomment, the binaries will end up in
Hello, World! is a basic example that builds a
binary that is injected into a container image. It uses the
$PROJECT_ROOTmethod to define its workspace.
Whole workspace is the same as the "Hello,
World!" example, except that it uses the
./srcmethod to define its workspace.
Building this builder
To build this builder, run the following command in this directory.
$ gcloud builds submit . --config=cloudbuild.yaml