Compare commits

..

21 Commits

Author SHA1 Message Date
holger krekel
d51a60be57 fix error string 2024-03-28 12:17:33 +01:00
holger krekel
0938b3a1b5 persist pending notifications to directory so that they survive a restart 2024-03-28 12:13:53 +01:00
holger krekel
4710e0d734 use json instead of python's marshal 2024-03-28 11:05:25 +01:00
holger krekel
d74b25adea test and fix for edge case 2024-03-28 10:49:57 +01:00
holger krekel
917da899c6 add changelog entry 2024-03-28 10:33:20 +01:00
holger krekel
92dbabc23d various naming refinements 2024-03-28 10:28:42 +01:00
holger krekel
277465462e remove timeout support, it's not needed 2024-03-27 18:34:01 +01:00
holger krekel
92b7273c71 refine logging 2024-03-27 18:20:00 +01:00
holger krekel
9c31d0762e more resilience 2024-03-27 18:14:43 +01:00
holger krekel
fab5e8a082 move persistentdict into own file, rename 2024-03-27 18:07:56 +01:00
holger krekel
1da5d91b71 extend imap online test to cover multi-device 2024-03-27 17:41:57 +01:00
holger krekel
c45e98d1dc back to using marshal, and a filelock 2024-03-27 17:25:29 +01:00
holger krekel
409b2b6919 add a persistent dict impl 2024-03-27 17:06:43 +01:00
holger krekel
e2a1ddb987 add multi-token support 2024-03-27 15:03:59 +01:00
holger krekel
89734d99cf fix target dir 2024-03-27 13:49:14 +01:00
holger krekel
193c8b2e85 use "devicetoken" consistently and take it from a var 2024-03-27 13:29:42 +01:00
holger krekel
8694dce7ec properly startup metadata service and add online test for metadata 2024-03-27 13:17:33 +01:00
holger krekel
0cf092abd5 store metadata in a per-mbox dir 2024-03-27 12:45:05 +01:00
holger krekel
419de239ac store tokens on a per-maildir basis 2024-03-27 12:27:12 +01:00
holger krekel
00bed66660 store tokens in guid-directories 2024-03-27 10:29:22 +01:00
link2xt
845ee42f76 Store raw tokens instead of dictionaries in metadata 2024-03-27 10:01:46 +01:00
9 changed files with 70 additions and 101 deletions

View File

@@ -4,17 +4,12 @@ on:
push:
branches:
- main
pull_request:
paths-ignore:
- 'scripts/**'
- staging-ci
jobs:
deploy:
name: deploy on staging.testrun.org, and run tests
runs-on: ubuntu-latest
concurrency:
group: staging-deploy
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
@@ -24,45 +19,44 @@ jobs:
echo "${{ secrets.STAGING_SSH_KEY }}" >> ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan staging.testrun.org > ~/.ssh/known_hosts
rsync -avz root@staging.testrun.org:/var/lib/acme . || true
rsync -avz root@staging.testrun.org:/etc/dkimkeys . || true
# rsync -avz root@staging.testrun.org:/var/lib/acme . || true
# rsync -avz root@staging.testrun.org:/var/lib/rspamd/dkim . || true
- name: rebuild staging.testrun.org to have a clean VPS
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.HETZNER_API_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"image":"debian-12"}' \
"https://api.hetzner.cloud/v1/servers/${{ secrets.STAGING_SERVER_ID }}/actions/rebuild"
#- name: rebuild staging.testrun.org to have a clean VPS
# run: |
# curl -X POST \
# -H "Authorization: Bearer ${{ secrets.HETZNER_API_TOKEN }}" \
# -H "Content-Type: application/json" \
# -d '{"image":"debian-12"}' \
# "https://api.hetzner.cloud/v1/servers/${{ secrets.STAGING_SERVER_ID }}/actions/rebuild"
- run: scripts/initenv.sh
- name: append venv/bin to PATH
run: echo venv/bin >>$GITHUB_PATH
- name: upload TLS cert after rebuilding
run: |
echo " --- wait until staging.testrun.org VPS is rebuilt --- "
rm ~/.ssh/known_hosts
while ! ssh -o ConnectTimeout=180 -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u ; do sleep 1 ; done
ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u
rsync -avz acme/ root@staging.testrun.org:/var/lib/acme || true
rsync -avz dkimkeys/ root@staging.testrun.org:/etc/dkimkeys || true
ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org chown root:root -R /var/lib/acme
- name: run formatting checks
run: cmdeploy fmt -v
- name: run deploy-chatmail offline tests
run: pytest --pyargs cmdeploy
#- name: upload TLS cert after rebuilding
# run: |
# echo " --- wait until staging.testrun.org VPS is rebuilt --- "
# rm ~/.ssh/known_hosts
# while ! ssh -o ConnectTimeout=180 -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u ; do sleep 1 ; done
# ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u
# rsync -avz acme root@staging.testrun.org:/var/lib/ || true
# rsync -avz dkim root@staging.testrun.org:/var/lib/rspamd/ || true
- run: cmdeploy init staging.testrun.org
- run: cmdeploy run
- name: set DNS entries
run: |
ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org chown opendkim:opendkim -R /etc/dkimkeys
#ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org chown _rspamd:_rspamd -R /var/lib/rspamd/dkim
cmdeploy dns --zonefile staging-generated.zone
cat staging-generated.zone >> .github/workflows/staging.testrun.org-default.zone
cat .github/workflows/staging.testrun.org-default.zone

