-
Notifications
You must be signed in to change notification settings - Fork 28
/
Dockerfile
95 lines (79 loc) · 3.9 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# syntax = docker/dockerfile-upstream:1.2.0-labs
# Meta args applied to stage base names.
ARG TOOLS
ARG PKGS
# Resolve package images using ${PKGS} to be used later in COPY --from=.
FROM ghcr.io/siderolabs/ca-certificates:${PKGS} AS pkg-ca-certificates
FROM ghcr.io/siderolabs/fhs:${PKGS} AS pkg-fhs
# The base target provides the base for running various tasks against the source
# code
FROM --platform=${BUILDPLATFORM} ${TOOLS} AS build
SHELL ["/toolchain/bin/bash", "-c"]
ENV PATH /toolchain/bin:/toolchain/go/bin:/go/bin
RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org
ENV CGO_ENABLED 0
ENV GOCACHE /.cache/go-build
ENV GOMODCACHE /.cache/mod
ENV GOTOOLCHAIN local
ARG CONTROLLER_GEN_VERSION
ARG CONVERSION_GEN_VERSION
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION}
RUN --mount=type=cache,target=/.cache go install k8s.io/code-generator/cmd/conversion-gen@${CONVERSION_GEN_VERSION}
WORKDIR /src
COPY ./go.mod ./
COPY ./go.sum ./
RUN --mount=type=cache,target=/.cache go mod download
RUN --mount=type=cache,target=/.cache go mod verify
COPY ./ ./
RUN --mount=type=cache,target=/.cache go list -mod=readonly all >/dev/null
FROM build AS manifests-build
ARG NAME
RUN --mount=type=cache,target=/.cache controller-gen crd:crdVersions=v1 paths="./api/..." output:crd:dir=config/crd/bases output:webhook:dir=config/webhook webhook
RUN --mount=type=cache,target=/.cache controller-gen rbac:roleName=manager-role paths="./controllers/..." output:rbac:dir=config/rbac
FROM scratch AS manifests
COPY --from=manifests-build /src/config /config
FROM build AS generate-build
RUN --mount=type=cache,target=/.cache controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
RUN --mount=type=cache,target=/.cache conversion-gen --output-file=zz_generated.conversion.go --go-header-file=./hack/boilerplate.go.txt -v 9 ./api/v1alpha2
FROM scratch AS generate
COPY --from=generate-build /src/api /api
FROM build AS integration-test-build
ENV CGO_ENABLED 1
ARG TALOS_VERSION
ARG TAG
ARG ARTIFACTS
ARG PKG=github.com/siderolabs/cluster-api-bootstrap-provider-talos/internal/integration
ARG GO_LDFLAGS="-linkmode=external -extldflags '-static' -X ${PKG}.TalosVersion=${TALOS_VERSION} -X ${PKG}.Artifacts=${ARTIFACTS} -X ${PKG}.Tag=${TAG}"
RUN --mount=type=cache,target=/.cache go test -race -ldflags "${GO_LDFLAGS}" -coverpkg=./... -v -c ./internal/integration
FROM scratch AS integration-test
COPY --from=integration-test-build /src/integration.test /integration.test
FROM --platform=${BUILDPLATFORM} alpine:3.13 AS release-build
ADD https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.1.0/kustomize_v4.1.0_linux_amd64.tar.gz .
RUN tar -xf kustomize_v4.1.0_linux_amd64.tar.gz -C /usr/local/bin && rm kustomize_v4.1.0_linux_amd64.tar.gz
COPY ./config ./config
ARG REGISTRY_AND_USERNAME
ARG NAME
ARG TAG
RUN cd config/manager \
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/${NAME}:${TAG} \
&& cd - \
&& kustomize build config/default > /bootstrap-components.yaml \
&& cp config/metadata/metadata.yaml /metadata.yaml
FROM scratch AS release-manifests
ARG TAG
COPY --from=release-build /bootstrap-components.yaml /bootstrap-talos/${TAG}/bootstrap-components.yaml
COPY --from=release-build /metadata.yaml /bootstrap-talos/${TAG}/metadata.yaml
FROM build AS binary
ARG TARGETARCH
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=${TARGETARCH} go build -ldflags "-s -w" -o /manager
RUN chmod +x /manager
FROM scratch AS container
COPY --from=pkg-ca-certificates / /
COPY --from=pkg-fhs / /
COPY --from=binary /manager /manager
LABEL org.opencontainers.image.source https://github.com/siderolabs/cluster-api-bootstrap-provider-talos
ENTRYPOINT [ "/manager" ]