Skip to content

Commit 2487307

Browse files
smiratalos-bot
authored andcommitted
chore: rework build, move to ghcr.io, build for arm64/amd64
Dockerfile/Makefile reworked to support cross-compilation, multi-arch builds. Using Talos base tools image. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 9c5538c commit 2487307

File tree

8 files changed

+92
-142
lines changed

8 files changed

+92
-142
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*
2+
!api
3+
!config
4+
!controllers
5+
!hack
6+
!internal
7+
!pkg
8+
!go.mod
9+
!go.sum
10+
!README.md
11+
!PROJECT
12+
!*.go

.drone.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ steps:
77
- name: setup-ci
88
image: autonomy/build-container:latest
99
commands:
10-
- git fetch --tags
11-
- apk add coreutils
12-
- docker buildx create --driver docker-container --platform linux/amd64 --buildkitd-flags "--allow-insecure-entitlement security.insecure" --name local --use unix:///var/outer-run/docker.sock
13-
- docker buildx inspect --bootstrap
10+
- setup-ci
1411
privileged: true
1512
volumes:
1613
- name: docker-socket
@@ -23,6 +20,8 @@ steps:
2320
- name: build-pull-request
2421
image: autonomy/build-container:latest
2522
pull: always
23+
environment:
24+
PLATFORM: linux/amd64,linux/arm64
2625
commands:
2726
- make
2827
when:
@@ -41,12 +40,13 @@ steps:
4140
image: autonomy/build-container:latest
4241
pull: always
4342
environment:
44-
DOCKER_USERNAME:
45-
from_secret: docker_username
46-
DOCKER_PASSWORD:
47-
from_secret: docker_password
43+
GHCR_USERNAME:
44+
from_secret: ghcr_username
45+
GHCR_PASSWORD:
46+
from_secret: ghcr_token
47+
PLATFORM: linux/amd64,linux/arm64
4848
commands:
49-
- docker login --username "$${DOCKER_USERNAME}" --password "$${DOCKER_PASSWORD}"
49+
- docker login --username "$${GHCR_USERNAME}" --password "$${GHCR_PASSWORD}" ghcr.io
5050
- make PUSH=true
5151
when:
5252
event:
@@ -128,6 +128,6 @@ depends_on:
128128
- default
129129
---
130130
kind: signature
131-
hmac: 9e465020b2d4d694c23f176e05cef4c7da9bb75acb2a51a230bef7343f4ee18c
131+
hmac: 2847e7d6100e958e0391d8c3822c13fca9fb50de86ec5ee648a9eacce0978e5b
132132

133133
...

Dockerfile

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,57 @@
1-
# syntax = docker/dockerfile-upstream:1.1.4-experimental
1+
# syntax = docker/dockerfile-upstream:1.2.0-labs
22

3-
FROM golang:1.15 AS build
3+
# Meta args applied to stage base names.
4+
5+
ARG TOOLS
6+
ARG PKGS
7+
8+
# Resolve package images using ${PKGS} to be used later in COPY --from=.
9+
10+
FROM ghcr.io/talos-systems/ca-certificates:${PKGS} AS pkg-ca-certificates
11+
FROM ghcr.io/talos-systems/fhs:${PKGS} AS pkg-fhs
12+
13+
# The base target provides the base for running various tasks against the source
14+
# code
15+
16+
FROM --platform=${BUILDPLATFORM} ${TOOLS} AS build
17+
SHELL ["/toolchain/bin/bash", "-c"]
18+
ENV PATH /toolchain/bin:/toolchain/go/bin:/go/bin
19+
RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"]
20+
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
21+
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
422
ENV GO111MODULE on
523
ENV GOPROXY https://proxy.golang.org
624
ENV CGO_ENABLED 0
7-
WORKDIR /tmp
8-
RUN go get sigs.k8s.io/controller-tools/cmd/[email protected]
9-
RUN go get k8s.io/code-generator/cmd/[email protected]
25+
ENV GOCACHE /.cache/go-build
26+
ENV GOMODCACHE /.cache/mod
27+
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/[email protected]
28+
RUN --mount=type=cache,target=/.cache go install k8s.io/code-generator/cmd/[email protected]
1029
WORKDIR /src
1130
COPY ./go.mod ./
1231
COPY ./go.sum ./
13-
RUN go mod download
14-
RUN go mod verify
32+
RUN --mount=type=cache,target=/.cache go mod download
33+
RUN --mount=type=cache,target=/.cache go mod verify
1534
COPY ./ ./
16-
RUN go list -mod=readonly all >/dev/null
17-
RUN ! go mod tidy -v 2>&1 | grep .
35+
RUN --mount=type=cache,target=/.cache go list -mod=readonly all >/dev/null
36+
RUN --mount=type=cache,target=/.cache ! go mod tidy -v 2>&1 | grep .
1837

1938
FROM build AS manifests-build
2039
ARG NAME
21-
RUN controller-gen crd:crdVersions=v1 paths="./api/..." output:crd:dir=config/crd/bases output:webhook:dir=config/webhook webhook
22-
RUN controller-gen rbac:roleName=manager-role paths="./controllers/..." output:rbac:dir=config/rbac
40+
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
41+
RUN --mount=type=cache,target=/.cache controller-gen rbac:roleName=manager-role paths="./controllers/..." output:rbac:dir=config/rbac
2342
FROM scratch AS manifests
2443
COPY --from=manifests-build /src/config /config
2544

