-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainerfile.alt
53 lines (36 loc) · 1.51 KB
/
Containerfile.alt
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
# TODO: This file is only needed for the time being because the version of buildah used
# in github actions is so old.
# https://github.com/redhat-actions/buildah-build/issues/116#issuecomment-1890340223
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 CGO_ENABLED=0 GOBIN=/builddir go install github.com/grpc-ecosystem/grpc-health-probe@645566f
# Copy across
COPY go.mod go.sum ./
# Install go application dependencies
RUN go mod download -x
# TODO: https://github.com/redhat-actions/buildah-build/issues/116#issuecomment-1890340223
# RUN --mount=type=cache,target=/go/pkg/mod/ \
# go mod download -x
FROM builder-base AS builder
ARG entrypoint
ARG gobuildopts=
ADD . .
RUN CGO_ENABLED=0 go build ${gobuildopts} -v -o /builddir/service ./$entrypoint
# TODO: https://github.com/redhat-actions/buildah-build/issues/116#issuecomment-1890340223
# 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"]