Docker images for Go on Google App Engine
This repository contains sources for the Go App Engine Flex build pipeline. This build pipeline utilizes Google Cloud Build to produce the application image. The
go-1.x.yamlconfiguration files are used in the build pipeline. User can now specify a Go version in app.yaml via
runtime: go1.x, where
1.xcan be 1.8, 1.9, etc. The resulting application image uses gcr.io/distroless/base as the base image, which contains a minimal Linux, glibc-based system.
The builder image
gcr.io/gcp-runtimes/go1-builderis tagged with supported Go major versions for builds to be able to target specific Go version to build against. Run the following gcloud command to list supported versions --
$ gcloud container images list-tags gcr.io/gcp-runtimes/go1-builder
Use only the Go major version tags e.g. 1.8, 1.9, instead of the unique version-datetime tags.
There are different ways to reuse the
go1-builderimage outside of AppEngine Flex. Here are a couple of examples.
Read up on how to use Docker's multi-stage builds.
Following is a trivial example of a Dockerfile with multi-stage build using the
go1-builderimage to bring in the Go SDK. The Go SDK is located under /usr/local/go of the builder image.
FROM gcr.io/gcp-runtimes/go1-builder:1.9 as builderWORKDIR /go/src/app COPY main.go .
RUN /usr/local/go/bin/go build -o app .
Application image.
FROM gcr.io/distroless/base:latest
COPY --from=builder /go/src/app/app /usr/local/bin/app
CMD ["/usr/local/bin/app"]
Read up on Google Cloud Build.
You can use one of the
go-1.x.yamlfiles for configuration file. The builder image's
ENTRYPOINTis the
go-build.shscript, which expects a certain layout of the uploaded directory. In particular, it expects --
_gopath/srcdirectory containing Go source files within package directory structure.
_gopath/main-package-pathfile containing the import path of the main application to be built.
/appdirectory.
The build script will build the application as referenced in
_gopath/main-package-pathfile and produce an application Dockerfile which the next step will run a docker build on.
You can customize your own cloudbuild.yaml file with your own Dockerfile.