sigs.k8s.io/cluster-api-provider-azure@v1.14.3/Dockerfile (about) 1 # syntax=docker/dockerfile:1 2 3 # Copyright 2019 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Build architecture 18 ARG ARCH 19 20 # Build the manager binary 21 FROM golang:1.20 as builder 22 WORKDIR /workspace 23 24 # Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy 25 ARG goproxy=https://proxy.golang.org 26 ENV GOPROXY=$goproxy 27 28 # Copy the Go Modules manifests 29 COPY go.mod go.mod 30 COPY go.sum go.sum 31 32 # Cache deps before building and copying source so that we don't need to re-download as much 33 # and so that source changes don't invalidate our downloaded layer 34 RUN --mount=type=cache,target=/go/pkg/mod \ 35 go mod download 36 37 # Copy the sources 38 COPY ./ ./ 39 40 # Cache the go build into the the Go’s compiler cache folder so we take benefits of compiler caching across docker build calls 41 RUN --mount=type=cache,target=/root/.cache/go-build \ 42 --mount=type=cache,target=/go/pkg/mod \ 43 go build . 44 45 # Build 46 ARG package=. 47 ARG ARCH 48 ARG ldflags 49 50 # Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder 51 RUN --mount=type=cache,target=/root/.cache/go-build \ 52 --mount=type=cache,target=/go/pkg/mod \ 53 CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ 54 go build -ldflags "${ldflags} -extldflags '-static'" \ 55 -o manager ${package} 56 57 # Production image 58 FROM gcr.io/distroless/static:nonroot-${ARCH} 59 WORKDIR / 60 COPY --from=builder /workspace/manager . 61 # Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies 62 USER 65532 63 ENTRYPOINT ["/manager"]