View File

@@ -1,20 +1,8 @@
# Changelog for chatmail deployment
## untagged
## unreleased
- better preserve notification order
([#263](https://github.com/deltachat/chatmail/pull/263))
- re-enable running the CI in pull requests, but not concurrently
([#258](https://github.com/deltachat/chatmail/pull/258))
## 1.1.0 - 2024-03-28
### The changelog starts to record changes from March 15th, 2024
- Move systemd unit templates to cmdeploy package
([#255](https://github.com/deltachat/chatmail/pull/255))
### Changes since March 15th, 2024
- Persist push tokens and support multiple device per address
([#254](https://github.com/deltachat/chatmail/pull/254))

View File

@@ -1,5 +1,5 @@
[Unit]
Description=Chatmail Postfix before queue filter
Description=Chatmail Postfix BeforeQeue filter
[Service]
ExecStart={execpath} {config_path}

View File

@@ -1,8 +1,7 @@
import pwd
from pathlib import Path
from threading import Thread
from queue import Queue
from threading import Thread, Event
from socketserver import (
UnixStreamServer,
StreamRequestHandler,
@@ -35,7 +34,7 @@ class Notifier:
self.notification_dir = vmail_dir / "pending_notifications"
if not self.notification_dir.exists():
self.notification_dir.mkdir()
self.notification_queue = Queue()
self.message_arrived_event = Event()
def get_metadata_dict(self, addr):
return FileDict(self.vmail_dir / addr / "metadata.json")
@@ -61,37 +60,31 @@ class Notifier:
def new_message_for_addr(self, addr):
self.notification_dir.joinpath(addr).touch()
self.notification_queue.put(addr)
self.message_arrived_event.set()
def thread_run_loop(self):
requests_session = requests.Session()
# on startup deliver all persisted notifications from last process run
self.notification_queue.put(None)
while 1:
self.message_arrived_event.wait()
self.message_arrived_event.clear()
self.thread_run_one(requests_session)
def thread_run_one(self, requests_session):
addr = self.notification_queue.get()
if addr is None:
# startup, notify any "pending" notifications from last run
for addr_path in self.notification_dir.iterdir():
if "@" in addr_path.name:
self.notify_tokens_for(requests_session, addr_path.name)
else:
self.notify_tokens_for(requests_session, addr)
def notify_tokens_for(self, requests_session, addr):
for token in self.get_tokens(addr):
response = requests_session.post(
"https://notifications.delta.chat/notify",
data=token,
timeout=60,
)
if response.status_code == 410:
# 410 Gone status code
# means the token is no longer valid.
self.remove_token(addr, token)
self.notification_dir.joinpath(addr).unlink(missing_ok=True)
for addr_path in self.notification_dir.iterdir():
addr = addr_path.name
if "@" not in addr:
continue
for token in self.get_tokens(addr):
response = requests_session.post(
"https://notifications.delta.chat/notify",
data=token,
timeout=60,
)
if response.status_code == 410:
# 410 Gone status code
# means the token is no longer valid.
self.remove_token(addr, token)
addr_path.unlink()
def handle_dovecot_protocol(rfile, wfile, notifier):

View File

@@ -84,7 +84,7 @@ def test_handle_dovecot_request_happy_path(notifier, testaddr):
assert handle_dovecot_request(f"B{tx2}\t{testaddr}", transactions, notifier) is None
msg = f"S{tx2}\tpriv/guid00/messagenew"
assert handle_dovecot_request(msg, transactions, notifier) is None
assert notifier.notification_queue.get() == testaddr
assert notifier.message_arrived_event.is_set()
assert handle_dovecot_request(f"C{tx2}", transactions, notifier) == "O\n"
assert not transactions
assert notifier.notification_dir.joinpath(testaddr).exists()
@@ -159,8 +159,8 @@ def test_handle_dovecot_protocol_messagenew(notifier):
wfile = io.BytesIO()
handle_dovecot_protocol(rfile, wfile, notifier)
assert wfile.getvalue() == b"O\n"
addr = notifier.notification_queue.get()
assert notifier.notification_dir.joinpath(addr).exists()
assert notifier.message_arrived_event.is_set()
assert notifier.notification_dir.joinpath("user@example.org").exists()
def test_notifier_thread_run(notifier, testaddr):

View File

@@ -110,9 +110,7 @@ def _install_remote_venv_with_chatmaild(config) -> None:
remote_venv_dir=remote_venv_dir,
mail_domain=config.mail_domain,
)
source_path = importlib.resources.files(__package__).joinpath(
"service", f"{fn}.service.f"
)
source_path = importlib.resources.files("chatmaild").joinpath(f"{fn}.service.f")
content = source_path.read_text().format(**params).encode()
files.put(
@@ -135,6 +133,20 @@ def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool:
"""Configures OpenDKIM"""
need_restart = False
server.group(name="Create opendkim group", group="opendkim", system=True)
server.user(
name="Create opendkim user",
user="opendkim",
groups=["opendkim"],
system=True,
)
server.user(
name="Add postfix user to opendkim group for socket access",
user="postfix",
groups=["opendkim"],
system=True,
)
main_config = files.template(
src=importlib.resources.files(__package__).joinpath("opendkim/opendkim.conf"),
dest="/etc/opendkim.conf",
@@ -462,24 +474,9 @@ def deploy_chatmail(config_path: Path) -> None:
from .www import build_webpages
apt.update(name="apt update", cache_time=24 * 3600)
server.group(name="Create vmail group", group="vmail", system=True)
server.user(name="Create vmail user", user="vmail", group="vmail", system=True)
server.group(name="Create opendkim group", group="opendkim", system=True)
server.user(
name="Create opendkim user",
user="opendkim",
groups=["opendkim"],
system=True,
)
server.user(
name="Add postfix user to opendkim group for socket access",
user="postfix",
groups=["opendkim"],
system=True,
)
apt.update(name="apt update", cache_time=24 * 3600)
apt.packages(
name="Install rsync",
packages=["rsync"],
@@ -566,17 +563,6 @@ def deploy_chatmail(config_path: Path) -> None:
restarted=mta_sts_need_restart,
)
# Dovecot should be started before Postfix
# because it creates authentication socket
# required by Postfix.
systemd.service(
name="Start and enable Dovecot",
service="dovecot.service",
running=True,
enabled=True,
restarted=dovecot_need_restart,
)
systemd.service(
name="Start and enable Postfix",
service="postfix.service",
@@ -585,6 +571,14 @@ def deploy_chatmail(config_path: Path) -> None:
restarted=postfix_need_restart,
)
systemd.service(
name="Start and enable Dovecot",
service="dovecot.service",
running=True,
enabled=True,
restarted=dovecot_need_restart,
)
systemd.service(
name="Start and enable nginx",
service="nginx.service",