...

Text file src/github.com/linkerd/linkerd2/cli/Dockerfile

Documentation: github.com/linkerd/linkerd2/cli

     1ARG BUILDPLATFORM=linux/amd64
     2
     3# Precompile key slow-to-build dependencies
     4FROM --platform=$BUILDPLATFORM golang:1.22-alpine as go-deps
     5WORKDIR /linkerd-build
     6COPY go.mod go.sum ./
     7COPY bin/install-deps bin/
     8RUN go mod download
     9RUN ./bin/install-deps
    10
    11## compile binaries
    12FROM go-deps as go-gen
    13WORKDIR /linkerd-build
    14COPY cli cli
    15COPY charts charts
    16COPY jaeger jaeger
    17COPY multicluster multicluster
    18COPY viz viz
    19
    20COPY controller/k8s controller/k8s
    21COPY controller/api controller/api
    22COPY controller/gen controller/gen
    23COPY pkg pkg
    24
    25# Generate static templates
    26# TODO: `go generate` does not honor -mod=readonly
    27RUN go generate -mod=readonly ./pkg/charts/static
    28RUN go generate -mod=readonly ./jaeger/static
    29RUN go generate -mod=readonly ./multicluster/static
    30RUN go generate -mod=readonly ./viz/static
    31
    32RUN mkdir -p /out
    33
    34FROM go-gen as linux-amd64-full
    35RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    36ARG LINKERD_VERSION
    37ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    38RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    39
    40FROM go-gen as linux-arm64-full
    41RUN ./bin/install-deps arm64
    42RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    43ARG LINKERD_VERSION
    44ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    45RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    46
    47FROM go-gen as linux-arm-full
    48RUN ./bin/install-deps arm
    49RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    50ARG LINKERD_VERSION
    51ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    52RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    53
    54FROM go-gen as darwin-full
    55RUN CGO_ENABLED=0 GOOS=darwin go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    56ARG LINKERD_VERSION
    57ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    58RUN CGO_ENABLED=0 GOOS=darwin go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    59
    60FROM go-gen as darwin-arm64-full
    61RUN CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    62ARG LINKERD_VERSION
    63ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    64RUN CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    65
    66FROM go-gen as windows-full
    67RUN CGO_ENABLED=0 GOOS=windows go build -o /out/linkerd -tags prod -mod=readonly -ldflags "-s -w" ./cli
    68ARG LINKERD_VERSION
    69ENV GO_LDFLAGS="-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=${LINKERD_VERSION}"
    70RUN CGO_ENABLED=0 GOOS=windows go build -o /out/linkerd -tags prod -mod=readonly -ldflags "${GO_LDFLAGS}" ./cli
    71
    72#
    73# bin/docker-build* will use any of the following targets depending on the
    74# value of DOCKER_TARGET, which if it's not set, will be set automatically
    75# depending on the host's OS and arch.
    76#
    77
    78FROM scratch as linux-amd64
    79COPY LICENSE /linkerd/LICENSE
    80COPY --from=linux-amd64-full /out/linkerd /out/linkerd-linux-amd64
    81# `ENTRYPOINT` prevents `docker build` from otherwise failing with "Error
    82# response from daemon: No command specified."
    83ENTRYPOINT ["/out/linkerd-linux-amd64"]
    84
    85FROM scratch as linux-arm64
    86COPY LICENSE /linkerd/LICENSE
    87COPY --from=linux-arm64-full /out/linkerd /out/linkerd-linux-arm64
    88ENTRYPOINT ["/out/linkerd-linux-arm64"]
    89
    90FROM scratch as linux-arm
    91COPY LICENSE /linkerd/LICENSE
    92COPY --from=linux-arm64-full /out/linkerd /out/linkerd-linux-arm
    93ENTRYPOINT ["/out/linkerd-linux-arm"]
    94
    95FROM scratch as darwin
    96COPY LICENSE /linkerd/LICENSE
    97COPY --from=darwin-full /out/linkerd /out/linkerd-darwin
    98ENTRYPOINT ["/out/linkerd-darwin"]
    99
   100FROM scratch as darwin-arm64
   101COPY LICENSE /linkerd/LICENSE
   102COPY --from=darwin-arm64-full /out/linkerd /out/linkerd-darwin-arm64
   103ENTRYPOINT ["/out/linkerd-darwin-arm64"]
   104
   105FROM scratch as windows
   106COPY LICENSE /linkerd/LICENSE
   107COPY --from=windows-full /out/linkerd /out/linkerd-windows
   108ENTRYPOINT ["/out/linkerd-windows"]
   109
   110FROM scratch as multi-arch
   111COPY LICENSE /linkerd/LICENSE
   112COPY --from=linux-amd64-full /out/linkerd /out/linkerd-linux-amd64
   113COPY --from=linux-arm64-full /out/linkerd /out/linkerd-linux-arm64
   114COPY --from=linux-arm-full /out/linkerd /out/linkerd-linux-arm
   115COPY --from=darwin-full /out/linkerd /out/linkerd-darwin
   116COPY --from=darwin-arm64-full /out/linkerd /out/linkerd-darwin-arm64
   117COPY --from=windows-full /out/linkerd /out/linkerd-windows
   118ENTRYPOINT ["/out/linkerd-linux-amd64"]

View as plain text