nixos: app stacks on Podman, unchanged

The apps keep deploying themselves: their CI copies a compose file and
a .env and runs docker compose as user deploy. `docker` is now the real
Docker CLI against rootful Podman's socket, so compose, inspect and
logs behave as before and every user sees the same containers.

Their compose files still expect the storage stack's network and the
hosts postgres and garage. On ops every container resolves those two
names to the host, where the native services run, and an empty storage
network exists, so nothing in the app repositories has to change for
the move itself.

Tried on the rehearsal pair with the real asxpio and datacenterbingo
images on the restored database and Garage (mail and IndexNow
disabled): both serve through Traefik, and a local compose build works.

One thing does need the app repositories: Podman ignores the
HEALTHCHECK of OCI-format images, which is what the CI builds, so the
deploy's wait for "healthy" would time out. Declaring the healthcheck
in each compose file fixes it, also under Docker; see MIGRATION.md.

ops-data.sh now also moves the monitoring history, Traefik's
certificates and the app directories, and pulls the images again.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 05:11:17 +04:00
commit fa46d26f89
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
5 changed files with 98 additions and 10 deletions

View file

@ -0,0 +1,38 @@
# The app stacks (asxpio, datacenterbingo, blog, czsk, vhpbot) deploy
# themselves from their own repositories: CI copies a compose file and a
# .env to /opt/<app> and runs `docker compose up -d` as user deploy.
#
# Their compose files still expect the Docker-era storage stack: a
# network named "storage" and the hosts "postgres" and "garage" on it.
# Postgres and Garage are native services now, so every container on
# this host resolves those two names to the host, and the network exists
# empty. Nothing in the app repositories has to change for the move;
# dropping the storage network from their compose files is a later
# clean-up.
{ config, pkgs, ... }:
let
hosts = pkgs.writeText "container-hosts" ''
10.10.0.10 postgres garage
'';
in
{
virtualisation.containers.containersConf.settings.containers.base_hosts_file = "${hosts}";
# The API service (the socket the Docker CLI and Traefik use) reads it
# at start only
systemd.services.podman.restartTriggers = [ hosts ];
# `docker compose up --build` (vhpbot-prod builds on the host) starts
# BuildKit in a privileged container
asxpio.security.containers."buildx_buildkit_.*" = [ "privileged" ];
systemd.services.podman-network-storage = {
description = "Podman network storage (empty; see apps.nix)";
wantedBy = [ "multi-user.target" ];
path = [ config.virtualisation.podman.package ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = "podman network exists storage || podman network create storage";
};
}

View file

@ -4,6 +4,7 @@
{ lib, ... }: { lib, ... }:
{ {
imports = [ imports = [
./apps.nix
./crawler.nix ./crawler.nix
./forgejo.nix ./forgejo.nix
./garage.nix ./garage.nix

View file

@ -46,6 +46,32 @@ if [ -f "$src/opt/traefik/letsencrypt/acme.json" ]; then
install -o traefik -g traefik -m 600 "$src/opt/traefik/letsencrypt/acme.json" /var/lib/traefik/acme.json install -o traefik -g traefik -m 600 "$src/opt/traefik/letsencrypt/acme.json" /var/lib/traefik/acme.json
fi fi
echo "== Monitoring history (Docker volumes; not in the restic backup)"
mvvol() { # mvvol <volume> <dest> <owner>
if [ -d "$vols/$1/_data" ]; then
rm -rf "$2"; mkdir -p "$(dirname "$2")"
mv "$vols/$1/_data" "$2"; chown -R "$3" "$2"
else
echo " $1: not there (a restore, not a conversion); starting empty"
fi
}
vols=$src/var/lib/docker/volumes
mvvol monitoring_prometheus-data /var/lib/prometheus2/data prometheus:prometheus
mvvol monitoring_loki-data /var/lib/loki loki:loki
if [ -f "$vols/monitoring_grafana-data/_data/grafana.db" ]; then
install -d -o grafana -g grafana /var/lib/grafana/data
mv "$vols/monitoring_grafana-data/_data/grafana.db" /var/lib/grafana/data/grafana.db
chown grafana:grafana /var/lib/grafana/data/grafana.db
fi
echo "== App stacks (compose file and .env each; CI deploys them later)"
for app in asxpio datacenterbingo blog czsk vhpbot-prod vhpbot-dev; do
[ -d "$src/opt/$app" ] || continue
rm -rf "/opt/$app"; mv "$src/opt/$app" "/opt/$app"
chown -R deploy:deploy "/opt/$app"
done
[ ! -d "$src/root/backups" ] || { rm -rf /root/backups; mv "$src/root/backups" /root/backups; }
echo "== Starting" echo "== Starting"
touch /var/lib/.data-in-place touch /var/lib/.data-in-place
systemctl start postgresql.service systemctl start postgresql.service
@ -63,4 +89,16 @@ echo "== Forgejo: hooks and SSH keys for the new paths"
forgejo-admin regenerate hooks forgejo-admin regenerate hooks
forgejo-admin regenerate keys forgejo-admin regenerate keys
echo "== Done. Check: systemctl --failed; garage status; a git clone over SSH and HTTPS" echo "== App stacks: images again (Docker's image store does not carry over)"
for app in asxpio datacenterbingo blog czsk vhpbot-prod vhpbot-dev; do
[ -f "/opt/$app/docker-compose.yml" ] || continue
echo " $app"
if grep -q "^ *build:" "/opt/$app/docker-compose.yml" && ! grep -q "image: *git" "/opt/$app/docker-compose.yml"; then
runuser -l deploy -c "cd /opt/$app && docker compose up -d --build" || echo " $app FAILED"
else
runuser -l deploy -c "cd /opt/$app && docker compose pull -q && docker compose up -d" || echo " $app FAILED"
fi
done
echo "== Done. Check: systemctl --failed; garage status; a git clone over SSH and HTTPS;"
echo " docker ps (as deploy): every app healthy; Grafana on gf.asxp.io"

View file

@ -244,9 +244,9 @@ in
pkgs.wireguard-tools pkgs.wireguard-tools
pkgs.iproute2 pkgs.iproute2
pkgs.coreutils pkgs.coreutils
config.virtualisation.podman.package pkgs.docker-client # `docker ps` / `docker inspect`, against Podman
"/run/current-system/sw" # docker, the alias for podman
]; ];
environment.DOCKER_HOST = "unix:///run/podman/podman.sock";
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
ExecStart = "${pkgs.python3}/bin/python3 ${./security-metrics.py} ${securityConfig}"; ExecStart = "${pkgs.python3}/bin/python3 ${./security-metrics.py} ${securityConfig}";

View file

@ -1,13 +1,16 @@
# Containers, for what has no native NixOS service: Podman, no Docker. # Containers, for what has no native NixOS service: Podman, no Docker
# Declared containers (virtualisation.oci-containers) become systemd units # daemon. Declared containers (virtualisation.oci-containers) become
# named podman-<name>.service. `docker` is an alias, and /run/docker.sock # systemd units named podman-<name>.service.
# is Podman's Docker-compatible socket (CI runner, compose files). #
{ ... }: # The `docker` command is the real Docker CLI (with compose and buildx)
# talking to rootful Podman's Docker-compatible socket, so the apps' CI
# deploys (`docker compose up -d`, `docker inspect`, `docker logs`) work
# unchanged, and root, deploy and the admins all see the same containers.
{ pkgs, ... }:
{ {
virtualisation.podman = { virtualisation.podman = {
enable = true; enable = true;
dockerCompat = true; dockerSocket.enable = true; # /run/docker.sock -> /run/podman/podman.sock
dockerSocket.enable = true;
defaultNetwork.settings.dns_enabled = true; defaultNetwork.settings.dns_enabled = true;
# Every image update and CI job leaves an image behind # Every image update and CI job leaves an image behind
autoPrune = { autoPrune = {
@ -17,4 +20,12 @@
}; };
}; };
virtualisation.oci-containers.backend = "podman"; virtualisation.oci-containers.backend = "podman";
environment.systemPackages = [ pkgs.docker-client ];
# Podman's DNS for container networks, on each bridge's gateway
asxpio.security.ports = [
"tcp/53/aardvark-dns"
"udp/53/aardvark-dns"
];
environment.variables.DOCKER_HOST = "unix:///run/podman/podman.sock";
} }