2645
FROM build AS generate-build
27-
RUN controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
28-
RUN conversion-gen --input-dirs=./api/v1alpha2 --output-base ./ --output-file-base=zz_generated.conversion --go-header-file=./hack/boilerplate.go.txt
46+
RUN --mount=type=cache,target=/.cache controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
47+
RUN --mount=type=cache,target=/.cache conversion-gen --input-dirs=./api/v1alpha2 --output-base ./ --output-file-base=zz_generated.conversion --go-header-file=./hack/boilerplate.go.txt
48+
2949
FROM scratch AS generate
3050
COPY --from=generate-build /src/api /api
3151

32-
FROM k8s.gcr.io/hyperkube:v1.17.0 AS release-build
33-
RUN apt update -y \
34-
&& apt install -y curl \
35-
&& curl -LO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.4.0/kustomize_v3.4.0_linux_amd64.tar.gz \
36-
&& tar -xf kustomize_v3.4.0_linux_amd64.tar.gz -C /usr/local/bin \
37-
&& rm kustomize_v3.4.0_linux_amd64.tar.gz
52+
FROM --platform=${BUILDPLATFORM} alpine:3.13 AS release-build
53+
ADD https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.1.0/kustomize_v4.1.0_linux_amd64.tar.gz .
54+
RUN tar -xf kustomize_v4.1.0_linux_amd64.tar.gz -C /usr/local/bin && rm kustomize_v4.1.0_linux_amd64.tar.gz
3855
COPY ./config ./config
3956
ARG REGISTRY_AND_USERNAME
4057
ARG NAME
@@ -44,16 +61,19 @@ RUN cd config/manager \
4461
&& cd - \
4562
&& kustomize build config > /bootstrap-components.yaml \
4663
&& cp config/metadata/metadata.yaml /metadata.yaml
64+
4765
FROM scratch AS release
4866
COPY --from=release-build /bootstrap-components.yaml /bootstrap-components.yaml
4967
COPY --from=release-build /metadata.yaml /metadata.yaml
5068

5169
FROM build AS binary
52-
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=linux go build -ldflags "-s -w" -o /manager
70+
ARG TARGETARCH
71+
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=${TARGETARCH} go build -ldflags "-s -w" -o /manager
5372
RUN chmod +x /manager
5473

5574
FROM scratch AS container
56-
COPY --from=docker.io/autonomy/ca-certificates:v0.1.0 / /
57-
COPY --from=docker.io/autonomy/fhs:v0.1.0 / /
75+
COPY --from=pkg-ca-certificates / /
76+
COPY --from=pkg-fhs / /
5877
COPY --from=binary /manager /manager
78+
LABEL org.opencontainers.image.source https://github.com/talos-systems/cluster-api-bootstrap-provider-talos
5979
ENTRYPOINT [ "/manager" ]

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
REGISTRY ?= docker.io
2-
USERNAME ?= autonomy
1+
REGISTRY ?= ghcr.io
2+
USERNAME ?= talos-systems
33
SHA ?= $(shell git describe --match=none --always --abbrev=8 --dirty)
44
TAG ?= $(shell git describe --tag --always --dirty)
55
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
@@ -8,6 +8,9 @@ NAME := cluster-api-talos-controller
88

99
ARTIFACTS := _out
1010

11+
TOOLS ?= ghcr.io/talos-systems/tools:v0.5.0
12+
PKGS ?= v0.5.0
13+
1114
BUILD := docker buildx build
1215
PLATFORM ?= linux/amd64
1316
PROGRESS ?= auto
@@ -18,6 +21,8 @@ COMMON_ARGS += --platform=$(PLATFORM)
1821
COMMON_ARGS += --build-arg=REGISTRY_AND_USERNAME=$(REGISTRY_AND_USERNAME)
1922
COMMON_ARGS += --build-arg=NAME=$(NAME)
2023
COMMON_ARGS += --build-arg=TAG=$(TAG)
24+
COMMON_ARGS += --build-arg=PKGS=$(PKGS)
25+
COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
2126

2227
all: manifests container
2328

@@ -63,19 +68,19 @@ init: ## Initialize the project.
6368

6469
.PHONY: generate
6570
generate: ## Generate source code.
66-
@$(MAKE) local-$@ DEST=./
71+
@$(MAKE) local-$@ DEST=./ PLATFORM=linux/amd64
6772

6873
.PHONY: container
6974
container: generate ## Build the container image.
7075
@$(MAKE) docker-$@ TARGET_ARGS="--push=$(PUSH)"
7176

7277
.PHONY: manifests
7378
manifests: ## Generate manifests (e.g. CRD, RBAC, etc.).
74-
@$(MAKE) local-$@ DEST=./
79+
@$(MAKE) local-$@ DEST=./ PLATFORM=linux/amd64
7580

