build(monitoring): respin the Alerta image on a patched base (#5334)

Supersedes #5244 and #5333: the same change from an in-tree branch, so
CI can build the new image. Includes main merged in and the test fixture
fix from #5333.

## What this PR does

Alerta 9.1.0 is the latest upstream release, and
`alerta/alerta-web:9.1.0` still ships the Debian packages of its build
day, the compiler toolchain and `-dev` headers it built wheels with, and
Python packages whose fixes landed after the release. The monitoring
chart ran that image by tag, without a digest.

This builds the Alerta image in-tree from the upstream one:

- `images/alerta/Containerfile` starts from `alerta/alerta-web:9.1.0`
pinned by its index digest, upgrades the OS packages, purges the
build-only packages and lifts the affected Python packages within the
ranges the installed packages declare (`pip check` gates the build).
`cryptography` stays below 47 because `pyOpenSSL` requires it; `lxml`
stays on 5.x.
- The result is copied into an empty image so the purged files are
really gone, and the upstream image config (env, user, ports,
entrypoint, command) is restated exactly; `docker-entrypoint.sh` renders
the nginx, uWSGI and Alerta configs from those variables. The image is
752 MB against 1.32 GB upstream; a purge layer on top would have made it
1.78 GB.
- `make image` builds it as `alerta:v9.1.0-cozystack.0` and writes the
digest into `alerta.image`, like the traces collector. Until then the
default is the digest-pinned upstream image.
- The Deployment takes the image from `alerta.image` through
`cozy-lib.image`, so mirrored-registry installs work for Alerta as they
do for Grafana.

Trade-off: `apt-get upgrade` takes whatever Debian has at build time, so
two builds of one revision can differ. That is what a respin is for;
bump `ALERTA_COZYSTACK_REV` to publish a fresh one.

Testing (podman, amd64):

- With `postgres:17-alpine` and the chart's env, Alertmanager v4
webhooks to `/api/webhooks/prometheus`: firing critical → 201 and the
alert open; `event=Heartbeat` → 202 and the heartbeat recorded; resolved
→ 201 and the alert closed. Admin login 200, UI 200, no ERROR in the
logs, and `alerta_telegram`, `alerta_slack`, `alerta_prometheus` import.
Upstream 9.1.0 gives the same results with the same script.
- `trivy rootfs`, CRITICAL and HIGH: 29/940 → 3/76. The three critical
left (sqlite CVE-2025-7458, libxml2 CVE-2026-6653, zlib CVE-2023-45853)
and every remaining Debian HIGH have no Debian 12 fix; the remaining
Python HIGH are cryptography and lxml, held back as above.
- `helm unittest .` (306 tests, including the new
`tests/alerta_image_test.yaml`) and `helm template`.
- arm64 was not built locally; aarch64 cp313 wheels exist for every
upgraded Python package, so the purged toolchain is not needed there.

### Screenshots

No UI changes.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

(Trigger map walked against the diff: only packages/system/monitoring —
an image build, a values key with no schema, a template line and a test.
No apps/extra package, schema, platform value, hack tooling or CRD
changes.)

### Release note

```release-note
build(monitoring): Alerta now runs a cozystack respin of 9.1.0 on an upgraded Debian base, without the build toolchain and with patched Python dependencies; its image is pinned by digest and follows the cluster images registry.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Updates**
  * Alerta now runs from a pinned, refreshed container image.
* The Alerta image can be configured, and deployments respect the
configured image registry.
* The default image is replaced with the Cozystack-built image when
using the image build workflow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-18 13:28:26 +03:00
commit fd426c7e4b
5 files changed
+125 -3

No files matched your search

+20 -2
View File
@@ -7,7 +7,7 @@ include ../../../hack/package.mk
test:
helm unittest .
.PHONY: image image-otelcol-tracing
.PHONY: image image-otelcol-tracing image-alerta
# The collector is versioned by its upstream release, pinned in the
# Containerfile; bump COZYSTACK_REV for a respin on the same release (a new
@@ -16,7 +16,14 @@ OTELCOL_VERSION = $(shell awk -F= '/^ARG VERSION=/{print $$2}' images/otelcol-tr
COZYSTACK_REV = 0
COMPONENT_VERSION = v$(OTELCOL_VERSION)-cozystack.$(COZYSTACK_REV)
image: image-otelcol-tracing
# Alerta is versioned by the upstream release it respins, pinned in the
# Containerfile; bump ALERTA_COZYSTACK_REV for a respin on the same release.
ALERTA_VERSION = $(shell awk -F= '/^ARG VERSION=/{print $$2}' images/alerta/Containerfile)
ALERTA_COZYSTACK_REV = 0
ALERTA_COMPONENT_VERSION = v$(ALERTA_VERSION)-cozystack.$(ALERTA_COZYSTACK_REV)
image: image-otelcol-tracing image-alerta
.NOTPARALLEL: image
image-otelcol-tracing:
docker buildx build images/otelcol-tracing \
@@ -28,3 +35,14 @@ image-otelcol-tracing:
IMAGE="$(REGISTRY)/otelcol-tracing:$(COMPONENT_VERSION)@$$(yq e '."containerimage.digest"' images/otelcol-tracing.json -o json -r)" \
yq -i '.tracingCollector.image = strenv(IMAGE)' values.yaml
rm -f images/otelcol-tracing.json
image-alerta:
docker buildx build images/alerta \
--file images/alerta/Containerfile \
$(call image-tags,alerta,$(ALERTA_COMPONENT_VERSION)) \
$(call cache-args,alerta) \
--metadata-file images/alerta.json \
$(BUILDX_ARGS)
IMAGE="$(REGISTRY)/alerta:$(ALERTA_COMPONENT_VERSION)@$$(yq e '."containerimage.digest"' images/alerta.json -o json -r)" \
yq -i '.alerta.image = strenv(IMAGE)' values.yaml
rm -f images/alerta.json
@@ -0,0 +1,61 @@
# Alerta 9.1.0 is the latest upstream release, and its image still carries the
# Debian packages of its build day plus the toolchain it compiled wheels with.
# The respin upgrades the OS packages, drops the build-only ones and lifts the
# Python packages whose fixes postdate the release, within the ranges the
# installed packages declare: cryptography stays below 47 for pyOpenSSL, and
# lxml stays on 5.x. A bump of VERSION needs the digest of the new tag's index
# as well.
ARG VERSION=9.1.0
FROM docker.io/alerta/alerta-web:${VERSION}@sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39 AS patched
USER root
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get purge -y build-essential linux-libc-dev libc6-dev python3-dev \
libpq-dev libldap2-dev libsasl2-dev libxml2-dev libxslt1-dev libexpat1-dev git \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& /venv/bin/pip install --no-cache-dir --upgrade \
'PyJWT>=2.14.0' 'certifi>=2026.10.18' 'brotli>=1.2.1' 'aiohttp>=3.14.4' \
'urllib3>=2.8.0' 'pyasn1>=0.6.5' 'pymongo>=4.18.3' 'dnspython>=2.9.0' 'msgpack>=1.2.3' \
&& /venv/bin/pip check \
&& pip install --no-cache-dir --upgrade virtualenv 'filelock>=4.2.1'
# A purge on top of the upstream layers hides files without removing them, so
# the result is copied into an empty image. That drops the image config with
# the layers; it is restated below exactly as the upstream image declares it,
# because docker-entrypoint.sh renders the nginx, uWSGI and Alerta configs from
# these variables.
FROM scratch
COPY --from=patched / /
ENV PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/venv/bin \
GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305 \
PYTHON_VERSION=3.13.12 \
PYTHON_SHA256=2a84cd31dd8d8ea8aaff75de66fc1b4b0127dd5799aa50a64ae9a313885b4593 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
SERVER_VERSION=9.1.0 \
CLIENT_VERSION=8.5.3 \
WEBUI_VERSION=8.7.1 \
NGINX_WORKER_PROCESSES=1 \
NGINX_WORKER_CONNECTIONS=1024 \
UWSGI_PROCESSES=5 \
UWSGI_LISTEN=100 \
UWSGI_BUFFER_SIZE=8192 \
UWSGI_MAX_WORKER_LIFETIME=30 \
UWSGI_WORKER_LIFETIME_DELTA=3 \
HEARTBEAT_SEVERITY=major \
HK_EXPIRED_DELETE_HRS=2 \
HK_INFO_DELETE_HRS=12 \
ALERTA_SVR_CONF_FILE=/app/alertad.conf \
ALERTA_CONF_FILE=/app/alerta.conf \
ALERTA_WEB_CONF_FILE=/web/config.json
USER 1001
EXPOSE 8080 1717
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["supervisord", "-c", "/app/supervisord.conf"]
@@ -184,7 +184,7 @@ spec:
spec:
containers:
- name: alerta
image: "alerta/alerta-web:9.1.0"
image: {{ include "cozy-lib.image" (list .Values.alerta.image $) }}
imagePullPolicy: IfNotPresent
resources: {{- toYaml .Values.alerta.resources | nindent 12 }}
env:
@@ -0,0 +1,40 @@
suite: alerta runs the image from values through cozy-lib.image
templates:
- templates/alerta/alerta.yaml
release:
name: monitoring
namespace: tenant-root
set:
_cluster:
issuer-name: letsencrypt-prod
solver: http01
gateway-enabled: "false"
_namespace:
host: example.org
ingress: tenant-root
tests:
- it: renders alerta.image as the container image
set:
alerta.image: registry.example.com/alerta:v9.1.0-cozystack.0@sha256:0000000000000000000000000000000000000000000000000000000000000000
documentSelector:
path: kind
value: Deployment
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: registry.example.com/alerta:v9.1.0-cozystack.0@sha256:0000000000000000000000000000000000000000000000000000000000000000
- it: prefixes the image with the cluster images-registry when set
set:
_cluster.images-registry: mirror.example.com
alerta.image: registry.example.com/alerta:v9.1.0-cozystack.0@sha256:0000000000000000000000000000000000000000000000000000000000000000
documentSelector:
path: kind
value: Deployment
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: mirror.example.com/registry.example.com/alerta:v9.1.0-cozystack.0@sha256:0000000000000000000000000000000000000000000000000000000000000000
+3
View File
@@ -68,6 +68,9 @@ tracingCollector:
cpu: 100m
memory: 256Mi
alerta:
# Alerta respun on a patched base (images/alerta); `make image` replaces this
# upstream default with the cozystack build.
image: docker.io/alerta/alerta-web:9.1.0@sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39
storage: 10Gi
storageClassName: ""
resources: