Compare commits

..
Author SHA1 Message Date
j4n fa318ac0b6 feat(dovecot): support Debian 13 (trixie)
Our 2.3.21 debs are older than trixie's 2.4.1, so the -1 pin now gets put in
in before any apt run, and the debs get installed in with one apt-get call because
fix-broken removes pinned packages. Missing builds now fail instead of falling
back to the distro dovecot.
2026-12-02 20:11:45 +01:00
j4n 9f98ebfc76 test(dovecot): assert exact primary and fallback download URLs 2026-12-01 10:04:48 +01:00
j4n 708211d71d fix(cmdeploy): check venv python versions and purge if mismatched
`cmdeploy run` fails after system upgrade to Debian 13 with
 "Fatal Python error: init_fs_encoding: failed to get the Python codec of the
 filesystem encoding" ,
indicating a Python version missmatch. Check for both versions and remove old
`remote_venv_dir` on mismatch to allow clean reinitialization by subsequent
pip.virtualenv().
2026-12-01 10:04:48 +01:00
5 changed files with 205 additions and 115 deletions
+1 -35
View File
@@ -1,38 +1,4 @@
## [1.14.0] - 2026-12-05
### Bug Fixes
- *(dovecot/lmtp)* retry from the raw mail when the first saved mail was expunged
- *(dovecot)* upgrade dovecot to `2.3.21+dfsg1-3+chatmail3 (deb12u1)` to include fixes from Debian security backports
- Allow http MX delivery to carry max-message-sized messages
- Read account address from list_transports()
- *(postfix)* Set bounce_queue_lifetime to match maximal_queue_lifetime
- Don't overwrite default journald.conf
- Let users overwrite volatile logging
- *(nginx)* Don't leak internal port 8443 in directory redirects
- Reset journald.conf back to packaged version if overridden (#1067)
- Don't check delta.chat/help links as it uses javascript for redirects
- *(docs)* OpenDKIM does not verify signatures but filtermail
- Chatmail-expire dry run no longer deletes over-quota messages
- *(dns)* Drop obsolete ADSP DNS record
### Documentation
- Remove ``/en/`` from deltachat links to get redirected to right language (#1073)
### Features
- Don't advertise special IMAP capabilities
- Increase message size from 30 to 50 mb gross
- Chatmail-expire writes storage statistics with --prom, replacing the daily fsreport scan
- *(expire)* Export deployed relay commit as chatmail_version_info
### Refactor
- Un-hardcode filesystem paths in configuration templates
- Merge fsreport.py into expire.py
- Merge Report into Expiry class and shorten prom output code
- *(dns)* Remove ssh calls from cmdeploy.dns
# Changelog for chatmail deployment
## [1.13.0] - 2026-09-22
+23
View File
@@ -102,6 +102,23 @@ def _install_remote_venv_with_chatmaild(deployer) -> None:
dest=remote_dist_file,
)
# Remove venv if its Python major.minor doesn't match the system Python
server.shell(
name="remove stale chatmaild venv if python version changed",
commands=[
"\n".join(
[
r"re='[0-9]+\.[0-9]+'", # major.minor out of 'Python X.Y.Z'
'sys_version=$(python3 --version 2>/dev/null | grep -oE "$re")',
f'venv_version=$({remote_venv_dir}/bin/python --version 2>/dev/null | grep -oE "$re")',
# an empty sys_version means we could not tell: keep the venv
f'[ -z "$sys_version" ] || [ "$sys_version" = "$venv_version" ] '
f"|| rm -rf {remote_venv_dir}",
]
)
],
)
pip.virtualenv(
name=f"chatmaild virtualenv {remote_venv_dir}",
path=remote_venv_dir,
@@ -421,6 +438,12 @@ class ChatmailDeployer(Deployer):
src=BytesIO(b'APT::Install-Recommends "false";\n'),
dest="/etc/apt/apt.conf.d/00InstallRecommends",
)
# Pin dovecot-* to priority -1 before any apt operation, apt should
# never manage dovecot as our version might be lower than the distro's.
self.put_file(
src=StringIO("Package: dovecot-*\nPin: version *\nPin-Priority: -1\n"),
dest="/etc/apt/preferences.d/pin-dovecot",
)
apt.update(name="apt update", cache_time=24 * 3600)
apt.upgrade(name="upgrade apt packages", auto_remove=True)
+31 -26
View File
@@ -1,11 +1,10 @@
import io
import urllib.request
from chatmaild.config import Config
from pyinfra import host
from pyinfra.facts.deb import DebPackages
from pyinfra.facts.server import Arch, Command, Sysctl
from pyinfra.operations import apt, files, server
from pyinfra.operations import files, server
from cmdeploy.basedeploy import (
Deployer,
@@ -16,9 +15,6 @@ from cmdeploy.basedeploy import (
)
from cmdeploy.pins import DOVECOT_SHA256, DOVECOT_VERSION
DOVECOT_STAMPED_VERSION = f"{DOVECOT_VERSION}+deb12u1"
DOVECOT_PACKAGE_VERSION = f"1:{DOVECOT_STAMPED_VERSION}"
class DovecotDeployer(Deployer):
daemon_reload = False
@@ -30,34 +26,29 @@ class DovecotDeployer(Deployer):
def install(self):
arch = host.get_fact(Arch)
version_id = host.get_fact(Command, "grep '^VERSION_ID=' /etc/os-release")
deb_release = _parse_version_id(version_id)
with blocked_service_startup():
debs = []
for pkg in ("core", "imapd", "lmtpd", "auth-lua"):
deb, changed = _download_dovecot_package(pkg, arch)
deb, changed = _download_dovecot_package(pkg, arch, deb_release)
self.need_restart |= changed
if deb:
debs.append(deb)
if debs:
deb_list = " ".join(debs)
# First dpkg may fail on missing dependencies (stderr suppressed);
# apt-get --fix-broken pulls them in, then dpkg retries cleanly.
# apt resolves dependencies of local debs despite the -1 pin, while
# apt-get --fix-broken after dpkg -i removes the pinned packages.
server.shell(
name="Install dovecot packages",
commands=[
f"dpkg --force-confdef --force-confold -i {deb_list} 2> /dev/null || true",
"DEBIAN_FRONTEND=noninteractive apt-get -y --fix-broken install",
f"dpkg --force-confdef --force-confold -i {deb_list}",
"DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades"
" -o Dpkg::Options::=--force-confdef"
" -o Dpkg::Options::=--force-confold"
f" install {deb_list}",
],
)
self.need_restart = True
self.put_file(
src=io.StringIO(
"Package: dovecot-*\n"
"Pin: version *\n"
"Pin-Priority: -1\n"
),
dest="/etc/apt/preferences.d/pin-dovecot",
)
def configure(self):
configure_remote_units(self, self.config.mail_domain_bare, self.units)
@@ -85,6 +76,15 @@ class DovecotDeployer(Deployer):
)
def _parse_version_id(version_line: str) -> int:
"""Debian major release from an /etc/os-release VERSION_ID line."""
_, _, raw = (version_line or "").strip().partition("=")
try:
return int(raw.strip('"'))
except ValueError:
raise ValueError(f"cannot determine Debian release from {version_line!r}")
def _pick_url(primary, fallback):
try:
req = urllib.request.Request(primary, method="HEAD")
@@ -94,22 +94,27 @@ def _pick_url(primary, fallback):
return fallback
def _download_dovecot_package(package: str, arch: str) -> tuple[str | None, bool]:
def _download_dovecot_package(
package: str, arch: str, deb_release: int
) -> tuple[str | None, bool]:
"""Download a dovecot .deb if needed, return (path, changed)."""
arch = "amd64" if arch == "x86_64" else arch
arch = "arm64" if arch == "aarch64" else arch
pkg_name = f"dovecot-{package}"
sha256 = DOVECOT_SHA256.get((package, arch))
if sha256 is None:
op = apt.packages(packages=[pkg_name])
return None, bool(getattr(op, "changed", False))
# never fall back to the distro package
try:
sha256 = DOVECOT_SHA256[(arch, deb_release, package)]
except KeyError:
raise ValueError(f"no dovecot build for {pkg_name} on deb{deb_release}/{arch}")
# chatmail/dovecot CI stamps the distro suffix into package version and filename
stamped_version = f"{DOVECOT_VERSION}+deb{deb_release}u1"
installed_versions = host.get_fact(DebPackages).get(pkg_name, [])
if DOVECOT_PACKAGE_VERSION in installed_versions:
if f"1:{stamped_version}" in installed_versions:
return None, False
url_version = DOVECOT_STAMPED_VERSION.replace("+", "%2B")
url_version = stamped_version.replace("+", "%2B")
tag = DOVECOT_VERSION.replace("+", "%2B")
deb_base = f"{pkg_name}_{url_version}_{arch}.deb"
primary_url = f"https://download.delta.chat/dovecot/{deb_base}"
+17 -8
View File
@@ -28,16 +28,25 @@ MTAIL_ARTIFACTS = {
),
}
# distro-neutral base version, as committed in chatmail/dovecot debian/changelog
DOVECOT_VERSION = "2.3.21+dfsg1-3+chatmail3"
DOVECOT_SHA256 = {
("core", "amd64"): "8064ca9a940684007063d4a4f60ec265b364f07d26cb4a7ffec83fc775812ebe",
("core", "arm64"): "5f5665735a01c70fb22ac0415b3aea00d23c1301b52effab96bf92c1b1e4366c",
("imapd", "amd64"): "1175a1dafb755e393385306bbe109fccacd31d5177a72db16c0f0b1731a83221",
("imapd", "arm64"): "48399b20ab600a20eaf377f8de34eb8e2a393954e53c6636b1e37c7ea99fd8a6",
("lmtpd", "amd64"): "d0681cd5ae6680d13338ee2e2bad290f929cac8b62d913d842576f2413cde48e",
("lmtpd", "arm64"): "3ad2a4484b2fa52f33e536cb8e36d13d9a86cb5c98732d5fe0f5e4898af03de5",
("auth-lua", "amd64"): "d2764bd247abb6dd90ee8026cea277cb044f9ac02348abd45c692ce52a2ed6f4",
("auth-lua", "arm64"): "5164b74a47a70aa265097f66a7f38985ebd6c575f8432ba64122ae6267749286",
("amd64", 12, "auth-lua"): "d2764bd247abb6dd90ee8026cea277cb044f9ac02348abd45c692ce52a2ed6f4",
("arm64", 12, "auth-lua"): "5164b74a47a70aa265097f66a7f38985ebd6c575f8432ba64122ae6267749286",
("amd64", 13, "auth-lua"): "09db7adf07948d897f7f9e282ef274de256b6b6db6b0d5fcda283545766ed707",
("arm64", 13, "auth-lua"): "215627e7874006e2072df488a04e2413415fcd2f7a77a8ff5cdfd647bc33825d",
("amd64", 12, "core"): "8064ca9a940684007063d4a4f60ec265b364f07d26cb4a7ffec83fc775812ebe",
("arm64", 12, "core"): "5f5665735a01c70fb22ac0415b3aea00d23c1301b52effab96bf92c1b1e4366c",
("amd64", 13, "core"): "0e51cf819be1a06cde3cb9cafc6ce545919ca9af78355b7aa53168e607b0a539",
("arm64", 13, "core"): "33a9494092668726272332ba59deb89f71e0c8b16004f1742db2db6ab1cda565",
("amd64", 12, "imapd"): "1175a1dafb755e393385306bbe109fccacd31d5177a72db16c0f0b1731a83221",
("arm64", 12, "imapd"): "48399b20ab600a20eaf377f8de34eb8e2a393954e53c6636b1e37c7ea99fd8a6",
("amd64", 13, "imapd"): "cdd052b7702006102a0a473c26cc5c2fda45e62bb858717dc39d49abf3543152",
("arm64", 13, "imapd"): "b4b14017ae2fd4f5e4de661f9e0e034a10390730dba76a00636a72e44051b6e7",
("amd64", 12, "lmtpd"): "d0681cd5ae6680d13338ee2e2bad290f929cac8b62d913d842576f2413cde48e",
("arm64", 12, "lmtpd"): "3ad2a4484b2fa52f33e536cb8e36d13d9a86cb5c98732d5fe0f5e4898af03de5",
("amd64", 13, "lmtpd"): "627175c4d76bfc15e2458d07d0fc173f804ea2781ccb418c133eecd5d7cdeab2",
("arm64", 13, "lmtpd"): "bdbedaa701f65dafa9f31aff40e79d2c61fa79a6c4268457db177a0b92186add",
}
TURN_VERSION = "v0.4"
TURN_ARTIFACTS = {
@@ -3,9 +3,13 @@ from types import SimpleNamespace
import pytest
from pyinfra.facts.deb import DebPackages
from pyinfra.facts.server import Command
from cmdeploy.dovecot import deployer as dovecot_deployer
# what dpkg reports after installing our deb12 build
INSTALLED_DEB12 = f"1:{dovecot_deployer.DOVECOT_VERSION}+deb12u1"
def make_host(*fact_pairs):
"""Build a mock host; get_fact(cls) dispatches to the provided facts mapping.
@@ -19,7 +23,7 @@ def make_host(*fact_pairs):
"""
facts = dict(fact_pairs)
def get_fact(cls):
def get_fact(cls, *args):
if cls not in facts:
registered = ", ".join(c.__name__ for c in facts)
raise LookupError(
@@ -64,7 +68,7 @@ def track_shell(monkeypatch):
def test_download_dovecot_package_skips_epoch_matched_install(monkeypatch):
epoch_version = dovecot_deployer.DOVECOT_PACKAGE_VERSION
epoch_version = INSTALLED_DEB12
downloads = []
monkeypatch.setattr(
dovecot_deployer,
@@ -82,15 +86,18 @@ def test_download_dovecot_package_skips_epoch_matched_install(monkeypatch):
lambda **kwargs: downloads.append(kwargs),
)
deb, changed = dovecot_deployer._download_dovecot_package("core", "amd64")
deb, changed = dovecot_deployer._download_dovecot_package(
"core", "amd64", deb_release=12
)
assert deb is None, f"expected no deb path when version matches, got {deb!r}"
assert changed is False, "should not flag changed when version already installed"
assert downloads == [], "should not download when version already installed"
@pytest.mark.parametrize(("arch", "deb_release"), [("amd64", 12), ("arm64", 13)])
def test_download_dovecot_package_uses_archive_version_for_url_and_filename(
monkeypatch,
monkeypatch, deb_release, arch
):
downloads = []
monkeypatch.setattr(
@@ -98,6 +105,53 @@ def test_download_dovecot_package_uses_archive_version_for_url_and_filename(
"host",
make_host((DebPackages, {})),
)
urls = {}
monkeypatch.setattr(
dovecot_deployer,
"_pick_url",
lambda primary, fallback: urls.update(primary=primary, fallback=fallback)
or primary,
)
monkeypatch.setattr(
dovecot_deployer.files,
"download",
lambda **kwargs: downloads.append(kwargs),
)
deb, changed = dovecot_deployer._download_dovecot_package(
"core", arch, deb_release=deb_release
)
version = dovecot_deployer.DOVECOT_VERSION
deb_base = f"dovecot-core_{version}+deb{deb_release}u1_{arch}.deb"
deb_base = deb_base.replace("+", "%2B")
tag = version.replace("+", "%2B")
# the release tag carries no distro suffix and filenames carry no epoch
assert changed is True, "should flag changed when package not yet installed"
assert deb == f"/root/{deb_base}"
assert urls["primary"] == f"https://download.delta.chat/dovecot/{deb_base}"
assert urls["fallback"] == (
"https://github.com/chatmail/dovecot/releases/download/"
f"upstream%2F{tag}/{deb_base}"
)
assert len(downloads) == 1, "files.download should be called exactly once"
assert downloads[0]["src"] == urls["primary"]
assert (
downloads[0]["sha256sum"]
== dovecot_deployer.DOVECOT_SHA256[(arch, deb_release, "core")]
), "must pass the sha256 matching (arch, release, package)"
def test_download_dovecot_package_replaces_deb12_build_after_upgrade_to_13(
monkeypatch,
):
downloads = []
monkeypatch.setattr(
dovecot_deployer,
"host",
make_host((DebPackages, {"dovecot-core": [INSTALLED_DEB12]})),
)
monkeypatch.setattr(
dovecot_deployer,
"_pick_url",
@@ -109,17 +163,12 @@ def test_download_dovecot_package_uses_archive_version_for_url_and_filename(
lambda **kwargs: downloads.append(kwargs),
)
deb, changed = dovecot_deployer._download_dovecot_package("core", "amd64")
archive_version = dovecot_deployer.DOVECOT_STAMPED_VERSION.replace("+", "%2B")
expected_deb = f"/root/dovecot-core_{archive_version}_amd64.deb"
# Verify the returned path uses archive version, not package version (with epoch)
assert changed is True, "should flag changed when package not yet installed"
assert deb == expected_deb, f"deb path mismatch: {deb!r} != {expected_deb!r}"
assert dovecot_deployer.DOVECOT_PACKAGE_VERSION not in deb, (
f"deb path should use archive version (no epoch), got {deb!r}"
deb, changed = dovecot_deployer._download_dovecot_package(
"core", "amd64", deb_release=13
)
assert changed is True, "a deb12 build on a deb13 host must be replaced"
assert "deb13u1" in deb, f"expected the deb13 build, got {deb!r}"
assert len(downloads) == 1, "files.download should be called exactly once"
@@ -133,13 +182,14 @@ def test_install_skips_dpkg_path_when_epoch_matched_packages_present(
(
dovecot_deployer.DebPackages,
{
"dovecot-core": [dovecot_deployer.DOVECOT_PACKAGE_VERSION],
"dovecot-imapd": [dovecot_deployer.DOVECOT_PACKAGE_VERSION],
"dovecot-lmtpd": [dovecot_deployer.DOVECOT_PACKAGE_VERSION],
"dovecot-auth-lua": [dovecot_deployer.DOVECOT_PACKAGE_VERSION],
"dovecot-core": [INSTALLED_DEB12],
"dovecot-imapd": [INSTALLED_DEB12],
"dovecot-lmtpd": [INSTALLED_DEB12],
"dovecot-auth-lua": [INSTALLED_DEB12],
},
),
(dovecot_deployer.Arch, "x86_64"),
(Command, 'VERSION_ID="12"'),
),
)
downloads = []
@@ -158,39 +208,23 @@ def test_install_skips_dpkg_path_when_epoch_matched_packages_present(
)
def test_install_unsupported_arch_falls_back_to_apt(
def test_install_unsupported_arch_raises(
deployer, patch_blocked, mock_files_put, track_shell, monkeypatch
):
# For unsupported architectures, all fact lookups return the arch string.
monkeypatch.setattr(
dovecot_deployer,
"host",
SimpleNamespace(get_fact=lambda cls: "riscv64"),
make_host(
(dovecot_deployer.Arch, "riscv64"),
(Command, 'VERSION_ID="12"'),
),
)
apt_calls = []
# Mirrors apt.packages() return value: OperationMeta with .changed property.
# Only lmtpd triggers a change to verify |= accumulation of changed flags.
def fake_apt(**kwargs):
apt_calls.append(kwargs)
changed = "lmtpd" in kwargs["packages"][0]
return SimpleNamespace(changed=changed)
# we never fall back to the pinned distro package
with pytest.raises(ValueError, match="no dovecot build for dovecot-core"):
deployer.install()
monkeypatch.setattr(dovecot_deployer.apt, "packages", fake_apt)
deployer.install()
actual_pkgs = [c["packages"] for c in apt_calls]
assert actual_pkgs == [
["dovecot-core"],
["dovecot-imapd"],
["dovecot-lmtpd"],
["dovecot-auth-lua"],
], f"expected apt install of core/imapd/lmtpd/auth-lua, got {actual_pkgs}"
assert track_shell == [], "should not run dpkg for unsupported arch"
assert deployer.need_restart is True, (
"need_restart should be True when apt installed a package"
)
def test_install_runs_dpkg_when_packages_need_download(
@@ -202,6 +236,7 @@ def test_install_runs_dpkg_when_packages_need_download(
make_host(
(dovecot_deployer.DebPackages, {}),
(dovecot_deployer.Arch, "x86_64"),
(Command, 'VERSION_ID="12"'),
),
)
monkeypatch.setattr(
@@ -221,10 +256,9 @@ def test_install_runs_dpkg_when_packages_need_download(
f"expected one server.shell() call for dpkg install, got {len(track_shell)}"
)
cmds = track_shell[0]["commands"]
assert len(cmds) == 3, f"expected 3 dpkg/apt commands, got: {cmds}"
assert cmds[0].startswith("dpkg --force-confdef --force-confold -i ")
assert "apt-get -y --fix-broken install" in cmds[1]
assert cmds[2].startswith("dpkg --force-confdef --force-confold -i ")
assert len(cmds) == 1, f"expected one apt-get install command, got: {cmds}"
assert "apt-get -y --allow-downgrades" in cmds[0]
assert " install /root/dovecot-core_" in cmds[0]
assert deployer.need_restart is True, (
"need_restart should be True after dpkg install"
)
@@ -239,3 +273,56 @@ def test_pick_url_falls_back_on_primary_error(monkeypatch):
assert result == "http://fallback", (
f"should fall back when primary fails, got {result!r}"
)
def test_install_fails_on_unsupported_debian_version(
deployer, patch_blocked, monkeypatch
):
monkeypatch.setattr(
dovecot_deployer,
"host",
make_host(
(dovecot_deployer.Arch, "x86_64"),
(Command, 'VERSION_ID="99"'),
),
)
with pytest.raises(ValueError, match="no dovecot build for dovecot-core on deb99"):
deployer.install()
@pytest.mark.parametrize(
"version_line",
["", None, "ID=debian", "VERSION_ID="],
ids=["empty", "none", "no-version-id", "empty-value"],
)
def test_parse_version_id_raises_without_version_id(version_line):
with pytest.raises(ValueError, match="cannot determine Debian release"):
dovecot_deployer._parse_version_id(version_line)
@pytest.mark.parametrize(
("version_line", "deb_release"),
[('VERSION_ID="12"\n', 12), ('VERSION_ID="13"\n', 13), ("VERSION_ID=13", 13)],
)
def test_parse_version_id(version_line, deb_release):
assert dovecot_deployer._parse_version_id(version_line) == deb_release
def test_dovecot_sha256_covers_all_packages_per_release():
"""Every release in the table needs all four packages on both arches."""
table = dovecot_deployer.DOVECOT_SHA256
expected = {
(arch, pkg)
for arch in ("amd64", "arm64")
for pkg in ("core", "imapd", "lmtpd", "auth-lua")
}
for release in {r for _, r, _ in table}:
got = {(arch, pkg) for arch, r, pkg in table if r == release}
assert got == expected, f"deb{release} incomplete: {sorted(expected - got)}"
def test_dovecot_sha256_has_no_duplicate_hashes():
"""Each build is a distinct file, so a repeated hash is a copy-paste error."""
table = dovecot_deployer.DOVECOT_SHA256
assert len(set(table.values())) == len(table)