| Giorgi Lekveishvili | 0048a78 | 2023-06-20 18:32:21 +0400 | [diff] [blame^] | 1 | # syntax=docker/dockerfile:1.3 |
| 2 | ARG GO_VERSION |
| 3 | FROM --platform=${TARGETPLATFORM} golang:${GO_VERSION}-alpine AS base |
| 4 | |
| 5 | WORKDIR /go/src/cert-manager-webhook-gandi |
| 6 | COPY go.* . |
| 7 | |
| 8 | RUN --mount=type=cache,target=/go/pkg/mod \ |
| 9 | apk add --no-cache git ca-certificates && \ |
| 10 | go mod download |
| 11 | |
| 12 | FROM base AS build |
| 13 | ARG TARGETOS |
| 14 | ARG TARGETARCH |
| 15 | |
| 16 | RUN --mount=readonly,target=. --mount=type=cache,target=/go/pkg/mod \ |
| 17 | GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -a -o /go/bin/webhook -ldflags '-w -extldflags "-static"' . |
| 18 | |
| 19 | FROM scratch AS image |
| 20 | COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
| 21 | COPY --from=build /go/bin/webhook /usr/local/bin/webhook |
| 22 | |
| 23 | ENTRYPOINT ["/usr/local/bin/webhook"] |