sysroot: Rework /var handling to act like Docker `VOLUME /var`
authorColin Walters <walters@verbum.org>
Fri, 9 Feb 2024 19:44:43 +0000 (14:44 -0500)
committerColin Walters <walters@verbum.org>
Fri, 9 Feb 2024 22:46:12 +0000 (17:46 -0500)
commitf81b9fa1666c62a024d5ca0bbe876321f72529c7
tree18b7472dc2cceafae2a53746627953f5aa86dbdc
parent1c18bd256a8812332acf38479024f4558f403b25
sysroot: Rework /var handling to act like Docker `VOLUME /var`

We've long struggled with semantics for `/var`.  Our stance of
"/var should start out empty and be managed by the OS" is a strict
one, that pushes things closer to the original systemd upstream
ideal of the "OS state is in /usr".

However...well, a few things.  First, we had some legacy bits
here which were always populating the deployment `/var`.  I don't
think we need that if systemd is in use, so detect if the tree
has `usr/lib/tmpfiles.d`, and don't create that stuff at
`ostree admin stateroot-init` time if so.

Building on that then, we have the stateroot `var` starting out
actually empty.

When we do a deployment, if the stateroot `var` is empty,
make a copy (reflink if possible of course) of the commit's `/var`
into it.

This matches the semantics that Docker created with volumes,
and this is sufficiently simple and easy to explain that I think
it's closer to the right thing to do.

Crucially...it's just really handy to have some pre-existing
directories in `/var` in container images, because Docker (and podman/kube/etc)
don't run systemd and hence don't run `tmpfiles.d` on startup.

I really hit on the fact that we need `/var/tmp` in our container
images by default for example.

So there's still some overlap here with e.g. `/usr/lib/tmpfiles.d/var.conf`
as shipped by systemd, but that's fine - they don't actually conflict
per se.
Makefile-tests.am
configure.ac
docs/var.md
src/boot/ostree-tmpfiles.conf
src/libostree/ostree-sysroot-deploy.c
src/libostree/ostree-sysroot-private.h
src/libostree/ostree-sysroot.c
tests/kolainst/destructive/deployment-lint
tests/test-admin-deploy-var.sh [new file with mode: 0755]