7681
.PHONY: release
7782
release: manifests container ## Create the release YAML. The build result will be ouput to the specified local destination.
78-
@$(MAKE) local-$@ DEST=./$(ARTIFACTS)
83+
@$(MAKE) local-$@ DEST=./$(ARTIFACTS) PLATFORM=linux/amd64
7984

8085
.PHONY: deploy
8186
deploy: manifests ## Deploy to a cluster. This is for testing purposes only.

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigs.yaml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.2.8
7+
controller-gen.kubebuilder.io/version: v0.5.0
88
creationTimestamp: null
99
name: talosconfigs.bootstrap.cluster.x-k8s.io
1010
spec:
@@ -24,14 +24,10 @@ spec:
2424
description: TalosConfig is the Schema for the talosconfigs API
2525
properties:
2626
apiVersion:
27-
description: 'APIVersion defines the versioned schema of this representation
28-
of an object. Servers should convert recognized schemas to the latest
29-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
3028
type: string
3129
kind:
32-
description: 'Kind is a string value representing the REST resource this
33-
object represents. Servers may infer this from the endpoint the client
34-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
3531
type: string
3632
metadata:
3733
type: object
@@ -59,12 +55,10 @@ spec:
5955
description: ErrorReason will be set on non-retryable errors
6056
type: string
6157
ready:
62-
description: Ready indicates the BootstrapData field is ready to be
63-
consumed
58+
description: Ready indicates the BootstrapData field is ready to be consumed
6459
type: boolean
6560
talosConfig:
66-
description: Talos config will be a string containing the config for
67-
download
61+
description: Talos config will be a string containing the config for download
6862
type: string
6963
type: object
7064
type: object
@@ -78,14 +72,10 @@ spec:
7872
description: TalosConfig is the Schema for the talosconfigs API
7973
properties:
8074
apiVersion:
81-
description: 'APIVersion defines the versioned schema of this representation
82-
of an object. Servers should convert recognized schemas to the latest
83-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
75+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
8476
type: string
8577
kind:
86-
description: 'Kind is a string value representing the REST resource this
87-
object represents. Servers may infer this from the endpoint the client
88-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
78+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
8979
type: string
9080
metadata:
9181
type: object
@@ -119,8 +109,7 @@ spec:
119109
description: TalosConfigStatus defines the observed state of TalosConfig
120110
properties:
121111
dataSecretName:
122-
description: DataSecretName is the name of the secret that stores
123-
the bootstrap data script.
112+
description: DataSecretName is the name of the secret that stores the bootstrap data script.
124113
type: string
125114
failureMessage:
126115
description: FailureMessage will be set on non-retryable errors
@@ -129,12 +118,10 @@ spec:
129118
description: FailureReason will be set on non-retryable errors
130119
type: string
131120
ready:
132-
description: Ready indicates the BootstrapData field is ready to be
133-
consumed
121+
description: Ready indicates the BootstrapData field is ready to be consumed
134122
type: boolean
135123
talosConfig:
136-
description: Talos config will be a string containing the config for
137-
download
124+
description: Talos config will be a string containing the config for download
138125
type: string
139126
type: object
140127
type: object

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigtemplates.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.2.8
7+
controller-gen.kubebuilder.io/version: v0.5.0
88
creationTimestamp: null
99
name: talosconfigtemplates.bootstrap.cluster.x-k8s.io
1010
spec:
@@ -21,18 +21,13 @@ spec:
2121
- name: v1alpha2
2222
schema:
2323
openAPIV3Schema:
24-
description: TalosConfigTemplate is the Schema for the talosconfigtemplates
25-
API
24+
description: TalosConfigTemplate is the Schema for the talosconfigtemplates API
2625
properties:
2726
apiVersion:
28-
description: 'APIVersion defines the versioned schema of this representation
29-
of an object. Servers should convert recognized schemas to the latest
30-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
3128
type: string
3229
kind:
33-
description: 'Kind is a string value representing the REST resource this
34-
object represents. Servers may infer this from the endpoint the client
35-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
3631
type: string
3732
metadata:
3833
type: object
@@ -62,18 +57,13 @@ spec:
6257
- name: v1alpha3
6358
schema:
6459
openAPIV3Schema:
65-
description: TalosConfigTemplate is the Schema for the talosconfigtemplates
66-
API
60+
description: TalosConfigTemplate is the Schema for the talosconfigtemplates API
6761
properties:
6862
apiVersion:
69-
description: 'APIVersion defines the versioned schema of this representation
70-
of an object. Servers should convert recognized schemas to the latest
71-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
63+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
7264
type: string
7365
kind:
74-
description: 'Kind is a string value representing the REST resource this
75-
object represents. Servers may infer this from the endpoint the client
76-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
66+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
7767
type: string
7868
metadata:
7969
type: object

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/talos-systems/cluster-api-bootstrap-provider-talos
22

3-
go 1.15
4-
5-
replace github.com/kubernetes-sigs/bootkube => github.com/talos-systems/bootkube v0.14.1-0.20200131192519-720c01d02032
3+
go 1.16
64

75
require (
86
github.com/evanphx/json-patch v4.9.0+incompatible

0 commit comments

Comments
 (0)