/
Containerfile
52 lines (36 loc) · 1.52 KB
/
Containerfile
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
FROM golang:1.21-alpine AS builder-base
WORKDIR /workdir
RUN mkdir /builddir
# Certificates
RUN apk --update upgrade
RUN apk add ca-certificates
RUN update-ca-certificates
# Build and include grpc-health-probe
RUN env GOBIN=/builddir go install github.com/grpc-ecosystem/grpc-health-probe@latest
# Copy across
COPY go.work go.work.sum ./
COPY modules/frontdoor/go.mod modules/frontdoor/go.sum ./modules/frontdoor/
COPY modules/mocks/go.mod modules/mocks/go.sum ./modules/mocks/
COPY modules/service-cli/go.mod modules/service-cli/go.sum ./modules/service-cli/
COPY modules/service-pkg/go.mod modules/service-pkg/go.sum ./modules/service-pkg/
COPY modules/testing-tools/go.mod modules/testing-tools/go.sum ./modules/testing-tools/
COPY modules/worker/go.mod modules/worker/go.sum ./modules/worker/
COPY test-harness/go.mod test-harness/go.sum ./test-harness/
# Install go application dependencies
RUN --mount=type=cache,target=/go/pkg/mod/ \
go mod download -x
FROM builder-base AS builder
ARG entrypoint
ARG gobuildopts=
ADD . .
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build ${gobuildopts} -v -o /builddir/service ./$entrypoint
FROM gcr.io/distroless/static AS runtime-base
USER nonroot
COPY --from=builder-base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder-base /builddir/grpc-health-probe /bin
FROM runtime-base AS runtime
USER nonroot
COPY --from=builder /builddir/service /bin
ENTRYPOINT ["/bin/service"]