From 82c9f70a018a8288b5bcb95a5b96eec583f0ada3 Mon Sep 17 00:00:00 2001 From: agent-company Date: Tue, 26 May 2026 20:45:33 +0000 Subject: [PATCH] feat: add Flux ImageRepository + ImagePolicy + ImageUpdateAutomation for all three API services (closes leeworks-agents/api-company#51) --- flux/air-quality/helmrelease.yaml | 2 +- flux/holidays/helmrelease.yaml | 2 +- flux/image-automation/imagepolicies.yaml | 39 +++++++++++++++++++ flux/image-automation/imagerepositories.yaml | 34 ++++++++++++++++ .../imageupdateautomation.yaml | 37 ++++++++++++++++++ flux/image-automation/kustomization.yaml | 6 +++ flux/kustomization.yaml | 1 + flux/zip-enrichment/helmrelease.yaml | 2 +- 8 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 flux/image-automation/imagepolicies.yaml create mode 100644 flux/image-automation/imagerepositories.yaml create mode 100644 flux/image-automation/imageupdateautomation.yaml create mode 100644 flux/image-automation/kustomization.yaml diff --git a/flux/air-quality/helmrelease.yaml b/flux/air-quality/helmrelease.yaml index 128be9a..a7a6920 100644 --- a/flux/air-quality/helmrelease.yaml +++ b/flux/air-quality/helmrelease.yaml @@ -35,7 +35,7 @@ spec: - name: gitea-registry containers: - name: air-quality - image: registry.leeworks.dev/air-quality/server:latest + image: registry.leeworks.dev/air-quality/server:latest # {"$imagepolicy": "flux-system:air-quality"} ports: - containerPort: 3000 env: diff --git a/flux/holidays/helmrelease.yaml b/flux/holidays/helmrelease.yaml index 35c48ba..40cc750 100644 --- a/flux/holidays/helmrelease.yaml +++ b/flux/holidays/helmrelease.yaml @@ -35,7 +35,7 @@ spec: - name: gitea-registry containers: - name: holidays - image: registry.leeworks.dev/holidays/server:latest + image: registry.leeworks.dev/holidays/server:latest # {"$imagepolicy": "flux-system:holidays"} ports: - containerPort: 3000 env: diff --git a/flux/image-automation/imagepolicies.yaml b/flux/image-automation/imagepolicies.yaml new file mode 100644 index 0000000..f55609c --- /dev/null +++ b/flux/image-automation/imagepolicies.yaml @@ -0,0 +1,39 @@ +# ImagePolicy: select the latest semver tag from each ImageRepository. +# Tags pushed by CI should follow semver (e.g. v1.2.3) or use "latest" — +# the semver policy picks up any vX.Y.Z tag. The "latest" alias keeps +# things working before formal releases are tagged. +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImagePolicy +metadata: + name: zip-enrichment + namespace: flux-system +spec: + imageRepositoryRef: + name: zip-enrichment + policy: + semver: + range: ">=0.1.0" +--- +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImagePolicy +metadata: + name: holidays + namespace: flux-system +spec: + imageRepositoryRef: + name: holidays + policy: + semver: + range: ">=0.1.0" +--- +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImagePolicy +metadata: + name: air-quality + namespace: flux-system +spec: + imageRepositoryRef: + name: air-quality + policy: + semver: + range: ">=0.1.0" diff --git a/flux/image-automation/imagerepositories.yaml b/flux/image-automation/imagerepositories.yaml new file mode 100644 index 0000000..bbf7214 --- /dev/null +++ b/flux/image-automation/imagerepositories.yaml @@ -0,0 +1,34 @@ +# Flux image-reflector-controller watches these registries for new image tags. +# Requires: flux-system/gitea-image-automation-token secret (see docs/operator-runbook.md) +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImageRepository +metadata: + name: zip-enrichment + namespace: flux-system +spec: + image: registry.leeworks.dev/zip-enrichment/server + interval: 5m + secretRef: + name: gitea-leeworks-agents-token +--- +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImageRepository +metadata: + name: holidays + namespace: flux-system +spec: + image: registry.leeworks.dev/holidays/server + interval: 5m + secretRef: + name: gitea-leeworks-agents-token +--- +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImageRepository +metadata: + name: air-quality + namespace: flux-system +spec: + image: registry.leeworks.dev/air-quality/server + interval: 5m + secretRef: + name: gitea-leeworks-agents-token diff --git a/flux/image-automation/imageupdateautomation.yaml b/flux/image-automation/imageupdateautomation.yaml new file mode 100644 index 0000000..332cd2d --- /dev/null +++ b/flux/image-automation/imageupdateautomation.yaml @@ -0,0 +1,37 @@ +# ImageUpdateAutomation: when an ImagePolicy selects a new tag, this object +# instructs Flux to open a commit on the api-company repo updating the +# image reference in the relevant HelmRelease values. +# +# The GitRepository used here is the api-company source (flux-system/api-company). +# Flux needs write access; create the token secret first: +# kubectl create secret generic gitea-image-automation-token \ +# -n flux-system \ +# --from-literal=username=leeworks-agents \ +# --from-literal=password= +# Then patch the api-company GitRepository to reference it (or reuse +# gitea-leeworks-agents-token if that token also has write:repository scope). +apiVersion: image.toolkit.fluxcd.io/v1beta2 +kind: ImageUpdateAutomation +metadata: + name: api-company + namespace: flux-system +spec: + interval: 10m + sourceRef: + kind: GitRepository + name: api-company + git: + checkout: + ref: + branch: main + commit: + author: + email: agent@leeworks.dev + name: Flux Image Automation + messageTemplate: | + chore(image): update {{range .Updated.Images}}{{.Repository}}:{{.NewTag}} {{end}} + push: + branch: main + update: + path: ./flux + strategy: Setters diff --git a/flux/image-automation/kustomization.yaml b/flux/image-automation/kustomization.yaml new file mode 100644 index 0000000..bd70636 --- /dev/null +++ b/flux/image-automation/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - imagerepositories.yaml + - imagepolicies.yaml + - imageupdateautomation.yaml diff --git a/flux/kustomization.yaml b/flux/kustomization.yaml index b5db76d..cef3caf 100644 --- a/flux/kustomization.yaml +++ b/flux/kustomization.yaml @@ -7,3 +7,4 @@ resources: - zip-enrichment - holidays - air-quality + - image-automation diff --git a/flux/zip-enrichment/helmrelease.yaml b/flux/zip-enrichment/helmrelease.yaml index 7bf2698..bb18736 100644 --- a/flux/zip-enrichment/helmrelease.yaml +++ b/flux/zip-enrichment/helmrelease.yaml @@ -35,7 +35,7 @@ spec: - name: gitea-registry containers: - name: zip-enrichment - image: registry.leeworks.dev/zip-enrichment/server:latest + image: registry.leeworks.dev/zip-enrichment/server:latest # {"$imagepolicy": "flux-system:zip-enrichment"} ports: - containerPort: 3000 env: