Skip to content

Commit 0e72887

Browse files
authored
Introduce builder (#559)
Signed-off-by: Andrei Kvapil <[email protected]> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added configuration for Kubernetes builder environment - Introduced Talos imager configuration with version v1.8.4 - Implemented garbage collection policies for OCI worker storage management - **Chores** - Updated Makefile to streamline image building process - Added Kubernetes deployment templates for builder sandbox - **Infrastructure** - Created new configuration files for builder package - Enhanced build and deployment workflows <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 38a993b commit 0e72887

6 files changed

Lines changed: 105 additions & 7 deletions

File tree

‎packages/core/builder/Chart.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apiVersion: v2
2+
name: builder
3+
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process

‎packages/core/builder/Makefile‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
NAMESPACE=cozy-builder
2+
NAME := builder
3+
4+
TALOS_VERSION=$(shell awk '/^version:/ {print $$2}' ../installer/images/talos/profiles/installer.yaml)
5+
6+
include ../../../scripts/common-envs.mk
7+
8+
help: ## Show this help.
9+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
10+
11+
show:
12+
helm template -n $(NAMESPACE) $(NAME) .
13+
14+
apply: ## Create builder sandbox in existing Kubernetes cluster.
15+
helm template -n $(NAMESPACE) $(NAME) . | kubectl apply -f -
16+
docker buildx ls | grep -q '^buildkit-builder*' || docker buildx create \
17+
--bootstrap \
18+
--name=buildkit-$(NAME) \
19+
--driver=kubernetes \
20+
--driver-opt=namespace=$(NAMESPACE),replicas=1 \
21+
--platform=linux/amd64 \
22+
--platform=linux/arm64 \
23+
--use \
24+
--config config.toml
25+
26+
diff:
27+
helm template -n $(NAMESPACE) $(NAME) . | kubectl diff -f -
28+
29+
delete: ## Remove builder sandbox from existing Kubernetes cluster.
30+
kubectl delete deploy -n $(NAMESPACE) $(NAME)-talos-imager
31+
docker buildx rm buildkit-$(NAME)
32+
33+
wait-for-builder:
34+
kubectl wait deploy --for=condition=Progressing -n $(NAMESPACE) $(NAME)-talos-imager
35+
kubectl wait pod --for=condition=Ready -n $(NAMESPACE) -l app=$(NAME)-talos-imager

‎packages/core/builder/config.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[worker.oci]
2+
gc = true
3+
gckeepstorage = 50000
4+
5+
[[worker.oci.gcpolicy]]
6+
keepBytes = 10737418240
7+
keepDuration = 604800
8+
filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"]
9+
[[worker.oci.gcpolicy]]
10+
all = true
11+
keepBytes = 53687091200
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: {{ .Release.Namespace }}
6+
labels:
7+
pod-security.kubernetes.io/enforce: privileged
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: {{ .Release.Name }}-talos-imager
13+
namespace: {{ .Release.Namespace }}
14+
spec:
15+
replicas: 1
16+
selector:
17+
matchLabels:
18+
app: {{ .Release.Name }}-talos-imager
19+
strategy:
20+
type: Recreate
21+
template:
22+
metadata:
23+
labels:
24+
app: {{ .Release.Name }}-talos-imager
25+
spec:
26+
automountServiceAccountToken: false
27+
terminationGracePeriodSeconds: 1
28+
containers:
29+
- name: imagere
30+
image: "{{ .Values.talos.imager.image }}"
31+
securityContext:
32+
privileged: true
33+
command:
34+
- sleep
35+
- infinity
36+
volumeMounts:
37+
- mountPath: /dev
38+
name: dev
39+
volumes:
40+
- hostPath:
41+
path: /dev
42+
type: Directory
43+
name: dev

‎packages/core/builder/values.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
talos:
2+
imager:
3+
image: ghcr.io/siderolabs/imager:v1.8.4

‎packages/core/installer/Makefile‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ diff:
1919

2020
update:
2121
hack/gen-profiles.sh
22+
IMAGE=$$(awk '/^version:/ {print $$2}' images/talos/profiles/installer.yaml) \
23+
yq -i '.talos.imager.image = "ghcr.io/siderolabs/imager:" + strenv(IMAGE)' ../builder/values.yaml
2224

2325
image: pre-checks image-cozystack image-talos image-matchbox
2426

25-
image-cozystack:
27+
image-cozystack: run-builder
2628
make -C ../../.. repos
2729
docker buildx build -f images/cozystack/Dockerfile ../../.. \
2830
--provenance false \
@@ -37,13 +39,11 @@ image-cozystack:
3739
yq -i '.cozystack.image = strenv(IMAGE)' values.yaml
3840
rm -f images/cozystack.json
3941

40-
image-talos:
42+
image-talos: run-builder
4143
test -f ../../../_out/assets/installer-amd64.tar || make talos-installer
42-
docker load -i ../../../_out/assets/installer-amd64.tar
43-
docker tag ghcr.io/siderolabs/installer:$(TALOS_VERSION) $(REGISTRY)/talos:$(call settag,$(TALOS_VERSION))
44-
docker push $(REGISTRY)/talos:$(call settag,$(TALOS_VERSION))
44+
skopeo copy docker-archive:../../../_out/assets/installer-amd64.tar docker://$(REGISTRY)/talos:$(call settag,$(TALOS_VERSION))
4545

46-
image-matchbox:
46+
image-matchbox: run-builder
4747
test -f ../../../_out/assets/kernel-amd64 || make talos-kernel
4848
test -f ../../../_out/assets/initramfs-metal-amd64.xz || make talos-initramfs
4949
docker buildx build -f images/matchbox/Dockerfile ../../.. \
@@ -62,5 +62,8 @@ assets: talos-iso talos-nocloud talos-metal
6262
talos-initramfs talos-kernel talos-installer talos-iso talos-nocloud talos-metal:
6363
mkdir -p ../../../_out/assets
6464
cat images/talos/profiles/$(subst talos-,,$@).yaml | \
65-
docker run --rm -i -v /dev:/dev --privileged "ghcr.io/siderolabs/imager:$(TALOS_VERSION)" --tar-to-stdout - | \
65+
kubectl exec -i -n cozy-builder deploy/builder-talos-imager -- imager --tar-to-stdout - | \
6666
tar -C ../../../_out/assets -xzf-
67+
68+
run-builder:
69+
make -C ../builder/ apply wait-for-builder

0 commit comments

Comments
 (0)