Replaces the docker_container playbook, which published 127.0.0.1:6379 and kept its /data in an anonymous Docker volume -- the one the audit flagged because no backup script can see it (docs/podman-compat-audit.md 3.1). Valkey becomes the base Quadlet unit, the same shape as Postgres: it knows nothing about its clients, and a service attaches itself by dropping a file into valkey.container.d/ via valkey/roles/attach. Nothing on the host needs 6379, so there is no PublishPort at all rather than a narrower one. The name stays `valkey` for the directory, container, unit and Podman network, and only the alias clients connect on is `redis`: Nextcloud's config.php (written by the image from REDIS_HOST=redis), outline and overleaf reach it as `redis`, while paperless-ngx and yamtrack use the container name. Renaming would touch every REDIS_HOST for no gain. The uid/gid mapping is the detail worth spelling out, because the audit only records the uid. The Alpine image's `valkey` account is 999:1000, not 999:999 -- Alpine already has a gid 999, and the Dockerfile says so before creating the group with the next id. 999 is the uid the anonymous volume was owned by, so the uid matches what was already on disk, but mapping only the uid would leave every file valkey-server writes, dump.rdb included, group-owned by a subgid. Both ids map onto the connection user, so ~/podman-data/valkey stays tanshu:tanshu. Persistence stays on deliberately, and the mount with it. The contents are disposable -- nothing is copied off monoco, and a cold start is survivable -- but this is not purely a cache: Nextcloud keeps its PHP sessions and memcache.locking in it, and Yamtrack uses it as its Celery broker. With RDB on, a rebuild is a graceful stop that writes a final snapshot on SIGTERM that the next container loads, so a redeploy does not log every Nextcloud user out or discard queued tasks. Tmpfs=/data with `save ""` would remove the mount and the whole keep-id mapping with it, and is the right shape for a pure cache, but it would make every redeploy exactly that. The rootless-Podman prerequisites are not applied here: they are the shared task file at caddy/roles/podman, and a host that has run caddy/playbook.yml has them. Two ordering details are load-bearing: - The attach include asserts that <name>.network exists before writing a drop-in that names it. Quadlet rejects the whole valkey unit, with an error that never mentions the drop-in, when a referenced .network file is missing. - A service that attaches flushes handlers before starting the app. The restart that joins Valkey to the new network is a handler, so by default it runs at the end of the play, after the app has already come up and failed to resolve `redis`. nextcloud/roles/valkey is the working example. The play waits on `valkey-cli ping` inside the container rather than trusting systemctl is-active. Restart=always reports active even while the container crash-loops, which is exactly what a wrong keep-id looks like.
44 lines
1.5 KiB
Django/Jinja
44 lines
1.5 KiB
Django/Jinja
# Valkey — rootless Podman Quadlet unit.
|
|
# Managed by Ansible (valkey/roles/valkey). Do not edit by hand.
|
|
#
|
|
# Valkey deliberately does NOT list the app networks it serves. Each service
|
|
# attaches itself by dropping a file into:
|
|
#
|
|
# {{ valkey_dropin_dir }}/
|
|
#
|
|
# which Quadlet merges into this unit. Removing a service therefore never means
|
|
# editing this file. See readme.md, "How services attach themselves".
|
|
|
|
[Unit]
|
|
Description=Valkey in-memory data store
|
|
Documentation=https://valkey.io/docs/
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Container]
|
|
ContainerName={{ container_name }}
|
|
Image={{ image }}
|
|
|
|
# Map the container's valkey account (uid {{ app_uid }}, gid {{ app_gid }}) onto
|
|
# {{ podman_user }} on the host, so {{ host_directory }} stays owned by
|
|
# {{ podman_user }} — owner *and* group — and never by a subuid or a subgid.
|
|
# The two ids differ because Alpine already has a gid 999; see vars/default.yml.
|
|
# The image's entrypoint runs as container-root, chowns the owner of anything in
|
|
# its WORKDIR that is not already valkey's, then drops to
|
|
# {{ app_uid }}:{{ app_gid }} — so everything it creates lands on
|
|
# {{ podman_user }} too.
|
|
UserNS=keep-id:uid={{ app_uid }},gid={{ app_gid }}
|
|
|
|
# No PublishPort, on purpose. The Docker-era playbook published
|
|
# 127.0.0.1:6379; here Valkey is reachable only from the app networks that
|
|
# attach themselves to it, so there is no host port to firewall or to collide
|
|
# with a second cache.
|
|
Volume={{ host_directory }}:{{ data_mount }}
|
|
|
|
[Service]
|
|
Restart=always
|
|
TimeoutStartSec=120
|
|
|
|
[Install]
|
|
WantedBy=default.target
|