This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
93 lines (66 loc) · 2.69 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# BUILD_BASE_IMAGE is the base image to use for the build. It contains a rolling
# accumulation of Go build/package caches.
ARG BUILD_BASE_IMAGE=golang:1.17.9-buster
# 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
# configuration option.
ARG RUNTIME_IMAGE=busybox:1.31.1-glibc
#:::
#::: BUILD CONTAINER
#:::
FROM ${BUILD_BASE_IMAGE} AS builder
# PLAN_DIR is the location containing the plan source inside the container.
ENV PLAN_DIR /plan
# SDK_DIR is the location containing the (optional) sdk source inside the container.
ENV SDK_DIR /sdk
# 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.
ARG GO_PROXY="direct"
# BUILD_TAGS is either nothing, or when expanded, it expands to "-tags <comma-separated build tags>"
ARG 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.
ENV GOCACHE /go/cache
# Copy only go.mod files and download deps, in order to leverage Docker caching.
COPY /plan/go.mod ${PLAN_DIR}/go.mod
# Download deps.
RUN echo "Using go proxy: ${GO_PROXY}" \
&& cd ${PLAN_DIR} \
&& go env -w GOPROXY="${GO_PROXY}" \
&& go mod download
# Now copy the rest of the source and run the build.
COPY . /
RUN cd ${PLAN_DIR} \
&& go env -w GOPROXY="${GO_PROXY}" \
&& CGO_ENABLED=${CgoEnabled} GOOS=linux GOARCH=amd64 go build -o ${PLAN_DIR}/testplan.bin ${BUILD_TAGS} ${TESTPLAN_EXEC_PKG}
# Store module dependencies
RUN cd ${PLAN_DIR} \
&& go list -m all > /testground_dep_list
#:::
#::: (OPTIONAL) RUNTIME CONTAINER
#:::
## 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.
ENV PLAN_DIR /plan
COPY --from=builder /testground_dep_list /
COPY --from=builder ${PLAN_DIR}/testplan.bin /testplan
ARG RABBIT_URL="rabbitmq"
ARG INFLUXDB_URL="influxdb"
ENV INFLUXDB_URL="testground-influxdb:8086"
ENV ENV_TYPE=docker
ENV PORT=8081
ENV RABBIT_BROKER_URL=amqp://guest:guest@${RABBIT_URL}:5672/
ENV REDIS_URL=redis:6379
EXPOSE 6060
ENTRYPOINT [ "/testplan"]