|
1 | | -FROM --platform=${BUILDPLATFORM} golang:1.23 AS builder |
| 1 | +# We use the Go 1.23 version unless asked to use something else. |
| 2 | +# The GitHub Actions CI job sets this argument for a consistent Go version. |
| 3 | +ARG GO_VERSION=1.23 |
| 4 | +ARG BASE_IMAGE=kcllang/kcl |
2 | 5 |
|
3 | | -# The TARGETOS and TARGETARCH args are set by docker. We set GOOS and GOARCH to |
4 | | -# these values to ask Go to compile a binary for these architectures. If |
5 | | -# TARGETOS and TARGETOS are different from BUILDPLATFORM, Go will cross compile |
6 | | -# for us (e.g. compile a linux/amd64 binary on a linux/arm64 build machine). |
7 | | -ARG TARGETOS |
8 | | -ARG TARGETARCH |
| 6 | +# Setup the base environment. The BUILDPLATFORM is set automatically by Docker. |
| 7 | +# The --platform=${BUILDPLATFORM} flag tells Docker to build the function using |
| 8 | +# the OS and architecture of the host running the build, not the OS and |
| 9 | +# architecture that we're building the function for. |
| 10 | +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as build |
9 | 11 |
|
10 | | -ENV GO111MODULE=on \ |
11 | | - GOPROXY=https://goproxy.cn,direct |
| 12 | +COPY / /src |
| 13 | +WORKDIR /src |
12 | 14 |
|
13 | | -WORKDIR / |
14 | | - |
15 | | -COPY . . |
| 15 | +ENV CGO_ENABLED=0 |
16 | 16 |
|
17 | 17 | # We run go mod download in a separate step so that we can cache its results. |
18 | 18 | # This lets us avoid re-downloading modules if we don't need to. The type=target |
19 | 19 | # mount tells Docker to mount the current directory read-only in the WORKDIR. |
20 | 20 | # The type=cache mount tells Docker to cache the Go modules cache across builds. |
21 | 21 | RUN --mount=target=. --mount=type=cache,target=/go/pkg/mod go mod download |
22 | 22 |
|
23 | | -RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-init cmd/wehbook-init/main.go |
24 | | - |
25 | | -FROM kcllang/kcl |
| 23 | +# The TARGETOS and TARGETARCH args are set by docker. We set GOOS and GOARCH to |
| 24 | +# these values to ask Go to compile a binary for these architectures. If |
| 25 | +# TARGETOS and TARGETOS are different from BUILDPLATFORM, Go will cross compile |
| 26 | +# for us (e.g. compile a linux/amd64 binary on a linux/arm64 build machine). |
| 27 | +ARG TARGETOS |
| 28 | +ARG TARGETARCH |
26 | 29 |
|
27 | | -WORKDIR / |
28 | | -COPY --from=builder /webhook-server . |
| 30 | +# Build the webhook init binary. The type=target mount tells Docker to mount the |
| 31 | +# current directory read-only in the WORKDIR. The type=cache mount tells Docker |
| 32 | +# to cache the Go modules cache across builds. |
| 33 | +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-init cmd/wehbook-init/main.go |
29 | 34 |
|
| 35 | +FROM ${BASE_IMAGE} as image |
| 36 | +RUN apt-get update && apt-get install -y ca-certificates tini |
| 37 | +COPY --from=build /src/webhook-init /usr/local/bin/ |
30 | 38 | ENV KCL_FAST_EVAL=1 |
31 | 39 | ENV LANG="en_US.UTF-8" |
32 | 40 |
|
33 | | -ENTRYPOINT ["/webhook-init"] |
| 41 | +ENTRYPOINT ["/usr/local/bin/webhook-init"] |
0 commit comments