# This Dockerfile performs a multi-stage build and RUNTIME_IMAGE is the image
# onto which to copy the resulting binary.
# Picking a different runtime base image from the build image allows us to
# slim down the deployable considerably.
# The user can override the runtime image by passing in the appropriate builder
ARG RUNTIME_IMAGE=busybox:1.31.1-glibc
FROM ${BUILD_BASE_IMAGE} AS builder
# PLAN_DIR is the location containing the plan source inside the container.
# SDK_DIR is the location containing the (optional) sdk source inside the container.
# Delete any prior artifacts, if this is a cached image.
RUN rm -rf ${PLAN_DIR} ${SDK_DIR} /testground_dep_list
# TESTPLAN_EXEC_PKG is the executable package of the testplan to build.
# The image will build that package only.
ARG TESTPLAN_EXEC_PKG="."
# GO_PROXY is the go proxy that will be used, or direct by default.
# BUILD_TAGS is either nothing, or when expanded, it expands to "-tags <comma-separated build tags>"
# TESTPLAN_EXEC_PKG is the executable package within this test plan we want to build.
ENV TESTPLAN_EXEC_PKG ${TESTPLAN_EXEC_PKG}
# We explicitly set GOCACHE under the /go directory for more tidiness.
{{.DockerfileExtensions.PreModDownload}}
# Copy only go.mod files and download deps, in order to leverage Docker caching.
COPY /plan/go.mod ${PLAN_DIR}/go.mod
COPY /sdk/go.mod /sdk/go.mod
RUN echo "Using go proxy: ${GO_PROXY}" \
&& go env -w GOPROXY="${GO_PROXY}" \
{{.DockerfileExtensions.PostModDownload}}
{{.DockerfileExtensions.PreSourceCopy}}
# Now copy the rest of the source and run the build.
{{.DockerfileExtensions.PostSourceCopy}}
{{.DockerfileExtensions.PreBuild}}
&& go env -w GOPROXY="${GO_PROXY}" \
&& GOOS=linux GOARCH=amd64 go build -o ${PLAN_DIR}/testplan.bin ${BUILD_TAGS} ${TESTPLAN_EXEC_PKG}
{{.DockerfileExtensions.PostBuild}}
# Store module dependencies
&& go list -m all > /testground_dep_list
#::: (OPTIONAL) RUNTIME CONTAINER
{{ if not .SkipRuntimeImage }}
## The 'AS runtime' token is used to parse Docker stdout to extract the build image ID to cache.
FROM ${RUNTIME_IMAGE} AS runtime
# PLAN_DIR is the location containing the plan source inside the build container.
{{.DockerfileExtensions.PreRuntimeCopy}}
COPY --from=builder /testground_dep_list /
COPY --from=builder ${PLAN_DIR}/testplan.bin /testplan
{{.DockerfileExtensions.PostRuntimeCopy}}
## The 'AS runtime' token is used to parse Docker stdout to extract the build image ID to cache.
# PLAN_DIR is the location containing the plan source inside the build container.
RUN mv ${PLAN_DIR}/testplan.bin /testplan
ENTRYPOINT [ "/testplan"]