sigs.k8s.io/cluster-api-provider-azure@v1.17.0/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.22 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 sources
    29  COPY ./ ./
    30  
    31  # Build
    32  ARG package=.
    33  ARG ARCH
    34  ARG ldflags
    35  
    36  # Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
    37  RUN --mount=type=cache,target=/root/.cache/go-build \
    38      --mount=type=cache,target=/go/pkg/mod \
    39      CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
    40      go build -ldflags "${ldflags} -extldflags '-static'" \
    41      -o manager ${package}
    42  
    43  # Production image
    44  FROM gcr.io/distroless/static:nonroot-${ARCH}
    45  WORKDIR /
    46  COPY --from=builder /workspace/manager .
    47  # Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
    48  USER 65532
    49  ENTRYPOINT ["/manager"]