зеркало из https://github.com/Azure/aks-engine.git
chore: Add Dockerfile for convenient building (#4431)
This enables cases like `docker build --output=bin/ https://github.com/Azure/aks-engine.git` without having to manually check out code and everything. It supports cross compilation so a user can set `--platform=darwin/amd64` or `--platform=local`, etc. to get a binary for whatever they need.
This commit is contained in:
Родитель
894885b6b2
Коммит
de057488f9
|
@ -0,0 +1,33 @@
|
|||
# syntax=docker/dockerfile:1.2
|
||||
|
||||
ARG GO_VERSION=1.16
|
||||
ARG GO_IMAGE=golang:${GO_VERSION}
|
||||
|
||||
|
||||
FROM --platform=$BUILDPLATFORM ${GO_IMAGE} AS build
|
||||
COPY . /go/src/github.com/azure/aks-engine
|
||||
WORKDIR /go/src/github.com/azure/aks-engine
|
||||
ARG TARGETARCH
|
||||
ARG TARGETOS
|
||||
ARG TARGETVARIANT
|
||||
SHELL ["/bin/bash", "-exc"]
|
||||
ENV GOCACHE=/go/.buildcache
|
||||
# We need to first generate everything w/o setting GOOS/GOARCH/GOARM
|
||||
# Otherwise it will try to build supporting binaries (for the build itself) for the $TARGETPLATFORM, which we don't want.
|
||||
# Those helper bins need to be for the $BUILDPLATFORM.
|
||||
RUN \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/go/.buildcache \
|
||||
make clean generate; \
|
||||
export GOOS="$TARGETOS"; \
|
||||
export GOARCH="$TARGETARCH"; \
|
||||
if [ -n TARGETVARIANT ] && [ "$TARGETARCH" = "arm" ]; then \
|
||||
export GOARM="${TARGETVARIANT//v}"; \
|
||||
fi; \
|
||||
make build
|
||||
|
||||
|
||||
# Alaways last so a simple `docker build` with no `--target` will produce the binary
|
||||
FROM scratch AS binary
|
||||
COPY --from=build /go/src/github.com/azure/aks-engine/bin/* /
|
||||
|
Загрузка…
Ссылка в новой задаче