forked from Azure/aks-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
33 lines (27 loc) · 1.02 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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/* /