Skip to content

Commit b1ba1f2

Browse files
committed
[platform] Separate assets server into dedicated daemonset
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 1f47fbc commit b1ba1f2

9 files changed

Lines changed: 121 additions & 34 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ build: build-deps
2626
make -C packages/system/bucket image
2727
make -C packages/system/objectstorage-controller image
2828
make -C packages/core/testing image
29+
make -C packages/core/platform image
2930
make -C packages/core/installer image
3031
make manifests
3132

‎packages/core/installer/images/cozystack/Dockerfile‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ WORKDIR /src
2626

2727
RUN go mod download
2828

29-
RUN go build -o /cozystack-assets-server -ldflags '-extldflags "-static" -w -s' ./cmd/cozystack-assets-server
30-
31-
RUN make repos
32-
3329
FROM alpine:3.22
3430

3531
RUN wget -O- https://github.com/cozystack/cozypkg/raw/refs/heads/main/hack/install.sh | sh -s -- -v 1.2.0
@@ -39,10 +35,7 @@ RUN apk add --no-cache make kubectl helm coreutils git jq
3935
COPY --from=builder /src/scripts /cozystack/scripts
4036
COPY --from=builder /src/packages/core /cozystack/packages/core
4137
COPY --from=builder /src/packages/system /cozystack/packages/system
42-
COPY --from=builder /src/_out/repos /cozystack/assets/repos
43-
COPY --from=builder /cozystack-assets-server /usr/bin/cozystack-assets-server
4438
COPY --from=k8s-await-election-builder /k8s-await-election /usr/bin/k8s-await-election
45-
COPY --from=builder /src/dashboards /cozystack/assets/dashboards
4639

4740
WORKDIR /cozystack
4841
ENTRYPOINT ["/usr/bin/k8s-await-election", "/cozystack/scripts/installer.sh" ]

‎packages/core/installer/templates/cozystack.yaml‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,10 @@ spec:
6868
valueFrom:
6969
fieldRef:
7070
fieldPath: metadata.name
71-
- name: assets
72-
image: "{{ .Values.cozystack.image }}"
73-
command:
74-
- /usr/bin/cozystack-assets-server
75-
- "-dir=/cozystack/assets"
76-
- "-address=:8123"
77-
ports:
78-
- name: http
79-
containerPort: 8123
8071
tolerations:
8172
- key: "node.kubernetes.io/not-ready"
8273
operator: "Exists"
8374
effect: "NoSchedule"
8475
- key: "node.cilium.io/agent-not-ready"
8576
operator: "Exists"
8677
effect: "NoSchedule"
87-
---
88-
apiVersion: v1
89-
kind: Service
90-
metadata:
91-
name: cozystack
92-
namespace: cozy-system
93-
spec:
94-
ports:
95-
- name: http
96-
port: 80
97-
targetPort: 8123
98-
selector:
99-
app: cozystack
100-
type: ClusterIP

‎packages/core/platform/Makefile‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
NAME=platform
22
NAMESPACE=cozy-system
33

4+
include ../../../scripts/common-envs.mk
5+
46
show:
57
cozypkg show -n $(NAMESPACE) $(NAME) --plain
68

@@ -18,3 +20,15 @@ namespaces-apply:
1820

