[platform] Use cozypkg instead of helm

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
Andrei Kvapil
2025-06-11 13:10:42 +02:00
parent 3266a5514e
commit 908c75927e
11 changed files with 33 additions and 74 deletions

View File

@@ -9,13 +9,13 @@ pre-checks:
../../../hack/pre-checks.sh
show:
helm template -n $(NAMESPACE) $(NAME) .
cozypkg show -n $(NAMESPACE) $(NAME) --plain
apply:
helm template -n $(NAMESPACE) $(NAME) . | kubectl apply -f -
cozypkg show -n $(NAMESPACE) $(NAME) --plain | kubectl apply -f-
diff:
helm template -n $(NAMESPACE) $(NAME) . | kubectl diff -f -
cozypkg show -n $(NAMESPACE) $(NAME) --plain | kubectl diff -f -
update:
hack/gen-profiles.sh
@@ -23,7 +23,6 @@ update:
image: pre-checks image-matchbox image-cozystack image-talos
image-cozystack:
make -C ../../.. repos
docker buildx build -f images/cozystack/Dockerfile ../../.. \
--provenance false \
--tag $(REGISTRY)/installer:$(call settag,$(TAG)) \

View File

@@ -1,4 +1,4 @@
FROM golang:alpine3.21 as k8s-await-election-builder
FROM golang:1.24-alpine as k8s-await-election-builder
ARG K8S_AWAIT_ELECTION_GITREPO=https://github.com/LINBIT/k8s-await-election
ARG K8S_AWAIT_ELECTION_VERSION=0.4.1
@@ -13,7 +13,10 @@ RUN git clone ${K8S_AWAIT_ELECTION_GITREPO} /usr/local/go/k8s-await-election/ \
&& make \
&& mv ./out/k8s-await-election-${TARGETARCH} /k8s-await-election
FROM golang:alpine3.21 as builder
FROM golang:1.24-alpine as builder
ARG TARGETOS
ARG TARGETARCH
RUN apk add --no-cache make git
RUN apk add helm --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
@@ -21,26 +24,26 @@ RUN apk add helm --repository=https://dl-cdn.alpinelinux.org/alpine/edge/communi
COPY . /src/
WORKDIR /src
RUN go mod download
RUN go build -o /cozystack-assets-server -ldflags '-extldflags "-static" -w -s' ./cmd/cozystack-assets-server
# Check that versions_map is not changed
RUN make repos
FROM alpine:3.21
FROM alpine:3.22
RUN apk add --no-cache make
RUN apk add helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk add yq
RUN apk add coreutils
RUN wget -O- https://github.com/cozystack/cozypkg/raw/refs/heads/main/hack/install.sh | sh -s
COPY scripts /cozystack/scripts
RUN apk add --no-cache make kubectl coreutils
COPY --from=builder /src/scripts /cozystack/scripts
COPY --from=builder /src/packages/core /cozystack/packages/core
COPY --from=builder /src/packages/system /cozystack/packages/system
COPY --from=builder /src/_out/repos /cozystack/assets/repos
COPY --from=builder /src/_out/logos /cozystack/assets/logos
COPY --from=builder /cozystack-assets-server /usr/bin/cozystack-assets-server
COPY --from=k8s-await-election-builder /k8s-await-election /usr/bin/k8s-await-election
COPY dashboards /cozystack/assets/dashboards
COPY --from=builder /src/dashboards /cozystack/assets/dashboards
WORKDIR /cozystack
ENTRYPOINT ["/usr/bin/k8s-await-election", "/cozystack/scripts/installer.sh" ]

View File

@@ -1,2 +1,2 @@
cozystack:
image: ghcr.io/cozystack/cozystack/installer:v0.32.0-beta.1@sha256:57e449187e4f76c3346de7646b4fe11c7136e63216b05ebd7171f8fd5cb077d2
image: ghcr.io/cozystack/cozystack/installer:latest@sha256:dedc7de5cd01f4b1336a4ff935ffc6600a52f63cdc020163dd9d35bf71373380

View File

@@ -1,23 +1,20 @@
NAME=platform
NAMESPACE=cozy-system
API_VERSIONS_FLAGS=$(addprefix -a ,$(shell kubectl api-versions))
show:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS)
cozypkg show -n $(NAMESPACE) $(NAME) --plain
apply:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) \
| kubectl apply -f-
cozypkg show -n $(NAMESPACE) $(NAME) --plain | kubectl apply -f-
kubectl delete helmreleases.helm.toolkit.fluxcd.io -l cozystack.io/marked-for-deletion=true -A
reconcile: apply
namespaces-show:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) -s templates/namespaces.yaml
cozypkg show -n $(NAMESPACE) $(NAME) --plain -s templates/namespaces.yaml
namespaces-apply:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) -s templates/namespaces.yaml | kubectl apply -n $(NAMESPACE) -f-
cozypkg show -n $(NAMESPACE) $(NAME) --plain -s templates/namespaces.yaml | kubectl apply -f-
diff:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) | kubectl diff -f-
cozypkg show -n $(NAMESPACE) $(NAME) --plain | kubectl diff -f-

