sigs.k8s.io/cluster-api-provider-aws@v1.5.5/Dockerfile (about)

     1  # syntax=docker/dockerfile:1.1-experimental
     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 the manager binary
    18  FROM golang:1.17.3 as toolchain
    19  
    20  # Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
    21  ARG goproxy=https://proxy.golang.org
    22  ENV GOPROXY=$goproxy
    23  
    24  FROM toolchain as builder
    25  WORKDIR /workspace
    26  
    27  # Copy the Go Modules manifests
    28  COPY go.mod go.mod
    29  COPY go.sum go.sum
    30  # Cache deps before building and copying source so that we don't need to re-download as much
    31  # and so that source changes don't invalidate our downloaded layer
    32  RUN  --mount=type=cache,target=/root/.local/share/golang \
    33       --mount=type=cache,target=/go/pkg/mod \
    34       go mod download
    35  
    36  # Copy the sources
    37  COPY ./ ./
    38  
    39  # Build
    40  ARG package=.
    41  ARG ARCH
    42  ARG LDFLAGS
    43  RUN --mount=type=cache,target=/root/.cache/go-build \
    44      --mount=type=cache,target=/go/pkg/mod \
    45      --mount=type=cache,target=/root/.local/share/golang \
    46      CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'"  -o manager ${package}
    47  ENTRYPOINT [ "/start.sh", "/workspace/manager" ]
    48  
    49  # Copy the controller-manager into a thin image
    50  FROM gcr.io/distroless/static:nonroot
    51  WORKDIR /
    52  COPY --from=builder /workspace/manager .
    53  # Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
    54  USER 65532
    55  ENTRYPOINT ["/manager"]