1921
diff:
2022
cozypkg show -n $(NAMESPACE) $(NAME) --plain | kubectl diff -f-
23+
24+
image: image-assets
25+
image-assets:
26+
docker buildx build -f images/cozystack-assets/Dockerfile ../../.. \
27+
--tag $(REGISTRY)/cozystack-assets:$(call settag,$(TAG)) \
28+
--cache-from type=registry,ref=$(REGISTRY)/cozystack-assets:latest \
29+
--cache-to type=inline \
30+
--metadata-file images/cozystack-assets.json \
31+
$(BUILDX_ARGS)
32+
IMAGE="$(REGISTRY)/cozystack-assets:$(call settag,$(TAG))@$$(yq e '."containerimage.digest"' images/cozystack-assets.json -o json -r)" \
33+
yq -i '.assets.image = strenv(IMAGE)' values.yaml
34+
rm -f images/cozystack-assets.json
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang:1.24-alpine AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
RUN apk add --no-cache make git
7+
RUN apk add helm --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
8+
9+
COPY . /src/
10+
WORKDIR /src
11+
12+
RUN go mod download
13+
14+
RUN go build -o /cozystack-assets-server -ldflags '-extldflags "-static" -w -s' ./cmd/cozystack-assets-server
15+
16+
RUN make repos
17+
18+
FROM alpine:3.22
19+
20+
COPY --from=builder /src/_out/repos /cozystack/assets/repos
21+
COPY --from=builder /cozystack-assets-server /usr/bin/cozystack-assets-server
22+
COPY --from=builder /src/dashboards /cozystack/assets/dashboards
23+
24+
WORKDIR /cozystack
25+
ENTRYPOINT ["/usr/bin/cozystack-assets-server"]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: cozystack-assets
5+
namespace: cozy-system
6+
labels:
7+
app: cozystack-assets
8+
spec:
9+
serviceName: cozystack-assets
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app: cozystack-assets
14+
template:
15+
metadata:
16+
labels:
17+
app: cozystack-assets
18+
spec:
19+
hostNetwork: true
20+
containers:
21+
- name: assets-server
22+
image: "{{ .Values.assets.image }}"
23+
args:
24+
- "-dir=/cozystack/assets"
25+
- "-address=:8123"
26+
ports:
27+
- name: http
28+
containerPort: 8123
29+
hostPort: 8123
30+
tolerations:
31+
- operator: Exists
32+
---
33+
apiVersion: rbac.authorization.k8s.io/v1
34+
kind: Role
35+
metadata:
36+
name: cozystack-assets-reader
37+
namespace: cozy-system
38+
rules:
39+
- apiGroups: [""]
40+
resources:
41+
- pods/proxy
42+
resourceNames:
43+
- cozystack-assets-0
44+
verbs:
45+
- get
46+
- create
47+
- update
48+
---
49+
apiVersion: rbac.authorization.k8s.io/v1
50+
kind: RoleBinding
51+
metadata:
52+
name: cozystack-assets-reader
53+
namespace: cozy-system
54+
subjects:
55+
- kind: User
56+
name: cozystack-assets-reader
57+
apiGroup: rbac.authorization.k8s.io
58+
roleRef:
59+
kind: Role
60+
name: cozystack-assets-reader
61+
apiGroup: rbac.authorization.k8s.io
62+
---
63+
apiVersion: v1
64+
kind: Service
65+
metadata:
66+
name: cozystack-assets
67+
namespace: cozy-system
68+
spec:
69+
ports:
70+
- name: http
71+
port: 80
72+
targetPort: 8123
73+
selector:
74+
app: cozystack-assets
75+
type: ClusterIP

‎packages/core/platform/templates/helmrepos.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
cozystack.io/repository: system
99
spec:
1010
interval: 5m0s
11-
url: http://cozystack.cozy-system.svc/repos/system
11+
url: http://cozystack-assets.cozy-system.svc/repos/system
1212
---
1313
apiVersion: source.toolkit.fluxcd.io/v1
1414
kind: HelmRepository
@@ -20,7 +20,7 @@ metadata:
2020
cozystack.io/repository: apps
2121
spec:
2222
interval: 5m0s
23-
url: http://cozystack.cozy-system.svc/repos/apps
23+
url: http://cozystack-assets.cozy-system.svc/repos/apps
2424
---
2525
apiVersion: source.toolkit.fluxcd.io/v1
2626
kind: HelmRepository
@@ -31,4 +31,4 @@ metadata:
3131
cozystack.io/repository: extra
3232
spec:
3333
interval: 5m0s
34-
url: http://cozystack.cozy-system.svc/repos/extra
34+
url: http://cozystack-assets.cozy-system.svc/repos/extra

‎packages/core/platform/values.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
assets:
2+
image: ghcr.io/cozystack/cozystack/cozystack-assets:latest@sha256:19b166819d0205293c85d8351a3e038dc4c146b876a8e2ae21dce1d54f0b9e33

‎packages/extra/monitoring/templates/dashboards.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ spec:
1111
instanceSelector:
1212
matchLabels:
1313
dashboards: grafana
14-
url: http://cozystack.cozy-system.svc/dashboards/{{ . }}.json
14+
url: http://cozystack-assets.cozy-system.svc/dashboards/{{ . }}.json
1515
{{- end }}
1616
{{- end }}

0 commit comments

Comments
 (0)