View File

@@ -17,3 +17,4 @@ RUN curl -sSL "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm
RUN curl -sSL "https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_${TARGETOS}_${TARGETARCH}" -o /usr/local/bin/yq \
&& chmod +x /usr/local/bin/yq
RUN curl -sSL "https://fluxcd.io/install.sh" | bash
RUN curl -sSL "https://github.com/cozystack/cozypkg/raw/refs/heads/main/hack/install.sh" | sh -s

View File

@@ -1,4 +1,4 @@
FROM golang:1.23-alpine AS builder
FROM golang:1.24-alpine AS builder
ARG TARGETOS
ARG TARGETARCH

View File

@@ -1,4 +1,4 @@
FROM golang:1.23-alpine AS builder
FROM golang:1.24-alpine AS builder
ARG TARGETOS
ARG TARGETARCH

View File

@@ -4,7 +4,7 @@ NAMESPACE=cozy-fluxcd
include ../../../scripts/package.mk
apply-locally:
helm upgrade -i -n $(NAMESPACE) $(NAME) .
cozypkg apply --plain -n $(NAMESPACE) $(NAME)
update:
rm -rf charts

View File

@@ -4,7 +4,7 @@ NAMESPACE=cozy-$(NAME)
include ../../../scripts/package.mk
apply-locally:
helm upgrade -i -n $(NAMESPACE) $(NAME) .
cozypkg apply --plain -n $(NAMESPACE) $(NAME)
update:
rm -rf charts

View File

@@ -1,37 +0,0 @@
#!/bin/sh
# This scripts adds common fluxcd labels to all objects
if [ -z "$NAME" ]; then
echo 'Variable $NAME is not set!' >&2
exit 1
fi
if [ -z "$NAMESPACE" ]; then
echo 'Variable $NAMESPACE is not set!' >&2
exit 1
fi
TMP_DIR=$(mktemp -d)
cat - > "${TMP_DIR}/helm-generated-output.yaml"
cat > "${TMP_DIR}/global-labels.yaml" <<EOT
apiVersion: builtin
kind: LabelTransformer
metadata:
name: global-labels
labels:
helm.toolkit.fluxcd.io/name: ${NAME}
helm.toolkit.fluxcd.io/namespace: ${NAMESPACE:-$HELM_NAMESPACE}
fieldSpecs:
- path: metadata/labels
create: true
EOT
cat > "${TMP_DIR}/kustomization.yaml" <<EOT
resources:
- helm-generated-output.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
- global-labels.yaml
EOT
kubectl kustomize "${TMP_DIR}"
rm -rf "${TMP_DIR}"

View File

@@ -1,30 +1,26 @@
.DEFAULT_GOAL=help
.PHONY=help show diff apply delete update image
.VALUES_FILES=$(shell kubectl get hr -n $(NAMESPACE) $(NAME) -o go-template='{{ range .spec.chart.spec.valuesFiles}}-f {{ . }} {{ end }}-f -')
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
show: check ## Show output of rendered templates
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm template --dry-run=server --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . $(.VALUES_FILES)
cozypkg show -n $(NAMESPACE) $(NAME)
apply: check suspend ## Apply Helm release to a Kubernetes cluster
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm upgrade -i --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . $(.VALUES_FILES)
cozypkg apply -n $(NAMESPACE) $(NAME)
diff: check ## Diff Helm release against objects in a Kubernetes cluster
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm diff upgrade --dry-run=server --show-secrets --allow-unreleased --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . $(.VALUES_FILES)
cozypkg diff -n $(NAMESPACE) $(NAME)
suspend: check ## Suspend reconciliation for an existing Helm release
kubectl patch hr -n $(NAMESPACE) $(NAME) -p '{"spec": {"suspend": true}}' --type=merge --field-manager=flux-client-side-apply
cozypkg suspend -n $(NAMESPACE) $(NAME)
resume: check ## Resume reconciliation for an existing Helm release
kubectl patch hr -n $(NAMESPACE) $(NAME) -p '{"spec": {"suspend": null}}' --type=merge --field-manager=flux-client-side-apply
cozypkg resume -n $(NAMESPACE) $(NAME)
delete: check suspend ## Delete Helm release from a Kubernetes cluster
helm uninstall -n $(NAMESPACE) $(NAME)
cozypkg delete -n $(NAMESPACE) $(NAME)
check:
@if [ -z "$(NAME)" ]; then echo "env NAME is not set!" >&2; exit 1; fi