mirror of
https://github.com/chatmail/relay.git
synced 2026-05-14 01:44:38 +00:00
Compare commits
5 Commits
j4n/docker
...
j4n/docker
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b50019aa2a | ||
|
|
7606612091 | ||
|
|
2b12ed1ca1 | ||
|
|
40051f7ac3 | ||
|
|
e45d2b99e4 |
18
.dockerignore
Normal file
18
.dockerignore
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
data/
|
||||||
|
venv/
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.orig
|
||||||
|
*.ini
|
||||||
|
.pytest_cache
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Slim build context — .git/ alone can be 100s of MB
|
||||||
|
.git
|
||||||
|
.github/
|
||||||
|
docs/
|
||||||
|
tests/
|
||||||
|
|
||||||
|
# Exclude markdown files but keep www/src/*.md (used by WebsiteDeployer)
|
||||||
|
*.md
|
||||||
|
!www/**/*.md
|
||||||
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
- name: download filtermail
|
- name: download filtermail
|
||||||
run: curl -L https://github.com/chatmail/filtermail/releases/download/v0.6.1/filtermail-x86_64 -o /usr/local/bin/filtermail && chmod +x /usr/local/bin/filtermail
|
run: curl -L https://github.com/chatmail/filtermail/releases/download/v0.6.0/filtermail-x86_64 -o /usr/local/bin/filtermail && chmod +x /usr/local/bin/filtermail
|
||||||
- name: run chatmaild tests
|
- name: run chatmaild tests
|
||||||
working-directory: chatmaild
|
working-directory: chatmaild
|
||||||
run: pipx run tox
|
run: pipx run tox
|
||||||
|
|||||||
125
.github/workflows/docker-deploy.yaml
vendored
125
.github/workflows/docker-deploy.yaml
vendored
@@ -1,125 +0,0 @@
|
|||||||
name: Docker deploy
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
staging_host:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
description: 'SSH hostname (e.g. staging2.testrun.org)'
|
|
||||||
mail_domain:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
description: 'MAIL_DOMAIN for docker compose'
|
|
||||||
zone_file:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
description: 'Default zone file basename (e.g. staging.testrun.org-default.zone)'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy-docker:
|
|
||||||
name: Docker deploy on ${{ inputs.staging_host }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 20
|
|
||||||
environment:
|
|
||||||
name: ${{ inputs.staging_host }}
|
|
||||||
url: https://${{ inputs.staging_host }}/
|
|
||||||
concurrency: ${{ inputs.staging_host }}
|
|
||||||
env:
|
|
||||||
VPS: root@${{ inputs.staging_host }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: Setup SSH
|
|
||||||
run: |
|
|
||||||
mkdir ~/.ssh
|
|
||||||
echo "${{ secrets.STAGING_SSH_KEY }}" >> ~/.ssh/id_ed25519
|
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
|
||||||
ssh-keyscan ${{ inputs.staging_host }} > ~/.ssh/known_hosts
|
|
||||||
# Reuse TCP connection for all subsequent ssh/scp calls
|
|
||||||
echo -e "Host ${{ inputs.staging_host }}\n ControlMaster auto\n ControlPath ~/.ssh/ctrl-%r@%h:%p\n ControlPersist 10m" >> ~/.ssh/config
|
|
||||||
|
|
||||||
- name: stop bare services, install Docker, prepare mounts
|
|
||||||
run: |
|
|
||||||
ssh $VPS bash -s <<'EOF'
|
|
||||||
systemctl stop postfix dovecot nginx opendkim unbound filtermail doveauth chatmail-metadata iroh-relay mtail fcgiwrap acmetool 2>/dev/null || true
|
|
||||||
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && chmod a+r /etc/apt/keyrings/docker.asc
|
|
||||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" > /etc/apt/sources.list.d/docker.list
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
||||||
mkdir -p /srv/chatmail/certs /srv/chatmail/dkim
|
|
||||||
cp -a /var/lib/acme/. /srv/chatmail/certs/ || true
|
|
||||||
cp -a /etc/dkimkeys/. /srv/chatmail/dkim/ || true
|
|
||||||
cp /etc/chatmail/chatmail.ini /srv/chatmail/chatmail.ini
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: deploy with Docker
|
|
||||||
run: |
|
|
||||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
|
||||||
GHCR_IMAGE="ghcr.io/chatmail/docker:sha-${SHORT_SHA}"
|
|
||||||
rsync -avz --exclude='.git' --exclude='venv' --exclude='__pycache__' ./ $VPS:/srv/chatmail/relay/
|
|
||||||
echo "${{ secrets.GITHUB_TOKEN }}" | ssh $VPS "docker login ghcr.io -u ${{ github.actor }} --password-stdin && \
|
|
||||||
docker pull ${GHCR_IMAGE} && \
|
|
||||||
cd /srv/chatmail/relay && CHATMAIL_IMAGE=${GHCR_IMAGE} MAIL_DOMAIN=${{ inputs.mail_domain }} docker compose -f docker/docker-compose.yaml -f docker/docker-compose.ci.yaml up -d"
|
|
||||||
|
|
||||||
- name: wait for container healthy
|
|
||||||
run: |
|
|
||||||
ssh $VPS 'docker exec chatmail journalctl -f --no-pager' &
|
|
||||||
LOG_PID=$!
|
|
||||||
trap "kill $LOG_PID 2>/dev/null || true" EXIT
|
|
||||||
for i in $(seq 1 60); do
|
|
||||||
status=$(ssh $VPS 'docker inspect --format={{.State.Health.Status}} chatmail 2>/dev/null' || echo "missing")
|
|
||||||
echo " [$i/60] status=$status"
|
|
||||||
if [ "$status" = "healthy" ]; then
|
|
||||||
echo "Container is healthy."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
if [ "$status" = "unhealthy" ]; then
|
|
||||||
echo "Container is unhealthy!"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
sleep 5
|
|
||||||
done
|
|
||||||
echo "Container did not become healthy."
|
|
||||||
kill $LOG_PID 2>/dev/null || true
|
|
||||||
ssh $VPS bash -s <<'EOF'
|
|
||||||
echo "--- failed units ---"
|
|
||||||
docker exec chatmail systemctl --failed --no-pager || true
|
|
||||||
echo "--- service logs ---"
|
|
||||||
docker exec chatmail journalctl -u dovecot -u postfix -u nginx -u unbound --no-pager -n 50 || true
|
|
||||||
echo "--- listening ports ---"
|
|
||||||
docker exec chatmail ss -tlnp || true
|
|
||||||
echo "--- chatmail.ini ---"
|
|
||||||
docker exec chatmail cat /etc/chatmail/chatmail.ini || true
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: show container state
|
|
||||||
run: |
|
|
||||||
ssh $VPS bash -s <<'EOF'
|
|
||||||
echo "--- listening ports ---"
|
|
||||||
docker exec chatmail ss -tlnp
|
|
||||||
echo "--- chatmail.ini ---"
|
|
||||||
docker exec chatmail cat /etc/chatmail/chatmail.ini
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Docker integration tests
|
|
||||||
run: ssh $VPS 'docker exec chatmail cmdeploy test --slow --ssh-host @local'
|
|
||||||
|
|
||||||
- name: Docker DNS
|
|
||||||
run: |
|
|
||||||
git checkout .github/workflows/${{ inputs.zone_file }}
|
|
||||||
ssh $VPS bash -s <<'EOF'
|
|
||||||
docker exec chatmail chown opendkim:opendkim -R /etc/dkimkeys
|
|
||||||
docker exec chatmail cmdeploy dns --ssh-host @local --zonefile /opt/chatmail/staging.zone --verbose
|
|
||||||
docker cp chatmail:/opt/chatmail/staging.zone /tmp/staging.zone
|
|
||||||
EOF
|
|
||||||
scp $VPS:/tmp/staging.zone staging-generated.zone
|
|
||||||
cat staging-generated.zone >> .github/workflows/${{ inputs.zone_file }}
|
|
||||||
cat .github/workflows/${{ inputs.zone_file }}
|
|
||||||
scp .github/workflows/${{ inputs.zone_file }} root@ns.testrun.org:/etc/nsd/${{ inputs.staging_host }}.zone
|
|
||||||
ssh root@ns.testrun.org "nsd-checkzone ${{ inputs.staging_host }} /etc/nsd/${{ inputs.staging_host }}.zone && systemctl reload nsd"
|
|
||||||
|
|
||||||
- name: Docker final DNS check
|
|
||||||
run: ssh $VPS 'docker exec chatmail cmdeploy dns -v --ssh-host @local'
|
|
||||||
207
.github/workflows/test-and-deploy-ipv4only.yaml
vendored
207
.github/workflows/test-and-deploy-ipv4only.yaml
vendored
@@ -12,11 +12,66 @@ on:
|
|||||||
- 'CHANGELOG.md'
|
- 'CHANGELOG.md'
|
||||||
- 'LICENSE'
|
- 'LICENSE'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
trigger-docker-build:
|
build-docker:
|
||||||
if: github.event_name == 'push'
|
name: Build Docker image
|
||||||
uses: ./.github/workflows/trigger-docker-build.yaml
|
runs-on: ubuntu-latest
|
||||||
secrets: inherit
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
outputs:
|
||||||
|
image: ${{ steps.image-ref.outputs.image }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to GHCR
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels)
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
# Tagged releases: v1.2.3 -> :1.2.3, :1.2, :latest
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
# Branch pushes: foo/docker-pr -> :foo-docker-pr
|
||||||
|
type=ref,event=branch
|
||||||
|
# Always: :sha-<hash>
|
||||||
|
type=sha
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: docker/chatmail_relay.dockerfile
|
||||||
|
push: ${{ github.event_name == 'push' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
build-args: |
|
||||||
|
GIT_HASH=${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Output image reference
|
||||||
|
id: image-ref
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
|
IMAGE="${{ env.REGISTRY }}/$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]'):sha-${SHORT_SHA}"
|
||||||
|
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: deploy on staging-ipv4.testrun.org, and run tests
|
name: deploy on staging-ipv4.testrun.org, and run tests
|
||||||
@@ -28,8 +83,6 @@ jobs:
|
|||||||
concurrency: staging-ipv4.testrun.org
|
concurrency: staging-ipv4.testrun.org
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
|
|
||||||
- name: prepare SSH
|
- name: prepare SSH
|
||||||
run: |
|
run: |
|
||||||
@@ -63,6 +116,7 @@ jobs:
|
|||||||
run: echo venv/bin >>$GITHUB_PATH
|
run: echo venv/bin >>$GITHUB_PATH
|
||||||
|
|
||||||
- name: upload TLS cert after rebuilding
|
- name: upload TLS cert after rebuilding
|
||||||
|
id: wait-for-vps
|
||||||
run: |
|
run: |
|
||||||
echo " --- wait until staging-ipv4.testrun.org VPS is rebuilt --- "
|
echo " --- wait until staging-ipv4.testrun.org VPS is rebuilt --- "
|
||||||
rm ~/.ssh/known_hosts
|
rm ~/.ssh/known_hosts
|
||||||
@@ -71,7 +125,7 @@ jobs:
|
|||||||
# download acme & dkim state from ns.testrun.org
|
# download acme & dkim state from ns.testrun.org
|
||||||
rsync -e "ssh -o StrictHostKeyChecking=accept-new" -avz root@ns.testrun.org:/tmp/acme-ipv4/acme acme-restore || true
|
rsync -e "ssh -o StrictHostKeyChecking=accept-new" -avz root@ns.testrun.org:/tmp/acme-ipv4/acme acme-restore || true
|
||||||
rsync -avz root@ns.testrun.org:/tmp/dkimkeys-ipv4/dkimkeys dkimkeys-restore || true
|
rsync -avz root@ns.testrun.org:/tmp/dkimkeys-ipv4/dkimkeys dkimkeys-restore || true
|
||||||
# restore acme & dkim state to staging-ipv4.testrun.org
|
# restore acme & dkim state to staging2.testrun.org
|
||||||
rsync -avz acme-restore/acme root@staging-ipv4.testrun.org:/var/lib/ || true
|
rsync -avz acme-restore/acme root@staging-ipv4.testrun.org:/var/lib/ || true
|
||||||
rsync -avz dkimkeys-restore/dkimkeys root@staging-ipv4.testrun.org:/etc/ || true
|
rsync -avz dkimkeys-restore/dkimkeys root@staging-ipv4.testrun.org:/etc/ || true
|
||||||
ssh -o StrictHostKeyChecking=accept-new -v root@staging-ipv4.testrun.org chown root:root -R /var/lib/acme || true
|
ssh -o StrictHostKeyChecking=accept-new -v root@staging-ipv4.testrun.org chown root:root -R /var/lib/acme || true
|
||||||
@@ -110,12 +164,133 @@ jobs:
|
|||||||
- name: cmdeploy dns
|
- name: cmdeploy dns
|
||||||
run: ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy dns -v --ssh-host localhost"
|
run: ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy dns -v --ssh-host localhost"
|
||||||
|
|
||||||
deploy-docker:
|
# --- Docker deploy (push only, runs even if bare failed) ---
|
||||||
needs: [deploy, trigger-docker-build]
|
|
||||||
if: github.event_name == 'push'
|
- name: stop bare services
|
||||||
uses: ./.github/workflows/docker-deploy.yaml
|
if: >-
|
||||||
with:
|
!cancelled() && github.event_name == 'push'
|
||||||
staging_host: staging-ipv4.testrun.org
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
mail_domain: staging-ipv4.testrun.org
|
run: |
|
||||||
zone_file: staging-ipv4.testrun.org-default.zone
|
ssh root@staging-ipv4.testrun.org 'systemctl stop postfix dovecot nginx opendkim unbound filtermail doveauth chatmail-metadata iroh-relay mtail fcgiwrap acmetool 2>/dev/null || true'
|
||||||
secrets: inherit
|
|
||||||
|
- name: install Docker on VPS
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging-ipv4.testrun.org 'apt-get update && apt-get install -y ca-certificates curl'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'install -m 0755 -d /etc/apt/keyrings'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && chmod a+r /etc/apt/keyrings/docker.asc'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" > /etc/apt/sources.list.d/docker.list'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin'
|
||||||
|
|
||||||
|
- name: prepare Docker bind mounts
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging-ipv4.testrun.org 'mkdir -p /srv/chatmail/certs /srv/chatmail/dkim'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'cp -a /var/lib/acme/. /srv/chatmail/certs/ && cp -a /etc/dkimkeys/. /srv/chatmail/dkim/' || true
|
||||||
|
|
||||||
|
- name: upload chatmail.ini for Docker
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Reuse chatmail.ini already created by the bare-metal deploy steps
|
||||||
|
ssh root@staging-ipv4.testrun.org "cp relay/chatmail.ini /srv/chatmail/chatmail.ini"
|
||||||
|
|
||||||
|
- name: deploy with Docker
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
|
GHCR_IMAGE="${{ env.REGISTRY }}/$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]'):sha-${SHORT_SHA}"
|
||||||
|
rsync -avz --exclude='.git' --exclude='venv' --exclude='__pycache__' ./ root@staging-ipv4.testrun.org:/srv/chatmail/relay/
|
||||||
|
# Login to GHCR on VPS and pull pre-built image
|
||||||
|
echo "${{ secrets.GITHUB_TOKEN }}" | ssh root@staging-ipv4.testrun.org 'docker login ghcr.io -u ${{ github.actor }} --password-stdin'
|
||||||
|
ssh root@staging-ipv4.testrun.org "docker pull ${GHCR_IMAGE}"
|
||||||
|
ssh root@staging-ipv4.testrun.org "cd /srv/chatmail/relay && CHATMAIL_IMAGE=${GHCR_IMAGE} MAIL_DOMAIN=staging-ipv4.testrun.org docker compose -f docker/docker-compose.yaml -f docker/docker-compose.ci.yaml up -d"
|
||||||
|
|
||||||
|
- name: wait for container healthy
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Stream journald inside the container
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail journalctl -f --no-pager' &
|
||||||
|
LOG_PID=$!
|
||||||
|
trap "kill $LOG_PID 2>/dev/null || true" EXIT
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
status=$(ssh root@staging-ipv4.testrun.org 'docker inspect --format={{.State.Health.Status}} chatmail 2>/dev/null' || echo "missing")
|
||||||
|
echo " [$i/60] status=$status"
|
||||||
|
if [ "$status" = "healthy" ]; then
|
||||||
|
echo "Container is healthy."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$status" = "unhealthy" ]; then
|
||||||
|
echo "Container is unhealthy!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
echo "Container did not become healthy."
|
||||||
|
kill $LOG_PID 2>/dev/null || true
|
||||||
|
echo "--- failed units ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail systemctl --failed --no-pager' || true
|
||||||
|
echo "--- service logs ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail journalctl -u dovecot -u postfix -u nginx -u unbound --no-pager -n 50' || true
|
||||||
|
echo "--- listening ports ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail ss -tlnp' || true
|
||||||
|
echo "--- chatmail.ini ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail cat /etc/chatmail/chatmail.ini' || true
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: show container state
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
echo "--- listening ports ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail ss -tlnp'
|
||||||
|
echo "--- chatmail.ini ---"
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail cat /etc/chatmail/chatmail.ini'
|
||||||
|
|
||||||
|
- name: Docker integration tests
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail cmdeploy test --slow --ssh-host @local'
|
||||||
|
|
||||||
|
- name: Docker DNS
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Reset zone file in case bare DNS already appended to it
|
||||||
|
git checkout .github/workflows/staging-ipv4.testrun.org-default.zone
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail chown opendkim:opendkim -R /etc/dkimkeys'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker exec chatmail cmdeploy dns --ssh-host @local --zonefile /opt/chatmail/staging.zone --verbose'
|
||||||
|
ssh root@staging-ipv4.testrun.org 'docker cp chatmail:/opt/chatmail/staging.zone /tmp/staging.zone'
|
||||||
|
scp root@staging-ipv4.testrun.org:/tmp/staging.zone staging-generated.zone
|
||||||
|
cat staging-generated.zone >> .github/workflows/staging-ipv4.testrun.org-default.zone
|
||||||
|
cat .github/workflows/staging-ipv4.testrun.org-default.zone
|
||||||
|
scp .github/workflows/staging-ipv4.testrun.org-default.zone root@ns.testrun.org:/etc/nsd/staging-ipv4.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org nsd-checkzone staging-ipv4.testrun.org /etc/nsd/staging-ipv4.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org systemctl reload nsd
|
||||||
|
|
||||||
|
- name: Docker final DNS check
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: ssh root@staging-ipv4.testrun.org 'docker exec chatmail cmdeploy dns -v --ssh-host @local'
|
||||||
|
|
||||||
|
# --- Cleanup ---
|
||||||
|
|
||||||
|
- name: add SSH keys
|
||||||
|
if: >-
|
||||||
|
!cancelled()
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: ssh root@staging-ipv4.testrun.org 'curl -s https://github.com/hpk42.keys https://github.com/j4n.keys >> .ssh/authorized_keys'
|
||||||
|
|||||||
207
.github/workflows/test-and-deploy.yaml
vendored
207
.github/workflows/test-and-deploy.yaml
vendored
@@ -12,11 +12,66 @@ on:
|
|||||||
- 'CHANGELOG.md'
|
- 'CHANGELOG.md'
|
||||||
- 'LICENSE'
|
- 'LICENSE'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
trigger-docker-build:
|
build-docker:
|
||||||
if: github.event_name == 'push'
|
name: Build Docker image
|
||||||
uses: ./.github/workflows/trigger-docker-build.yaml
|
runs-on: ubuntu-latest
|
||||||
secrets: inherit
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
outputs:
|
||||||
|
image: ${{ steps.image-ref.outputs.image }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to GHCR
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels)
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
# Tagged releases: v1.2.3 -> :1.2.3, :1.2, :latest
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
# Branch pushes: foo/docker-pr -> :foo-docker-pr
|
||||||
|
type=ref,event=branch
|
||||||
|
# Always: :sha-<hash>
|
||||||
|
type=sha
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: docker/chatmail_relay.dockerfile
|
||||||
|
push: ${{ github.event_name == 'push' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
build-args: |
|
||||||
|
GIT_HASH=${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Output image reference
|
||||||
|
id: image-ref
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
|
IMAGE="${{ env.REGISTRY }}/$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]'):sha-${SHORT_SHA}"
|
||||||
|
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: deploy on staging2.testrun.org, and run tests
|
name: deploy on staging2.testrun.org, and run tests
|
||||||
@@ -61,6 +116,7 @@ jobs:
|
|||||||
run: echo venv/bin >>$GITHUB_PATH
|
run: echo venv/bin >>$GITHUB_PATH
|
||||||
|
|
||||||
- name: upload TLS cert after rebuilding
|
- name: upload TLS cert after rebuilding
|
||||||
|
id: wait-for-vps
|
||||||
run: |
|
run: |
|
||||||
echo " --- wait until staging2.testrun.org VPS is rebuilt --- "
|
echo " --- wait until staging2.testrun.org VPS is rebuilt --- "
|
||||||
rm ~/.ssh/known_hosts
|
rm ~/.ssh/known_hosts
|
||||||
@@ -77,8 +133,8 @@ jobs:
|
|||||||
- name: add hpk42 key to staging server
|
- name: add hpk42 key to staging server
|
||||||
run: ssh root@staging2.testrun.org 'curl -s https://github.com/hpk42.keys >> .ssh/authorized_keys'
|
run: ssh root@staging2.testrun.org 'curl -s https://github.com/hpk42.keys >> .ssh/authorized_keys'
|
||||||
|
|
||||||
- name: run deploy-chatmail offline tests
|
- name: run deploy-chatmail offline tests
|
||||||
run: pytest --pyargs cmdeploy
|
run: pytest --pyargs cmdeploy
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
cmdeploy init staging2.testrun.org
|
cmdeploy init staging2.testrun.org
|
||||||
@@ -101,12 +157,133 @@ jobs:
|
|||||||
- name: cmdeploy dns
|
- name: cmdeploy dns
|
||||||
run: cmdeploy dns -v
|
run: cmdeploy dns -v
|
||||||
|
|
||||||
deploy-docker:
|
# --- Docker deploy (push only, runs even if bare failed) ---
|
||||||
needs: [deploy, trigger-docker-build]
|
|
||||||
if: github.event_name == 'push'
|
- name: stop bare services
|
||||||
uses: ./.github/workflows/docker-deploy.yaml
|
if: >-
|
||||||
with:
|
!cancelled() && github.event_name == 'push'
|
||||||
staging_host: staging2.testrun.org
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
mail_domain: staging2.testrun.org
|
run: |
|
||||||
zone_file: staging.testrun.org-default.zone
|
ssh root@staging2.testrun.org 'systemctl stop postfix dovecot nginx opendkim unbound filtermail doveauth chatmail-metadata iroh-relay mtail fcgiwrap acmetool 2>/dev/null || true'
|
||||||
secrets: inherit
|
|
||||||
|
- name: install Docker on VPS
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging2.testrun.org 'apt-get update && apt-get install -y ca-certificates curl'
|
||||||
|
ssh root@staging2.testrun.org 'install -m 0755 -d /etc/apt/keyrings'
|
||||||
|
ssh root@staging2.testrun.org 'curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && chmod a+r /etc/apt/keyrings/docker.asc'
|
||||||
|
ssh root@staging2.testrun.org 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" > /etc/apt/sources.list.d/docker.list'
|
||||||
|
ssh root@staging2.testrun.org 'apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin'
|
||||||
|
|
||||||
|
- name: prepare Docker bind mounts
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging2.testrun.org 'mkdir -p /srv/chatmail/certs /srv/chatmail/dkim'
|
||||||
|
ssh root@staging2.testrun.org 'cp -a /var/lib/acme/. /srv/chatmail/certs/ && cp -a /etc/dkimkeys/. /srv/chatmail/dkim/' || true
|
||||||
|
|
||||||
|
- name: upload chatmail.ini for Docker
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Reuse chatmail.ini already created by the bare-metal deploy steps
|
||||||
|
scp chatmail.ini root@staging2.testrun.org:/srv/chatmail/chatmail.ini
|
||||||
|
|
||||||
|
- name: deploy with Docker
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
|
GHCR_IMAGE="${{ env.REGISTRY }}/$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]'):sha-${SHORT_SHA}"
|
||||||
|
rsync -avz --exclude='.git' --exclude='venv' --exclude='__pycache__' ./ root@staging2.testrun.org:/srv/chatmail/relay/
|
||||||
|
# Login to GHCR on VPS and pull pre-built image
|
||||||
|
echo "${{ secrets.GITHUB_TOKEN }}" | ssh root@staging2.testrun.org 'docker login ghcr.io -u ${{ github.actor }} --password-stdin'
|
||||||
|
ssh root@staging2.testrun.org "docker pull ${GHCR_IMAGE}"
|
||||||
|
ssh root@staging2.testrun.org "cd /srv/chatmail/relay && CHATMAIL_IMAGE=${GHCR_IMAGE} MAIL_DOMAIN=staging2.testrun.org docker compose -f docker/docker-compose.yaml -f docker/docker-compose.ci.yaml up -d"
|
||||||
|
|
||||||
|
- name: wait for container healthy
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Stream journald inside the container
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail journalctl -f --no-pager' &
|
||||||
|
LOG_PID=$!
|
||||||
|
trap "kill $LOG_PID 2>/dev/null || true" EXIT
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
status=$(ssh root@staging2.testrun.org 'docker inspect --format={{.State.Health.Status}} chatmail 2>/dev/null' || echo "missing")
|
||||||
|
echo " [$i/60] status=$status"
|
||||||
|
if [ "$status" = "healthy" ]; then
|
||||||
|
echo "Container is healthy."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$status" = "unhealthy" ]; then
|
||||||
|
echo "Container is unhealthy!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
echo "Container did not become healthy."
|
||||||
|
kill $LOG_PID 2>/dev/null || true
|
||||||
|
echo "--- failed units ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail systemctl --failed --no-pager' || true
|
||||||
|
echo "--- service logs ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail journalctl -u dovecot -u postfix -u nginx -u unbound --no-pager -n 50' || true
|
||||||
|
echo "--- listening ports ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail ss -tlnp' || true
|
||||||
|
echo "--- chatmail.ini ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail cat /etc/chatmail/chatmail.ini' || true
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: show container state
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
echo "--- listening ports ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail ss -tlnp'
|
||||||
|
echo "--- chatmail.ini ---"
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail cat /etc/chatmail/chatmail.ini'
|
||||||
|
|
||||||
|
- name: Docker integration tests
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail cmdeploy test --slow --ssh-host @local'
|
||||||
|
|
||||||
|
- name: Docker DNS
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: |
|
||||||
|
# Reset zone file in case bare DNS already appended to it
|
||||||
|
git checkout .github/workflows/staging.testrun.org-default.zone
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail chown opendkim:opendkim -R /etc/dkimkeys'
|
||||||
|
ssh root@staging2.testrun.org 'docker exec chatmail cmdeploy dns --ssh-host @local --zonefile /opt/chatmail/staging.zone --verbose'
|
||||||
|
ssh root@staging2.testrun.org 'docker cp chatmail:/opt/chatmail/staging.zone /tmp/staging.zone'
|
||||||
|
scp root@staging2.testrun.org:/tmp/staging.zone staging-generated.zone
|
||||||
|
cat staging-generated.zone >> .github/workflows/staging.testrun.org-default.zone
|
||||||
|
cat .github/workflows/staging.testrun.org-default.zone
|
||||||
|
scp .github/workflows/staging.testrun.org-default.zone root@ns.testrun.org:/etc/nsd/staging2.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org nsd-checkzone staging2.testrun.org /etc/nsd/staging2.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org systemctl reload nsd
|
||||||
|
|
||||||
|
- name: Docker final DNS check
|
||||||
|
if: >-
|
||||||
|
!cancelled() && github.event_name == 'push'
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: ssh root@staging2.testrun.org 'docker exec chatmail cmdeploy dns -v --ssh-host @local'
|
||||||
|
|
||||||
|
# --- Cleanup ---
|
||||||
|
|
||||||
|
- name: add SSH keys
|
||||||
|
if: >-
|
||||||
|
!cancelled()
|
||||||
|
&& steps.wait-for-vps.outcome == 'success'
|
||||||
|
run: ssh root@staging2.testrun.org 'curl -s https://github.com/hpk42.keys https://github.com/j4n.keys >> .ssh/authorized_keys'
|
||||||
|
|||||||
24
.github/workflows/trigger-docker-build.yaml
vendored
24
.github/workflows/trigger-docker-build.yaml
vendored
@@ -1,24 +0,0 @@
|
|||||||
name: Trigger Docker image build
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
trigger-docker-build:
|
|
||||||
name: Trigger Docker image build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/github-script@v7
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.CHATMAIL_DOCKER_DISPATCH_TOKEN }}
|
|
||||||
script: |
|
|
||||||
await github.rest.repos.createDispatchEvent({
|
|
||||||
owner: 'chatmail',
|
|
||||||
repo: 'docker',
|
|
||||||
event_type: 'relay-updated',
|
|
||||||
client_payload: {
|
|
||||||
relay_ref: context.ref,
|
|
||||||
relay_sha: context.sha,
|
|
||||||
relay_sha_short: context.sha.slice(0, 7)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -164,3 +164,9 @@ cython_debug/
|
|||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
chatmail.zone
|
chatmail.zone
|
||||||
|
|
||||||
|
# docker
|
||||||
|
/data/
|
||||||
|
/custom/
|
||||||
|
docker/docker-compose.override.yaml
|
||||||
|
docker/.env
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ build-backend = "setuptools.build_meta"
|
|||||||
name = "chatmaild"
|
name = "chatmaild"
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aiosmtpd",
|
||||||
"iniconfig",
|
"iniconfig",
|
||||||
|
"deltachat-rpc-server",
|
||||||
|
"deltachat-rpc-client",
|
||||||
"filelock",
|
"filelock",
|
||||||
"requests",
|
"requests",
|
||||||
"crypt-r >= 3.13.1 ; python_version >= '3.11'",
|
"crypt-r >= 3.13.1 ; python_version >= '3.11'",
|
||||||
@@ -67,7 +70,6 @@ commands =
|
|||||||
deps = pytest
|
deps = pytest
|
||||||
pdbpp
|
pdbpp
|
||||||
pytest-localserver
|
pytest-localserver
|
||||||
aiosmtpd
|
|
||||||
execnet
|
execnet
|
||||||
commands = pytest -v -rsXx {posargs}
|
commands = pytest -v -rsXx {posargs}
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Config:
|
|||||||
self.filtermail_smtp_port_incoming = int(
|
self.filtermail_smtp_port_incoming = int(
|
||||||
params.get("filtermail_smtp_port_incoming", "10081")
|
params.get("filtermail_smtp_port_incoming", "10081")
|
||||||
)
|
)
|
||||||
self.filtermail_http_port = int(params.get("filtermail_http_port", "10082"))
|
|
||||||
self.postfix_reinject_port = int(params.get("postfix_reinject_port", "10025"))
|
self.postfix_reinject_port = int(params.get("postfix_reinject_port", "10025"))
|
||||||
self.postfix_reinject_port_incoming = int(
|
self.postfix_reinject_port_incoming = int(
|
||||||
params.get("postfix_reinject_port_incoming", "10026")
|
params.get("postfix_reinject_port_incoming", "10026")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ dependencies = [
|
|||||||
"pillow",
|
"pillow",
|
||||||
"qrcode",
|
"qrcode",
|
||||||
"markdown",
|
"markdown",
|
||||||
|
"pytest",
|
||||||
"setuptools>=68",
|
"setuptools>=68",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
"build",
|
"build",
|
||||||
@@ -20,7 +21,6 @@ dependencies = [
|
|||||||
"execnet",
|
"execnet",
|
||||||
"imap_tools",
|
"imap_tools",
|
||||||
"deltachat-rpc-client",
|
"deltachat-rpc-client",
|
||||||
"deltachat-rpc-server",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import io
|
|||||||
import os
|
import os
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from pyinfra import host
|
|
||||||
from pyinfra.facts.server import Command
|
|
||||||
from pyinfra.operations import files, server, systemd
|
from pyinfra.operations import files, server, systemd
|
||||||
|
|
||||||
|
|
||||||
@@ -13,17 +11,6 @@ def has_systemd():
|
|||||||
return os.path.isdir("/run/systemd/system")
|
return os.path.isdir("/run/systemd/system")
|
||||||
|
|
||||||
|
|
||||||
def is_in_container() -> bool:
|
|
||||||
"""Return True if running inside a container (Docker, LXC, etc.)."""
|
|
||||||
return (
|
|
||||||
host.get_fact(
|
|
||||||
Command,
|
|
||||||
"systemd-detect-virt --container --quiet 2>/dev/null && echo yes || true",
|
|
||||||
)
|
|
||||||
== "yes"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def blocked_service_startup():
|
def blocked_service_startup():
|
||||||
"""Prevent services from auto-starting during package installation.
|
"""Prevent services from auto-starting during package installation.
|
||||||
|
|||||||
32
cmdeploy/src/cmdeploy/chatmail.zone.j2
Normal file
32
cmdeploy/src/cmdeploy/chatmail.zone.j2
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
;
|
||||||
|
; Required DNS entries for chatmail servers
|
||||||
|
;
|
||||||
|
{% if A %}
|
||||||
|
{{ mail_domain }}. A {{ A }}
|
||||||
|
{% endif %}
|
||||||
|
{% if AAAA %}
|
||||||
|
{{ mail_domain }}. AAAA {{ AAAA }}
|
||||||
|
{% endif %}
|
||||||
|
{{ mail_domain }}. MX 10 {{ mail_domain }}.
|
||||||
|
{% if strict_tls %}
|
||||||
|
_mta-sts.{{ mail_domain }}. TXT "v=STSv1; id={{ sts_id }}"
|
||||||
|
mta-sts.{{ mail_domain }}. CNAME {{ mail_domain }}.
|
||||||
|
{% endif %}
|
||||||
|
www.{{ mail_domain }}. CNAME {{ mail_domain }}.
|
||||||
|
{{ dkim_entry }}
|
||||||
|
|
||||||
|
;
|
||||||
|
; Recommended DNS entries for interoperability and security-hardening
|
||||||
|
;
|
||||||
|
{{ mail_domain }}. TXT "v=spf1 a ~all"
|
||||||
|
_dmarc.{{ mail_domain }}. TXT "v=DMARC1;p=reject;adkim=s;aspf=s"
|
||||||
|
|
||||||
|
{% if acme_account_url %}
|
||||||
|
{{ mail_domain }}. CAA 0 issue "letsencrypt.org;accounturi={{ acme_account_url }}"
|
||||||
|
{% endif %}
|
||||||
|
_adsp._domainkey.{{ mail_domain }}. TXT "dkim=discardable"
|
||||||
|
|
||||||
|
_submission._tcp.{{ mail_domain }}. SRV 0 1 587 {{ mail_domain }}.
|
||||||
|
_submissions._tcp.{{ mail_domain }}. SRV 0 1 465 {{ mail_domain }}.
|
||||||
|
_imap._tcp.{{ mail_domain }}. SRV 0 1 143 {{ mail_domain }}.
|
||||||
|
_imaps._tcp.{{ mail_domain }}. SRV 0 1 993 {{ mail_domain }}.
|
||||||
@@ -207,7 +207,6 @@ def test_cmd(args, out):
|
|||||||
"""Run local and online tests for chatmail deployment."""
|
"""Run local and online tests for chatmail deployment."""
|
||||||
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["CHATMAIL_INI"] = str(args.inipath.absolute())
|
|
||||||
if args.ssh_host:
|
if args.ssh_host:
|
||||||
env["CHATMAIL_SSH"] = args.ssh_host
|
env["CHATMAIL_SSH"] = args.ssh_host
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from pyinfra import facts, host, logger
|
|||||||
from pyinfra.api import FactBase
|
from pyinfra.api import FactBase
|
||||||
from pyinfra.facts import hardware
|
from pyinfra.facts import hardware
|
||||||
from pyinfra.facts.files import Sha256File
|
from pyinfra.facts.files import Sha256File
|
||||||
|
from pyinfra.facts.server import Command
|
||||||
from pyinfra.facts.systemd import SystemdEnabled
|
from pyinfra.facts.systemd import SystemdEnabled
|
||||||
from pyinfra.operations import apt, files, pip, server, systemd
|
from pyinfra.operations import apt, files, pip, server, systemd
|
||||||
|
|
||||||
@@ -23,11 +24,9 @@ from .basedeploy import (
|
|||||||
Deployer,
|
Deployer,
|
||||||
Deployment,
|
Deployment,
|
||||||
activate_remote_units,
|
activate_remote_units,
|
||||||
blocked_service_startup,
|
|
||||||
configure_remote_units,
|
configure_remote_units,
|
||||||
get_resource,
|
get_resource,
|
||||||
has_systemd,
|
has_systemd,
|
||||||
is_in_container,
|
|
||||||
)
|
)
|
||||||
from .dovecot.deployer import DovecotDeployer
|
from .dovecot.deployer import DovecotDeployer
|
||||||
from .external.deployer import ExternalTlsDeployer
|
from .external.deployer import ExternalTlsDeployer
|
||||||
@@ -150,16 +149,33 @@ class UnboundDeployer(Deployer):
|
|||||||
self.need_restart = False
|
self.need_restart = False
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
# Run local DNS resolver `unbound`. `resolvconf` takes care of
|
# Run local DNS resolver `unbound`.
|
||||||
# setting up /etc/resolv.conf to use 127.0.0.1 as the resolver.
|
# `resolvconf` takes care of setting up /etc/resolv.conf
|
||||||
|
# to use 127.0.0.1 as the resolver.
|
||||||
|
|
||||||
# On an IPv4-only system, if unbound is started but not configured,
|
#
|
||||||
# it causes subsequent steps to fail to resolve hosts.
|
# On an IPv4-only system, if unbound is started but not
|
||||||
with blocked_service_startup():
|
# configured, it causes subsequent steps to fail to resolve hosts.
|
||||||
apt.packages(
|
# Here, we use policy-rc.d to prevent unbound from starting up
|
||||||
name="Install unbound",
|
# on initial install. Later, we will configure it and start it.
|
||||||
packages=["unbound", "unbound-anchor", "dnsutils"],
|
#
|
||||||
)
|
# For documentation about policy-rc.d, see:
|
||||||
|
# https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
|
||||||
|
#
|
||||||
|
files.put(
|
||||||
|
src=get_resource("policy-rc.d"),
|
||||||
|
dest="/usr/sbin/policy-rc.d",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="755",
|
||||||
|
)
|
||||||
|
|
||||||
|
apt.packages(
|
||||||
|
name="Install unbound",
|
||||||
|
packages=["unbound", "unbound-anchor", "dnsutils"],
|
||||||
|
)
|
||||||
|
|
||||||
|
files.file("/usr/sbin/policy-rc.d", present=False)
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
server.shell(
|
server.shell(
|
||||||
@@ -320,12 +336,12 @@ class TurnDeployer(Deployer):
|
|||||||
def install(self):
|
def install(self):
|
||||||
(url, sha256sum) = {
|
(url, sha256sum) = {
|
||||||
"x86_64": (
|
"x86_64": (
|
||||||
"https://github.com/chatmail/chatmail-turn/releases/download/v0.4/chatmail-turn-x86_64-linux",
|
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-x86_64-linux",
|
||||||
"1ec1f5c50122165e858a5a91bcba9037a28aa8cb8b64b8db570aa457c6141a8a",
|
"841e527c15fdc2940b0469e206188ea8f0af48533be12ecb8098520f813d41e4",
|
||||||
),
|
),
|
||||||
"aarch64": (
|
"aarch64": (
|
||||||
"https://github.com/chatmail/chatmail-turn/releases/download/v0.4/chatmail-turn-aarch64-linux",
|
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-aarch64-linux",
|
||||||
"0fb3e792419494e21ecad536464929dba706bb2c88884ed8f1788141d26fc756",
|
"a5fc2d06d937b56a34e098d2cd72a82d3e89967518d159bf246dc69b65e81b42",
|
||||||
),
|
),
|
||||||
}[host.get_fact(facts.server.Arch)]
|
}[host.get_fact(facts.server.Arch)]
|
||||||
|
|
||||||
@@ -458,9 +474,8 @@ class ChatmailDeployer(Deployer):
|
|||||||
("iroh", None, None),
|
("iroh", None, None),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, mail_domain):
|
||||||
self.config = config
|
self.mail_domain = mail_domain
|
||||||
self.mail_domain = config.mail_domain
|
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
files.put(
|
files.put(
|
||||||
@@ -483,18 +498,12 @@ class ChatmailDeployer(Deployer):
|
|||||||
name="Install rsync",
|
name="Install rsync",
|
||||||
packages=["rsync"],
|
packages=["rsync"],
|
||||||
)
|
)
|
||||||
|
apt.packages(
|
||||||
def configure(self):
|
name="Ensure cron is installed",
|
||||||
# metadata crashes if the mailboxes dir does not exist
|
packages=["cron"],
|
||||||
files.directory(
|
|
||||||
name="Ensure vmail mailbox directory exists",
|
|
||||||
path=str(self.config.mailboxes_dir),
|
|
||||||
user="vmail",
|
|
||||||
group="vmail",
|
|
||||||
mode="700",
|
|
||||||
present=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
# This file is used by auth proxy.
|
# This file is used by auth proxy.
|
||||||
# https://wiki.debian.org/EtcMailName
|
# https://wiki.debian.org/EtcMailName
|
||||||
server.shell(
|
server.shell(
|
||||||
@@ -584,7 +593,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -
|
|||||||
Out().red(f"Deploy failed: mtail_address {config.mtail_address} is not available (VPN up?).\n")
|
Out().red(f"Deploy failed: mtail_address {config.mtail_address} is not available (VPN up?).\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not is_in_container():
|
if host.get_fact(Command, "systemd-detect-virt -c || true") == "none":
|
||||||
port_services = [
|
port_services = [
|
||||||
(["master", "smtpd"], 25),
|
(["master", "smtpd"], 25),
|
||||||
("unbound", 53),
|
("unbound", 53),
|
||||||
@@ -624,7 +633,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -
|
|||||||
tls_deployer = get_tls_deployer(config, mail_domain)
|
tls_deployer = get_tls_deployer(config, mail_domain)
|
||||||
|
|
||||||
all_deployers = [
|
all_deployers = [
|
||||||
ChatmailDeployer(config),
|
ChatmailDeployer(mail_domain),
|
||||||
LegacyRemoveDeployer(),
|
LegacyRemoveDeployer(),
|
||||||
FiltermailDeployer(),
|
FiltermailDeployer(),
|
||||||
JournaldDeployer(),
|
JournaldDeployer(),
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
from . import remote
|
from . import remote
|
||||||
|
|
||||||
|
|
||||||
def parse_zone_records(text):
|
|
||||||
"""Yield ``(name, ttl, rtype, rdata)`` from standard BIND-format text."""
|
|
||||||
for raw_line in text.splitlines():
|
|
||||||
line = raw_line.strip()
|
|
||||||
if not line or line.startswith(";"):
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
name, ttl, _in, rtype, rdata = line.split(None, 4)
|
|
||||||
except ValueError:
|
|
||||||
raise ValueError(f"Bad zone record line: {line!r}") from None
|
|
||||||
name = name.rstrip(".")
|
|
||||||
yield name, ttl, rtype.upper(), rdata
|
|
||||||
|
|
||||||
|
|
||||||
def get_initial_remote_data(sshexec, mail_domain):
|
def get_initial_remote_data(sshexec, mail_domain):
|
||||||
return sshexec.logged(
|
return sshexec.logged(
|
||||||
call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain)
|
call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain)
|
||||||
@@ -42,39 +31,13 @@ def get_filled_zone_file(remote_data):
|
|||||||
if not sts_id:
|
if not sts_id:
|
||||||
remote_data["sts_id"] = datetime.datetime.now().strftime("%Y%m%d%H%M")
|
remote_data["sts_id"] = datetime.datetime.now().strftime("%Y%m%d%H%M")
|
||||||
|
|
||||||
d = remote_data["mail_domain"]
|
template = importlib.resources.files(__package__).joinpath("chatmail.zone.j2")
|
||||||
|
content = template.read_text()
|
||||||
def append_record(name, rtype, rdata, ttl=3600):
|
zonefile = Template(content).render(**remote_data)
|
||||||
lines.append(f"{name:<40} {ttl:<6} IN {rtype:<5} {rdata}")
|
lines = [x.strip() for x in zonefile.split("\n") if x.strip()]
|
||||||
|
|
||||||
lines = ["; Required DNS entries"]
|
|
||||||
if remote_data.get("A"):
|
|
||||||
append_record(f"{d}.", "A", remote_data["A"])
|
|
||||||
if remote_data.get("AAAA"):
|
|
||||||
append_record(f"{d}.", "AAAA", remote_data["AAAA"])
|
|
||||||
append_record(f"{d}.", "MX", f"10 {d}.")
|
|
||||||
if remote_data.get("strict_tls"):
|
|
||||||
append_record(f"_mta-sts.{d}.", "TXT", f'"v=STSv1; id={remote_data["sts_id"]}"')
|
|
||||||
append_record(f"mta-sts.{d}.", "CNAME", f"{d}.")
|
|
||||||
append_record(f"www.{d}.", "CNAME", f"{d}.")
|
|
||||||
lines.append(remote_data["dkim_entry"])
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append("; Recommended DNS entries")
|
zonefile = "\n".join(lines)
|
||||||
append_record(f"{d}.", "TXT", '"v=spf1 a ~all"')
|
return zonefile
|
||||||
append_record(f"_dmarc.{d}.", "TXT", '"v=DMARC1;p=reject;adkim=s;aspf=s"')
|
|
||||||
if remote_data.get("acme_account_url"):
|
|
||||||
append_record(
|
|
||||||
f"{d}.",
|
|
||||||
"CAA",
|
|
||||||
f'0 issue "letsencrypt.org;accounturi={remote_data["acme_account_url"]}"',
|
|
||||||
)
|
|
||||||
append_record(f"_adsp._domainkey.{d}.", "TXT", '"dkim=discardable"')
|
|
||||||
append_record(f"_submission._tcp.{d}.", "SRV", f"0 1 587 {d}.")
|
|
||||||
append_record(f"_submissions._tcp.{d}.", "SRV", f"0 1 465 {d}.")
|
|
||||||
append_record(f"_imap._tcp.{d}.", "SRV", f"0 1 143 {d}.")
|
|
||||||
append_record(f"_imaps._tcp.{d}.", "SRV", f"0 1 993 {d}.")
|
|
||||||
lines.append("")
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def check_full_zone(sshexec, remote_data, out, zonefile) -> int:
|
def check_full_zone(sshexec, remote_data, out, zonefile) -> int:
|
||||||
@@ -95,8 +58,7 @@ def check_full_zone(sshexec, remote_data, out, zonefile) -> int:
|
|||||||
returncode = 1
|
returncode = 1
|
||||||
if remote_data.get("dkim_entry") in required_diff:
|
if remote_data.get("dkim_entry") in required_diff:
|
||||||
out(
|
out(
|
||||||
"If the DKIM entry above does not work with your DNS provider,"
|
"If the DKIM entry above does not work with your DNS provider, you can try this one:\n"
|
||||||
" you can try this one:\n"
|
|
||||||
)
|
)
|
||||||
out(remote_data.get("web_dkim_entry") + "\n")
|
out(remote_data.get("web_dkim_entry") + "\n")
|
||||||
if recommended_diff:
|
if recommended_diff:
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import io
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
from chatmaild.config import Config
|
from chatmaild.config import Config
|
||||||
from pyinfra import host
|
from pyinfra import host
|
||||||
from pyinfra.facts.deb import DebPackages
|
from pyinfra.facts.deb import DebPackages
|
||||||
from pyinfra.facts.server import Arch, Sysctl
|
from pyinfra.facts.server import Arch, Command, Sysctl
|
||||||
from pyinfra.operations import apt, files, server, systemd
|
from pyinfra.operations import apt, files, server, systemd
|
||||||
|
|
||||||
from cmdeploy.basedeploy import (
|
from cmdeploy.basedeploy import (
|
||||||
@@ -13,11 +12,9 @@ from cmdeploy.basedeploy import (
|
|||||||
blocked_service_startup,
|
blocked_service_startup,
|
||||||
configure_remote_units,
|
configure_remote_units,
|
||||||
get_resource,
|
get_resource,
|
||||||
is_in_container,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DOVECOT_ARCHIVE_VERSION = "2.3.21+dfsg1-3"
|
DOVECOT_VERSION = "2.3.21+dfsg1-3"
|
||||||
DOVECOT_PACKAGE_VERSION = f"1:{DOVECOT_ARCHIVE_VERSION}"
|
|
||||||
|
|
||||||
DOVECOT_SHA256 = {
|
DOVECOT_SHA256 = {
|
||||||
("core", "amd64"): "dd060706f52a306fa863d874717210b9fe10536c824afe1790eec247ded5b27d",
|
("core", "amd64"): "dd060706f52a306fa863d874717210b9fe10536c824afe1790eec247ded5b27d",
|
||||||
@@ -40,42 +37,13 @@ class DovecotDeployer(Deployer):
|
|||||||
def install(self):
|
def install(self):
|
||||||
arch = host.get_fact(Arch)
|
arch = host.get_fact(Arch)
|
||||||
with blocked_service_startup():
|
with blocked_service_startup():
|
||||||
debs = []
|
_install_dovecot_package("core", arch)
|
||||||
for pkg in ("core", "imapd", "lmtpd"):
|
_install_dovecot_package("imapd", arch)
|
||||||
deb, changed = _download_dovecot_package(pkg, arch)
|
_install_dovecot_package("lmtpd", arch)
|
||||||
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.
|
|
||||||
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}",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
self.need_restart = True
|
|
||||||
files.put(
|
|
||||||
name="Pin dovecot packages to block Debian dist-upgrades",
|
|
||||||
src=io.StringIO(
|
|
||||||
"Package: dovecot-*\n"
|
|
||||||
"Pin: version *\n"
|
|
||||||
"Pin-Priority: -1\n"
|
|
||||||
),
|
|
||||||
dest="/etc/apt/preferences.d/pin-dovecot",
|
|
||||||
user="root",
|
|
||||||
group="root",
|
|
||||||
mode="644",
|
|
||||||
)
|
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
configure_remote_units(self.config.mail_domain, self.units)
|
configure_remote_units(self.config.mail_domain, self.units)
|
||||||
config_restart, self.daemon_reload = _configure_dovecot(self.config)
|
self.need_restart, self.daemon_reload = _configure_dovecot(self.config)
|
||||||
self.need_restart |= config_restart
|
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
activate_remote_units(self.units)
|
activate_remote_units(self.units)
|
||||||
@@ -104,22 +72,21 @@ def _pick_url(primary, fallback):
|
|||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
def _download_dovecot_package(package: str, arch: str) -> tuple[str | None, bool]:
|
def _install_dovecot_package(package: str, arch: str):
|
||||||
"""Download a dovecot .deb if needed, return (path, changed)."""
|
|
||||||
arch = "amd64" if arch == "x86_64" else arch
|
arch = "amd64" if arch == "x86_64" else arch
|
||||||
arch = "arm64" if arch == "aarch64" else arch
|
arch = "arm64" if arch == "aarch64" else arch
|
||||||
|
|
||||||
pkg_name = f"dovecot-{package}"
|
pkg_name = f"dovecot-{package}"
|
||||||
sha256 = DOVECOT_SHA256.get((package, arch))
|
sha256 = DOVECOT_SHA256.get((package, arch))
|
||||||
if sha256 is None:
|
if sha256 is None:
|
||||||
op = apt.packages(packages=[pkg_name])
|
apt.packages(packages=[pkg_name])
|
||||||
return None, bool(getattr(op, "changed", False))
|
return
|
||||||
|
|
||||||
installed_versions = host.get_fact(DebPackages).get(pkg_name, [])
|
installed_versions = host.get_fact(DebPackages).get(pkg_name, [])
|
||||||
if DOVECOT_PACKAGE_VERSION in installed_versions:
|
if DOVECOT_VERSION in installed_versions:
|
||||||
return None, False
|
return
|
||||||
|
|
||||||
url_version = DOVECOT_ARCHIVE_VERSION.replace("+", "%2B")
|
url_version = DOVECOT_VERSION.replace("+", "%2B")
|
||||||
deb_base = f"{pkg_name}_{url_version}_{arch}.deb"
|
deb_base = f"{pkg_name}_{url_version}_{arch}.deb"
|
||||||
primary_url = f"https://download.delta.chat/dovecot/{deb_base}"
|
primary_url = f"https://download.delta.chat/dovecot/{deb_base}"
|
||||||
fallback_url = f"https://github.com/chatmail/dovecot/releases/download/upstream%2F{url_version}/{deb_base}"
|
fallback_url = f"https://github.com/chatmail/dovecot/releases/download/upstream%2F{url_version}/{deb_base}"
|
||||||
@@ -134,10 +101,10 @@ def _download_dovecot_package(package: str, arch: str) -> tuple[str | None, bool
|
|||||||
cache_time=60 * 60 * 24 * 365 * 10, # never redownload the package
|
cache_time=60 * 60 * 24 * 365 * 10, # never redownload the package
|
||||||
)
|
)
|
||||||
|
|
||||||
return deb_filename, True
|
apt.deb(name=f"Install {pkg_name}", src=deb_filename)
|
||||||
|
|
||||||
|
|
||||||
def _configure_dovecot(config: Config, debug: bool = False) -> tuple[bool, bool]:
|
def _configure_dovecot(config: Config, debug: bool = False) -> (bool, bool):
|
||||||
"""Configures Dovecot IMAP server."""
|
"""Configures Dovecot IMAP server."""
|
||||||
need_restart = False
|
need_restart = False
|
||||||
daemon_reload = False
|
daemon_reload = False
|
||||||
@@ -172,7 +139,7 @@ def _configure_dovecot(config: Config, debug: bool = False) -> tuple[bool, bool]
|
|||||||
|
|
||||||
# as per https://doc.dovecot.org/2.3/configuration_manual/os/
|
# as per https://doc.dovecot.org/2.3/configuration_manual/os/
|
||||||
# it is recommended to set the following inotify limits
|
# it is recommended to set the following inotify limits
|
||||||
can_modify = not is_in_container()
|
can_modify = host.get_fact(Command, "systemd-detect-virt -c || true") == "none"
|
||||||
for name in ("max_user_instances", "max_user_watches"):
|
for name in ("max_user_instances", "max_user_watches"):
|
||||||
key = f"fs.inotify.{name}"
|
key = f"fs.inotify.{name}"
|
||||||
value = host.get_fact(Sysctl)[key]
|
value = host.get_fact(Sysctl)[key]
|
||||||
@@ -180,7 +147,7 @@ def _configure_dovecot(config: Config, debug: bool = False) -> tuple[bool, bool]
|
|||||||
continue
|
continue
|
||||||
if not can_modify:
|
if not can_modify:
|
||||||
print(
|
print(
|
||||||
"\n!!!! refusing to attempt sysctl setting in containers\n"
|
"\n!!!! refusing to attempt sysctl setting in shared-kernel containers\n"
|
||||||
f"!!!! dovecot: sysctl {key!r}={value}, should be >65534 for production setups\n"
|
f"!!!! dovecot: sysctl {key!r}={value}, should be >65534 for production setups\n"
|
||||||
"!!!!"
|
"!!!!"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ class FiltermailDeployer(Deployer):
|
|||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
arch = host.get_fact(facts.server.Arch)
|
arch = host.get_fact(facts.server.Arch)
|
||||||
url = f"https://github.com/chatmail/filtermail/releases/download/v0.6.1/filtermail-{arch}"
|
url = f"https://github.com/chatmail/filtermail/releases/download/v0.6.0/filtermail-{arch}"
|
||||||
sha256sum = {
|
sha256sum = {
|
||||||
"x86_64": "48b3fb80c092d00b9b0a0ef77a8673496da3b9aed5ec1851e1df936d5589d62f",
|
"x86_64": "3fd8b18282252c75a5bbfa603d8c1b65f6563e5e920bddf3e64e451b7cdb43ce",
|
||||||
"aarch64": "c65bd5f45df187d3d65d6965a285583a3be0f44a6916ff12909ff9a8d702c22e",
|
"aarch64": "2bd191de205f7fd60158dd8e3516ab7e3efb14627696f3d7dc186bdcd9e10a43",
|
||||||
}[arch]
|
}[arch]
|
||||||
self.need_restart |= files.download(
|
self.need_restart |= files.download(
|
||||||
name="Download filtermail",
|
name="Download filtermail",
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ http {
|
|||||||
|
|
||||||
access_log syslog:server=unix:/dev/log,facility=local7;
|
access_log syslog:server=unix:/dev/log,facility=local7;
|
||||||
|
|
||||||
location /mxdeliv/ {
|
|
||||||
proxy_pass http://127.0.0.1:{{ config.filtermail_http_port }};
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
# First attempt to serve request as file, then
|
# First attempt to serve request as file, then
|
||||||
# as directory, then fall back to displaying a 404.
|
# as directory, then fall back to displaying a 404.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ smtpd_tls_key_file={{ config.tls_key_path }}
|
|||||||
smtpd_tls_security_level=may
|
smtpd_tls_security_level=may
|
||||||
|
|
||||||
smtp_tls_CApath=/etc/ssl/certs
|
smtp_tls_CApath=/etc/ssl/certs
|
||||||
smtp_tls_security_level=verify
|
smtp_tls_security_level={{ "verify" if config.tls_cert_mode == "acme" else "encrypt" }}
|
||||||
# Send SNI extension when connecting to other servers.
|
# Send SNI extension when connecting to other servers.
|
||||||
# <https://www.postfix.org/postconf.5.html#smtp_tls_servername>
|
# <https://www.postfix.org/postconf.5.html#smtp_tls_servername>
|
||||||
smtp_tls_servername = hostname
|
smtp_tls_servername = hostname
|
||||||
@@ -88,22 +88,6 @@ inet_protocols = ipv4
|
|||||||
inet_protocols = all
|
inet_protocols = all
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Postfix does not try IPv4 and IPv6 connections
|
|
||||||
# concurrently as of version 3.7.11.
|
|
||||||
#
|
|
||||||
# When relay has both A (IPv4) and AAAA (IPv6) records,
|
|
||||||
# but broken IPv6 connectivity,
|
|
||||||
# every second message is delayed by the connection timeout
|
|
||||||
# <https://www.postfix.org/postconf.5.html#smtp_connect_timeout>
|
|
||||||
# which defaults to 30 seconds. Reducing timeouts is not a solution
|
|
||||||
# as this will result in a failure to connect to slow servers.
|
|
||||||
#
|
|
||||||
# As a workaround we always prefer IPv4 when it is available.
|
|
||||||
#
|
|
||||||
# The setting is documented at
|
|
||||||
# <https://www.postfix.org/postconf.5.html#smtp_address_preference>
|
|
||||||
smtp_address_preference=ipv4
|
|
||||||
|
|
||||||
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
||||||
virtual_mailbox_domains = {{ config.mail_domain }}
|
virtual_mailbox_domains = {{ config.mail_domain }}
|
||||||
lmtp_header_checks = regexp:/etc/postfix/lmtp_header_cleanup
|
lmtp_header_checks = regexp:/etc/postfix/lmtp_header_cleanup
|
||||||
|
|||||||
@@ -57,10 +57,9 @@ def get_dkim_entry(mail_domain, pre_command, dkim_selector):
|
|||||||
dkim_value_raw = f"v=DKIM1;k=rsa;p={dkim_pubkey};s=email;t=s"
|
dkim_value_raw = f"v=DKIM1;k=rsa;p={dkim_pubkey};s=email;t=s"
|
||||||
dkim_value = '" "'.join(re.findall(".{1,255}", dkim_value_raw))
|
dkim_value = '" "'.join(re.findall(".{1,255}", dkim_value_raw))
|
||||||
web_dkim_value = "".join(re.findall(".{1,255}", dkim_value_raw))
|
web_dkim_value = "".join(re.findall(".{1,255}", dkim_value_raw))
|
||||||
name = f"{dkim_selector}._domainkey.{mail_domain}."
|
|
||||||
return (
|
return (
|
||||||
f'{name:<40} 3600 IN TXT "{dkim_value}"',
|
f'{dkim_selector}._domainkey.{mail_domain}. TXT "{dkim_value}"',
|
||||||
f'{name:<40} 3600 IN TXT "{web_dkim_value}"',
|
f'{dkim_selector}._domainkey.{mail_domain}. TXT "{web_dkim_value}"',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +94,7 @@ def check_zonefile(zonefile, verbose=True):
|
|||||||
if not zf_line.strip() or zf_line.startswith(";"):
|
if not zf_line.strip() or zf_line.startswith(";"):
|
||||||
continue
|
continue
|
||||||
print(f"dns-checking {zf_line!r}") if verbose else log_progress("")
|
print(f"dns-checking {zf_line!r}") if verbose else log_progress("")
|
||||||
zf_domain, _ttl, _in, zf_typ, zf_value = zf_line.split(None, 4)
|
zf_domain, zf_typ, zf_value = zf_line.split(maxsplit=2)
|
||||||
zf_domain = zf_domain.rstrip(".")
|
zf_domain = zf_domain.rstrip(".")
|
||||||
zf_value = zf_value.strip()
|
zf_value = zf_value.strip()
|
||||||
query_value = query_dns(zf_typ, zf_domain)
|
query_value = query_dns(zf_typ, zf_domain)
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ def openssl_selfsigned_args(domain, cert_path, key_path, days=36500):
|
|||||||
"-keyout", str(key_path),
|
"-keyout", str(key_path),
|
||||||
"-out", str(cert_path),
|
"-out", str(cert_path),
|
||||||
"-subj", f"/CN={domain}",
|
"-subj", f"/CN={domain}",
|
||||||
# Mark as end-entity cert so it cannot be used as a CA to sign others.
|
|
||||||
"-addext", "basicConstraints=critical,CA:FALSE",
|
|
||||||
"-addext", "extendedKeyUsage=serverAuth,clientAuth",
|
"-addext", "extendedKeyUsage=serverAuth,clientAuth",
|
||||||
"-addext",
|
"-addext",
|
||||||
f"subjectAltName=DNS:{domain},DNS:www.{domain},DNS:mta-sts.{domain}",
|
f"subjectAltName=DNS:{domain},DNS:www.{domain},DNS:mta-sts.{domain}",
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
; Required DNS entries
|
; Required DNS entries for chatmail servers
|
||||||
zftest.testrun.org. 3600 IN A 135.181.204.127
|
zftest.testrun.org. A 135.181.204.127
|
||||||
zftest.testrun.org. 3600 IN AAAA 2a01:4f9:c012:52f4::1
|
zftest.testrun.org. AAAA 2a01:4f9:c012:52f4::1
|
||||||
zftest.testrun.org. 3600 IN MX 10 zftest.testrun.org.
|
zftest.testrun.org. MX 10 zftest.testrun.org.
|
||||||
_mta-sts.zftest.testrun.org. 3600 IN TXT "v=STSv1; id=202403211706"
|
_mta-sts.zftest.testrun.org. TXT "v=STSv1; id=202403211706"
|
||||||
mta-sts.zftest.testrun.org. 3600 IN CNAME zftest.testrun.org.
|
mta-sts.zftest.testrun.org. CNAME zftest.testrun.org.
|
||||||
www.zftest.testrun.org. 3600 IN CNAME zftest.testrun.org.
|
www.zftest.testrun.org. CNAME zftest.testrun.org.
|
||||||
opendkim._domainkey.zftest.testrun.org. 3600 IN TXT "v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoYt82CVUyz2ouaqjX2kB+5J80knAyoOU3MGU5aWppmwUwwTvj/oSTSpkc5JMtVTRmKKr8NUDWAL1Yw7dfGqqPHdHfwwjS3BIvDzYx+hzgtz62RnfNgV+/2MAoNpfX7cAFIHdRzEHNtwugc3RDLquqPoupAE3Y2YRw2T5zG5fILh4vwIcJZL5Uq6B92j8wwJqOex" "33n+vm1NKQ9rxo/UsHAmZlJzpooXcG/4igTBxJyJlamVSRR6N7Nul1v//YJb7J6v2o0iPHW6uE0StzKaPPNC2IVosSRFbD9H2oqppltptFSNPlI0E+t0JBWHem6YK7xcugiO3ImMCaaU8g6Jt/wIDAQAB;s=email;t=s"
|
opendkim._domainkey.zftest.testrun.org. TXT "v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoYt82CVUyz2ouaqjX2kB+5J80knAyoOU3MGU5aWppmwUwwTvj/oSTSpkc5JMtVTRmKKr8NUDWAL1Yw7dfGqqPHdHfwwjS3BIvDzYx+hzgtz62RnfNgV+/2MAoNpfX7cAFIHdRzEHNtwugc3RDLquqPoupAE3Y2YRw2T5zG5fILh4vwIcJZL5Uq6B92j8wwJqOex" "33n+vm1NKQ9rxo/UsHAmZlJzpooXcG/4igTBxJyJlamVSRR6N7Nul1v//YJb7J6v2o0iPHW6uE0StzKaPPNC2IVosSRFbD9H2oqppltptFSNPlI0E+t0JBWHem6YK7xcugiO3ImMCaaU8g6Jt/wIDAQAB;s=email;t=s"
|
||||||
|
|
||||||
; Recommended DNS entries
|
; Recommended DNS entries
|
||||||
zftest.testrun.org. 3600 IN TXT "v=spf1 a ~all"
|
_submission._tcp.zftest.testrun.org. SRV 0 1 587 zftest.testrun.org.
|
||||||
_dmarc.zftest.testrun.org. 3600 IN TXT "v=DMARC1;p=reject;adkim=s;aspf=s"
|
_submissions._tcp.zftest.testrun.org. SRV 0 1 465 zftest.testrun.org.
|
||||||
zftest.testrun.org. 3600 IN CAA 0 issue "letsencrypt.org;accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/1371472956"
|
_imap._tcp.zftest.testrun.org. SRV 0 1 143 zftest.testrun.org.
|
||||||
_adsp._domainkey.zftest.testrun.org. 3600 IN TXT "dkim=discardable"
|
_imaps._tcp.zftest.testrun.org. SRV 0 1 993 zftest.testrun.org.
|
||||||
_submission._tcp.zftest.testrun.org. 3600 IN SRV 0 1 587 zftest.testrun.org.
|
zftest.testrun.org. CAA 0 issue "letsencrypt.org;accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/1371472956"
|
||||||
_submissions._tcp.zftest.testrun.org. 3600 IN SRV 0 1 465 zftest.testrun.org.
|
zftest.testrun.org. TXT "v=spf1 a:zftest.testrun.org ~all"
|
||||||
_imap._tcp.zftest.testrun.org. 3600 IN SRV 0 1 143 zftest.testrun.org.
|
_dmarc.zftest.testrun.org. TXT "v=DMARC1;p=reject;adkim=s;aspf=s"
|
||||||
_imaps._tcp.zftest.testrun.org. 3600 IN SRV 0 1 993 zftest.testrun.org.
|
_adsp._domainkey.zftest.testrun.org. TXT "dkim=discardable"
|
||||||
|
|||||||
@@ -71,44 +71,6 @@ class TestSSHExecutor:
|
|||||||
assert (now - since_date).total_seconds() < 60 * 60 * 51
|
assert (now - since_date).total_seconds() < 60 * 60 * 51
|
||||||
|
|
||||||
|
|
||||||
def test_dovecot_main_process_matches_installed_binary(sshdomain):
|
|
||||||
sshexec = get_sshexec(sshdomain)
|
|
||||||
main_pid = int(
|
|
||||||
sshexec(
|
|
||||||
call=remote.rshell.shell,
|
|
||||||
kwargs=dict(
|
|
||||||
command="timeout 10 systemctl show -p MainPID --value dovecot.service"
|
|
||||||
),
|
|
||||||
).strip()
|
|
||||||
)
|
|
||||||
assert main_pid != 0, "dovecot.service MainPID is 0 -- service not running?"
|
|
||||||
|
|
||||||
exe = sshexec(
|
|
||||||
call=remote.rshell.shell,
|
|
||||||
kwargs=dict(command=f"timeout 10 readlink /proc/{main_pid}/exe"),
|
|
||||||
).strip()
|
|
||||||
status_text = sshexec(
|
|
||||||
call=remote.rshell.shell,
|
|
||||||
kwargs=dict(
|
|
||||||
command="timeout 10 systemctl show -p StatusText --value dovecot.service"
|
|
||||||
),
|
|
||||||
).strip()
|
|
||||||
installed_version = sshexec(
|
|
||||||
call=remote.rshell.shell, kwargs=dict(command="timeout 10 dovecot --version")
|
|
||||||
).strip()
|
|
||||||
|
|
||||||
assert not exe.endswith("(deleted)"), (
|
|
||||||
f"running dovecot binary was deleted (stale after upgrade): {exe}"
|
|
||||||
)
|
|
||||||
expected_status_text = f"v{installed_version}"
|
|
||||||
assert status_text == expected_status_text or status_text.startswith(
|
|
||||||
f"{expected_status_text} "
|
|
||||||
), (
|
|
||||||
f"dovecot status version mismatch: "
|
|
||||||
f"StatusText={status_text!r}, installed={installed_version!r}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_timezone_env(remote):
|
def test_timezone_env(remote):
|
||||||
for line in remote.iter_output("env"):
|
for line in remote.iter_output("env"):
|
||||||
print(line)
|
print(line)
|
||||||
|
|||||||
@@ -35,11 +35,6 @@ def pytest_runtest_setup(item):
|
|||||||
|
|
||||||
|
|
||||||
def _get_chatmail_config():
|
def _get_chatmail_config():
|
||||||
inipath = os.environ.get("CHATMAIL_INI")
|
|
||||||
if inipath:
|
|
||||||
path = Path(inipath).resolve()
|
|
||||||
return read_config(path), path
|
|
||||||
|
|
||||||
current = Path().resolve()
|
current = Path().resolve()
|
||||||
while 1:
|
while 1:
|
||||||
path = current.joinpath("chatmail.ini").resolve()
|
path = current.joinpath("chatmail.ini").resolve()
|
||||||
@@ -393,15 +388,12 @@ def cmfactory(rpc, gencreds, maildomain, chatmail_config):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def remote(sshdomain):
|
def remote(sshdomain):
|
||||||
r = Remote(sshdomain)
|
return Remote(sshdomain)
|
||||||
yield r
|
|
||||||
r.close()
|
|
||||||
|
|
||||||
|
|
||||||
class Remote:
|
class Remote:
|
||||||
def __init__(self, sshdomain):
|
def __init__(self, sshdomain):
|
||||||
self.sshdomain = sshdomain
|
self.sshdomain = sshdomain
|
||||||
self._procs = []
|
|
||||||
|
|
||||||
def iter_output(self, logcmd="", ready=None):
|
def iter_output(self, logcmd="", ready=None):
|
||||||
getjournal = "journalctl -f" if not logcmd else logcmd
|
getjournal = "journalctl -f" if not logcmd else logcmd
|
||||||
@@ -411,32 +403,19 @@ class Remote:
|
|||||||
case "localhost": command = []
|
case "localhost": command = []
|
||||||
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
||||||
[command.append(arg) for arg in getjournal.split()]
|
[command.append(arg) for arg in getjournal.split()]
|
||||||
popen = subprocess.Popen(
|
self.popen = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
stdin=subprocess.DEVNULL,
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL,
|
|
||||||
)
|
)
|
||||||
self._procs.append(popen)
|
while 1:
|
||||||
try:
|
line = self.popen.stdout.readline()
|
||||||
while 1:
|
res = line.decode().strip().lower()
|
||||||
line = popen.stdout.readline()
|
if not res:
|
||||||
res = line.decode().strip().lower()
|
break
|
||||||
if not res:
|
if ready is not None:
|
||||||
break
|
ready()
|
||||||
if ready is not None:
|
ready = None
|
||||||
ready()
|
yield res
|
||||||
ready = None
|
|
||||||
yield res
|
|
||||||
finally:
|
|
||||||
popen.terminate()
|
|
||||||
popen.wait()
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
while self._procs:
|
|
||||||
proc = self._procs.pop()
|
|
||||||
proc.kill()
|
|
||||||
proc.wait()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@@ -23,19 +23,15 @@ class TestCmdline:
|
|||||||
run = parser.parse_args(["run"])
|
run = parser.parse_args(["run"])
|
||||||
assert init and run
|
assert init and run
|
||||||
|
|
||||||
def test_init_not_overwrite(self, capsys, tmp_path, monkeypatch):
|
def test_init_not_overwrite(self, capsys):
|
||||||
monkeypatch.delenv("CHATMAIL_INI", raising=False)
|
assert main(["init", "chat.example.org"]) == 0
|
||||||
inipath = tmp_path / "chatmail.ini"
|
|
||||||
args = ["init", "--config", str(inipath), "chat.example.org"]
|
|
||||||
assert main(args) == 0
|
|
||||||
capsys.readouterr()
|
capsys.readouterr()
|
||||||
|
|
||||||
assert main(args) == 1
|
assert main(["init", "chat.example.org"]) == 1
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert "path exists" in out.lower()
|
assert "path exists" in out.lower()
|
||||||
|
|
||||||
args.insert(1, "--force")
|
assert main(["init", "chat.example.org", "--force"]) == 0
|
||||||
assert main(args) == 0
|
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert "deleting config file" in out.lower()
|
assert "deleting config file" in out.lower()
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from copy import deepcopy
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cmdeploy import remote
|
from cmdeploy import remote
|
||||||
from cmdeploy.dns import check_full_zone, check_initial_remote_data, parse_zone_records
|
from cmdeploy.dns import check_full_zone, check_initial_remote_data
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -125,49 +125,18 @@ class TestPerformInitialChecks:
|
|||||||
assert not l
|
assert not l
|
||||||
|
|
||||||
|
|
||||||
def test_parse_zone_records():
|
|
||||||
text = """
|
|
||||||
; This is a comment
|
|
||||||
some.domain. 3600 IN A 1.1.1.1
|
|
||||||
|
|
||||||
; Another comment
|
|
||||||
www.some.domain. 3600 IN CNAME some.domain.
|
|
||||||
|
|
||||||
; Multi-word rdata
|
|
||||||
some.domain. 3600 IN MX 10 mail.some.domain.
|
|
||||||
|
|
||||||
; DKIM record (single line, multi-word TXT rdata)
|
|
||||||
dkim._domainkey.some.domain. 3600 IN TXT "v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG" "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA"
|
|
||||||
|
|
||||||
; Another TXT record
|
|
||||||
_dmarc.some.domain. 3600 IN TXT "v=DMARC1;p=reject"
|
|
||||||
"""
|
|
||||||
records = list(parse_zone_records(text))
|
|
||||||
assert records == [
|
|
||||||
("some.domain", "3600", "A", "1.1.1.1"),
|
|
||||||
("www.some.domain", "3600", "CNAME", "some.domain."),
|
|
||||||
("some.domain", "3600", "MX", "10 mail.some.domain."),
|
|
||||||
(
|
|
||||||
"dkim._domainkey.some.domain",
|
|
||||||
"3600",
|
|
||||||
"TXT",
|
|
||||||
'"v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG" "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA"',
|
|
||||||
),
|
|
||||||
("_dmarc.some.domain", "3600", "TXT", '"v=DMARC1;p=reject"'),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_zone_records_invalid_line():
|
|
||||||
text = "invalid line"
|
|
||||||
with pytest.raises(ValueError, match="Bad zone record line"):
|
|
||||||
list(parse_zone_records(text))
|
|
||||||
|
|
||||||
|
|
||||||
def parse_zonefile_into_dict(zonefile, mockdns_base, only_required=False):
|
def parse_zonefile_into_dict(zonefile, mockdns_base, only_required=False):
|
||||||
if only_required:
|
for zf_line in zonefile.split("\n"):
|
||||||
zonefile = zonefile.split("; Recommended")[0]
|
if zf_line.startswith("#"):
|
||||||
for name, ttl, rtype, rdata in parse_zone_records(zonefile):
|
if "Recommended" in zf_line and only_required:
|
||||||
mockdns_base.setdefault(rtype, {})[name] = rdata
|
return
|
||||||
|
continue
|
||||||
|
if not zf_line.strip():
|
||||||
|
continue
|
||||||
|
zf_domain, zf_typ, zf_value = zf_line.split(maxsplit=2)
|
||||||
|
zf_domain = zf_domain.rstrip(".")
|
||||||
|
zf_value = zf_value.strip()
|
||||||
|
mockdns_base.setdefault(zf_typ, {})[zf_domain] = zf_value
|
||||||
|
|
||||||
|
|
||||||
class MockSSHExec:
|
class MockSSHExec:
|
||||||
|
|||||||
@@ -1,238 +0,0 @@
|
|||||||
from contextlib import nullcontext
|
|
||||||
from types import SimpleNamespace
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from cmdeploy.dovecot import deployer as dovecot_deployer
|
|
||||||
from pyinfra.facts.deb import DebPackages
|
|
||||||
|
|
||||||
|
|
||||||
def make_host(*fact_pairs):
|
|
||||||
"""Build a mock host; get_fact(cls) dispatches to the provided facts mapping.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*fact_pairs: tuples of (fact_class, fact_value) to register
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
SimpleNamespace with get_fact that raises a clear error if an
|
|
||||||
unexpected fact type is requested.
|
|
||||||
"""
|
|
||||||
facts = dict(fact_pairs)
|
|
||||||
|
|
||||||
def get_fact(cls):
|
|
||||||
if cls not in facts:
|
|
||||||
registered = ", ".join(c.__name__ for c in facts)
|
|
||||||
raise LookupError(
|
|
||||||
f"unexpected get_fact({cls.__name__}); "
|
|
||||||
f"only registered: {registered}"
|
|
||||||
)
|
|
||||||
return facts[cls]
|
|
||||||
|
|
||||||
return SimpleNamespace(get_fact=get_fact)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def deployer():
|
|
||||||
return dovecot_deployer.DovecotDeployer(
|
|
||||||
SimpleNamespace(mail_domain="chat.example.org"),
|
|
||||||
disable_mail=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def patch_blocked(monkeypatch):
|
|
||||||
monkeypatch.setattr(dovecot_deployer, "blocked_service_startup", nullcontext)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_files_put(monkeypatch):
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.files,
|
|
||||||
"put",
|
|
||||||
lambda **kwargs: SimpleNamespace(changed=False),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def track_shell(monkeypatch):
|
|
||||||
calls = []
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.server,
|
|
||||||
"shell",
|
|
||||||
lambda **kwargs: calls.append(kwargs) or SimpleNamespace(changed=False),
|
|
||||||
)
|
|
||||||
return calls
|
|
||||||
|
|
||||||
|
|
||||||
def test_download_dovecot_package_skips_epoch_matched_install(monkeypatch):
|
|
||||||
epoch_version = dovecot_deployer.DOVECOT_PACKAGE_VERSION
|
|
||||||
downloads = []
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"host",
|
|
||||||
make_host((DebPackages, {"dovecot-core": [epoch_version]})),
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"_pick_url",
|
|
||||||
lambda primary, fallback: primary,
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.files,
|
|
||||||
"download",
|
|
||||||
lambda **kwargs: downloads.append(kwargs),
|
|
||||||
)
|
|
||||||
|
|
||||||
deb, changed = dovecot_deployer._download_dovecot_package("core", "amd64")
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
def test_download_dovecot_package_uses_archive_version_for_url_and_filename(
|
|
||||||
monkeypatch,
|
|
||||||
):
|
|
||||||
downloads = []
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"host",
|
|
||||||
make_host((DebPackages, {})),
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"_pick_url",
|
|
||||||
lambda primary, fallback: primary,
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.files,
|
|
||||||
"download",
|
|
||||||
lambda **kwargs: downloads.append(kwargs),
|
|
||||||
)
|
|
||||||
|
|
||||||
deb, changed = dovecot_deployer._download_dovecot_package("core", "amd64")
|
|
||||||
|
|
||||||
archive_version = dovecot_deployer.DOVECOT_ARCHIVE_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}"
|
|
||||||
)
|
|
||||||
assert len(downloads) == 1, "files.download should be called exactly once"
|
|
||||||
|
|
||||||
|
|
||||||
def test_install_skips_dpkg_path_when_epoch_matched_packages_present(
|
|
||||||
deployer, patch_blocked, mock_files_put, track_shell, monkeypatch
|
|
||||||
):
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"host",
|
|
||||||
make_host(
|
|
||||||
(
|
|
||||||
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_deployer.Arch, "x86_64"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
downloads = []
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.files,
|
|
||||||
"download",
|
|
||||||
lambda **kwargs: downloads.append(kwargs),
|
|
||||||
)
|
|
||||||
|
|
||||||
deployer.install()
|
|
||||||
|
|
||||||
assert downloads == [], "should not download when all packages epoch-matched"
|
|
||||||
assert track_shell == [], "should not run dpkg when all packages epoch-matched"
|
|
||||||
assert deployer.need_restart is False, (
|
|
||||||
"need_restart should be False when nothing changed"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_install_unsupported_arch_falls_back_to_apt(
|
|
||||||
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"),
|
|
||||||
)
|
|
||||||
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)
|
|
||||||
|
|
||||||
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"]], (
|
|
||||||
f"expected apt install of core/imapd/lmtpd, 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(
|
|
||||||
deployer, patch_blocked, mock_files_put, track_shell, monkeypatch
|
|
||||||
):
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"host",
|
|
||||||
make_host(
|
|
||||||
(dovecot_deployer.DebPackages, {}),
|
|
||||||
(dovecot_deployer.Arch, "x86_64"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer,
|
|
||||||
"_pick_url",
|
|
||||||
lambda primary, fallback: primary,
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(
|
|
||||||
dovecot_deployer.files,
|
|
||||||
"download",
|
|
||||||
lambda **kwargs: SimpleNamespace(changed=True),
|
|
||||||
)
|
|
||||||
|
|
||||||
deployer.install()
|
|
||||||
|
|
||||||
assert len(track_shell) == 1, (
|
|
||||||
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 deployer.need_restart is True, (
|
|
||||||
"need_restart should be True after dpkg install"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_pick_url_falls_back_on_primary_error(monkeypatch):
|
|
||||||
def raise_error(req, timeout):
|
|
||||||
raise OSError("connection timeout")
|
|
||||||
|
|
||||||
monkeypatch.setattr(dovecot_deployer.urllib.request, "urlopen", raise_error)
|
|
||||||
result = dovecot_deployer._pick_url("http://primary", "http://fallback")
|
|
||||||
assert result == "http://fallback", (
|
|
||||||
f"should fall back when primary fails, got {result!r}"
|
|
||||||
)
|
|
||||||
264
doc/source/docker.rst
Normal file
264
doc/source/docker.rst
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
Docker installation
|
||||||
|
===================
|
||||||
|
|
||||||
|
This section provides instructions for installing a chatmail relay
|
||||||
|
using Docker Compose.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
- Docker support is experimental, CI builds and tests the image automatically, but please report bugs.
|
||||||
|
- The image wraps the cmdeploy process detailed in the :doc:`getting_started` instructions in a Debian-systemd image with r/w access to `/sys/fs`
|
||||||
|
- Currently amd64-only (arm64 should work but is untested).
|
||||||
|
|
||||||
|
|
||||||
|
Setup Preparation
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
We use ``chat.example.org`` as the chatmail domain in the following
|
||||||
|
steps. Please substitute it with your own domain.
|
||||||
|
|
||||||
|
1. Install docker and docker compose v2 (check with `docker compose version`), install, e.g., on
|
||||||
|
- Debian 12 through the `official install instructions <https://docs.docker.com/engine/install/debian/#install-using-the-repository>`_
|
||||||
|
- Debian 13+ with `apt install docker docker-compose`
|
||||||
|
|
||||||
|
2. Setup the initial DNS records.
|
||||||
|
The following is an example in the familiar BIND zone file format with
|
||||||
|
a TTL of 1 hour (3600 seconds).
|
||||||
|
Please substitute your domain and IP addresses.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
chat.example.org. 3600 IN A 198.51.100.5
|
||||||
|
chat.example.org. 3600 IN AAAA 2001:db8::5
|
||||||
|
www.chat.example.org. 3600 IN CNAME chat.example.org.
|
||||||
|
mta-sts.chat.example.org. 3600 IN CNAME chat.example.org.
|
||||||
|
|
||||||
|
3. Configure kernel parameters on the host, as these can not be set from the container::
|
||||||
|
|
||||||
|
echo "fs.inotify.max_user_instances=65536" | sudo tee -a /etc/sysctl.d/99-inotify.conf
|
||||||
|
echo "fs.inotify.max_user_watches=65536" | sudo tee -a /etc/sysctl.d/99-inotify.conf
|
||||||
|
sudo sysctl --system
|
||||||
|
|
||||||
|
|
||||||
|
Docker Compose Setup
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Pre-built images are available from GitHub Container Registry. The
|
||||||
|
``main`` branch and tagged releases are pushed automatically by CI::
|
||||||
|
|
||||||
|
docker pull ghcr.io/chatmail/relay:main # latest main branch
|
||||||
|
docker pull ghcr.io/chatmail/relay:1.2.3 # tagged release
|
||||||
|
|
||||||
|
|
||||||
|
Create service directory
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Either:
|
||||||
|
|
||||||
|
- Create a service directory and download the compose files::
|
||||||
|
|
||||||
|
mkdir -p /srv/chatmail-relay && cd /srv/chatmail-relay
|
||||||
|
wget https://raw.githubusercontent.com/chatmail/relay/refs/heads/main/docker/docker-compose.yaml
|
||||||
|
wget https://raw.githubusercontent.com/chatmail/relay/refs/heads/main/docker/docker-compose.override.yaml.example -O docker-compose.override.yaml
|
||||||
|
|
||||||
|
- or clone the chatmail repo and enter the docker directory::
|
||||||
|
|
||||||
|
git clone https://github.com/chatmail/relay
|
||||||
|
cd relay/docker
|
||||||
|
|
||||||
|
|
||||||
|
Customize and start
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
1. Set the fully qualified domain name of the relay::
|
||||||
|
|
||||||
|
echo 'MAIL_DOMAIN=chat.example.org' > .env
|
||||||
|
|
||||||
|
The container generates a ``chatmail.ini`` with defaults from
|
||||||
|
``MAIL_DOMAIN`` on first start. To customize chatmail settings, mount
|
||||||
|
your own ``chatmail.ini`` instead (see `Custom chatmail.ini`_ below).
|
||||||
|
|
||||||
|
2. All local customizations (data paths, extra volumes, config mounts) go in
|
||||||
|
``docker-compose.override.yaml``, which Compose merges automatically with
|
||||||
|
the base file. By default, all data is stored in docker volumes, you will
|
||||||
|
likely want to at least create and configure the mail storage location, but
|
||||||
|
you might also want to configure external TLS certificates there.
|
||||||
|
|
||||||
|
3. Start the container::
|
||||||
|
|
||||||
|
docker compose up -d
|
||||||
|
docker compose logs -f chatmail # view logs, Ctrl+C to exit
|
||||||
|
|
||||||
|
4. After installation is complete, open ``https://chat.example.org`` in
|
||||||
|
your browser.
|
||||||
|
|
||||||
|
Finish install and test
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
You can test the installation with::
|
||||||
|
|
||||||
|
pip install cmping chat.example.org # or
|
||||||
|
uvx cmping chat.example.org # if you use https://docs.astral.sh/uv/
|
||||||
|
|
||||||
|
You should check and extend your DNS records for better interoperability::
|
||||||
|
|
||||||
|
# Show required DNS records
|
||||||
|
docker exec chatmail cmdeploy dns --ssh-host @local
|
||||||
|
|
||||||
|
You can check server status with::
|
||||||
|
|
||||||
|
docker exec chatmail cmdeploy status --ssh-host @local
|
||||||
|
|
||||||
|
You can run some benchmarks (can also run from any machine with cmdeploy installed)::
|
||||||
|
|
||||||
|
docker exec chatmail cmdeploy bench
|
||||||
|
|
||||||
|
You can run the test suite with::
|
||||||
|
|
||||||
|
docker exec chatmail cmdeploy test --ssh-host localhost
|
||||||
|
|
||||||
|
You can look at logs::
|
||||||
|
|
||||||
|
docker exec chatmail journalctl -fu postfix@-
|
||||||
|
|
||||||
|
|
||||||
|
Customization
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Website
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
You can customize the chatmail landing page by mounting a directory with
|
||||||
|
your own website source files.
|
||||||
|
|
||||||
|
1. Create a directory with your custom website source::
|
||||||
|
|
||||||
|
mkdir -p ./custom/www/src
|
||||||
|
nano ./custom/www/src/index.md
|
||||||
|
|
||||||
|
2. Add the volume mount in ``docker-compose.override.yaml``::
|
||||||
|
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
volumes:
|
||||||
|
- ./custom/www:/opt/chatmail-www
|
||||||
|
|
||||||
|
3. Restart the service::
|
||||||
|
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
|
||||||
|
Custom chatmail.ini
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
If you want to go beyond simply setting the ``MAIL_DOMAIN`` in ``.env``, you
|
||||||
|
can use a regular `chatmail.ini` to give you full control.
|
||||||
|
|
||||||
|
1. Extract the generated config from a running container::
|
||||||
|
|
||||||
|
docker cp chatmail:/etc/chatmail/chatmail.ini ./chatmail.ini
|
||||||
|
|
||||||
|
2. Edit ``chatmail.ini`` as needed.
|
||||||
|
|
||||||
|
3. Add the volume mount in ``docker-compose.override.yaml`` ::
|
||||||
|
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
volumes:
|
||||||
|
- ./chatmail.ini:/etc/chatmail/chatmail.ini
|
||||||
|
|
||||||
|
4. Restart the container, the container skips generating a new one: ::
|
||||||
|
|
||||||
|
docker compose down && docker compose up -d
|
||||||
|
|
||||||
|
|
||||||
|
External TLS certificates
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
If TLS certificates are managed outside the container (e.g. by certbot,
|
||||||
|
acmetool, or Traefik on the host), mount them into the container and set
|
||||||
|
``TLS_EXTERNAL_CERT_AND_KEY`` in ``docker-compose.override.yaml``.
|
||||||
|
Changed certificates are picked up automatically via inotify.
|
||||||
|
See the examples in the example override and :ref:`external-tls` in the getting started guide for details.
|
||||||
|
|
||||||
|
|
||||||
|
Migrating from a bare-metal install
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
If you have an existing bare-metal chatmail installation and want to
|
||||||
|
switch to Docker:
|
||||||
|
|
||||||
|
1. Stop all existing services::
|
||||||
|
|
||||||
|
systemctl stop postfix dovecot doveauth nginx opendkim unbound \
|
||||||
|
acmetool-redirector filtermail filtermail-incoming chatmail-turn \
|
||||||
|
iroh-relay chatmail-metadata lastlogin mtail
|
||||||
|
systemctl disable postfix dovecot doveauth nginx opendkim unbound \
|
||||||
|
acmetool-redirector filtermail filtermail-incoming chatmail-turn \
|
||||||
|
iroh-relay chatmail-metadata lastlogin mtail
|
||||||
|
|
||||||
|
2. Copy your existing ``chatmail.ini`` and mount it into the container
|
||||||
|
(see `Custom chatmail.ini`_ above)::
|
||||||
|
|
||||||
|
cp /usr/local/lib/chatmaild/chatmail.ini ./chatmail.ini
|
||||||
|
|
||||||
|
3. Copy persistent data into the ``./data/`` subdirectories (for example, as configured in `Customize and start`_) ::
|
||||||
|
|
||||||
|
mkdir -p data/dkim data/certs data/mail
|
||||||
|
|
||||||
|
# DKIM keys
|
||||||
|
cp -a /etc/dkimkeys/* data/dkim/
|
||||||
|
|
||||||
|
# TLS certificates
|
||||||
|
rsync -a /var/lib/acme/ data/certs/
|
||||||
|
|
||||||
|
Note that ownership of dkim and acme is adjusted on container start.
|
||||||
|
|
||||||
|
For the mail directory::
|
||||||
|
|
||||||
|
rsync -a /home/vmail/ data/mail/
|
||||||
|
|
||||||
|
Alternatively, mount ``/home/vmail`` directly by changing the volume
|
||||||
|
in ``docker-compose-override.yaml``::
|
||||||
|
|
||||||
|
- /home/vmail:/home/vmail
|
||||||
|
|
||||||
|
The three ``./data/`` subdirectories cover all persistent state.
|
||||||
|
Everything else is regenerated by the ``configure`` and ``activate``
|
||||||
|
stages on container start.
|
||||||
|
|
||||||
|
Building the image
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Clone the repository and build the Docker image::
|
||||||
|
|
||||||
|
git clone https://github.com/chatmail/relay
|
||||||
|
cd relay
|
||||||
|
docker/build.sh
|
||||||
|
|
||||||
|
The build bakes all binaries, Python packages, and the install stage
|
||||||
|
into the image. After building, only the ``docker/`` directory and a ``.env``
|
||||||
|
with ``MAIL_DOMAIN`` are needed to run the container. The `build.sh` passes the
|
||||||
|
git hash onto the docker build so it can be determined if there has been a
|
||||||
|
change that warrants a redeploy.
|
||||||
|
|
||||||
|
You can transfer a locally built image to your server directly (pigz is parallel `gzip` which can be used instead as well) ::
|
||||||
|
|
||||||
|
docker save chatmail-relay:latest | pigz | ssh chat.example.org 'pigz -d | docker load'
|
||||||
|
|
||||||
|
|
||||||
|
Forcing a full reinstall
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
On container start, only the ``configure`` and ``activate`` stages run by default.
|
||||||
|
|
||||||
|
To force a full reinstall (e.g. after updating the source), either
|
||||||
|
rebuild the image::
|
||||||
|
|
||||||
|
docker compose build chatmail
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
Or override the stages at runtime without rebuilding::
|
||||||
|
|
||||||
|
CMDEPLOY_STAGES="install,configure,activate" docker compose up -d
|
||||||
@@ -102,8 +102,7 @@ Docker installation
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
There is experimental support for running chatmail via Docker Compose.
|
There is experimental support for running chatmail via Docker Compose.
|
||||||
See the `chatmail/docker README <https://github.com/chatmail/docker>`_
|
See :doc:`docker` for full setup instructions.
|
||||||
for full setup instructions.
|
|
||||||
|
|
||||||
Other helpful commands
|
Other helpful commands
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Contributions and feedback welcome through the https://github.com/chatmail/relay
|
|||||||
:maxdepth: 5
|
:maxdepth: 5
|
||||||
|
|
||||||
getting_started
|
getting_started
|
||||||
|
docker
|
||||||
proxy
|
proxy
|
||||||
migrate
|
migrate
|
||||||
overview
|
overview
|
||||||
|
|||||||
9
docker/build.sh
Executable file
9
docker/build.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Build the chatmail Docker image with the current git hash baked in.
|
||||||
|
# Usage: ./docker/build.sh [extra docker-compose build args...]
|
||||||
|
#
|
||||||
|
# .git/ is excluded from the build context (.dockerignore) so the hash
|
||||||
|
# must be passed as a build arg from the host.
|
||||||
|
|
||||||
|
export GIT_HASH=$(git rev-parse HEAD)
|
||||||
|
exec docker compose -f docker/docker-compose.yaml build "$@"
|
||||||
14
docker/chatmail-init.service
Normal file
14
docker/chatmail-init.service
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run container setup commands
|
||||||
|
After=multi-user.target
|
||||||
|
ConditionPathExists=/chatmail-init.sh
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/bash /chatmail-init.sh
|
||||||
|
RemainAfterExit=true
|
||||||
|
WorkingDirectory=/opt/chatmail
|
||||||
|
PassEnvironment=<envs_list>
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
85
docker/chatmail-init.sh
Executable file
85
docker/chatmail-init.sh
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
export CHATMAIL_INI="${CHATMAIL_INI:-/etc/chatmail/chatmail.ini}"
|
||||||
|
|
||||||
|
CMDEPLOY=/opt/cmdeploy/bin/cmdeploy
|
||||||
|
|
||||||
|
if [ -z "$MAIL_DOMAIN" ]; then
|
||||||
|
echo "ERROR: Environment variable 'MAIL_DOMAIN' must be set!" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate DKIM keys if not mounted
|
||||||
|
if [ ! -f /etc/dkimkeys/opendkim.private ]; then
|
||||||
|
/usr/sbin/opendkim-genkey -D /etc/dkimkeys -d "$MAIL_DOMAIN" -s opendkim
|
||||||
|
fi
|
||||||
|
# Fix ownership for bind-mounted keys (host opendkim UID may differ from container)
|
||||||
|
chown -R opendkim:opendkim /etc/dkimkeys
|
||||||
|
|
||||||
|
# Create chatmail.ini, skip if mounted
|
||||||
|
mkdir -p "$(dirname "$CHATMAIL_INI")"
|
||||||
|
if [ ! -f "$CHATMAIL_INI" ]; then
|
||||||
|
$CMDEPLOY init --config "$CHATMAIL_INI" "$MAIL_DOMAIN"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Auto-detect IPv6: if the host has no IPv6 connectivity, set disable_ipv6
|
||||||
|
# in the ini so dovecot/postfix/nginx bind to IPv4 only.
|
||||||
|
# Uses network_mode:host so /proc/net/if_inet6 reflects the host's stack.
|
||||||
|
if [ ! -e /proc/net/if_inet6 ]; then
|
||||||
|
if grep -q '^disable_ipv6 = False' "$CHATMAIL_INI"; then
|
||||||
|
sed -i 's/^disable_ipv6 = False/disable_ipv6 = True/' "$CHATMAIL_INI"
|
||||||
|
echo "[INFO] IPv6 not available, set disable_ipv6 = True"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Inject external TLS paths from env var unless defined in chatmail.ini
|
||||||
|
if [ -n "${TLS_EXTERNAL_CERT_AND_KEY:-}" ]; then
|
||||||
|
if ! grep -q '^tls_external_cert_and_key' "$CHATMAIL_INI"; then
|
||||||
|
echo "tls_external_cert_and_key = $TLS_EXTERNAL_CERT_AND_KEY" >> "$CHATMAIL_INI"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure mailboxes directory exists (chatmail-metadata needs it at startup,
|
||||||
|
# but Dovecot only creates it on first mail delivery)
|
||||||
|
mkdir -p "/home/vmail/mail/${MAIL_DOMAIN}"
|
||||||
|
chown vmail:vmail "/home/vmail/mail/${MAIL_DOMAIN}"
|
||||||
|
|
||||||
|
# --- Deploy fingerprint: skip cmdeploy run if nothing changed ---
|
||||||
|
# On restart with identical image+config, systemd already brings up all
|
||||||
|
# enabled services only configure+activate are needed here.
|
||||||
|
IMAGE_VERSION_FILE="/etc/chatmail-image-version"
|
||||||
|
FINGERPRINT_FILE="/etc/chatmail/.deploy-fingerprint"
|
||||||
|
image_ver="none"
|
||||||
|
[ -f "$IMAGE_VERSION_FILE" ] && image_ver=$(cat "$IMAGE_VERSION_FILE")
|
||||||
|
config_hash=$(sha256sum "$CHATMAIL_INI" | cut -c1-16)
|
||||||
|
current_fp="${image_ver}:${config_hash}"
|
||||||
|
|
||||||
|
# CMDEPLOY_STAGES non-empty in env = operator override -> always run.
|
||||||
|
# Otherwise, if fingerprint matches the last successful deploy, skip.
|
||||||
|
if [ -z "${CMDEPLOY_STAGES:-}" ] \
|
||||||
|
&& [ -f "$FINGERPRINT_FILE" ] \
|
||||||
|
&& [ "$(cat "$FINGERPRINT_FILE")" = "$current_fp" ]; then
|
||||||
|
echo "[INFO] No changes detected ($current_fp), skipping deploy."
|
||||||
|
else
|
||||||
|
export CMDEPLOY_STAGES="${CMDEPLOY_STAGES:-configure,activate}"
|
||||||
|
|
||||||
|
# Skip DNS check when MAIL_DOMAIN is a bare IP address
|
||||||
|
SKIP_DNS=""
|
||||||
|
if [[ "$MAIL_DOMAIN" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$MAIL_DOMAIN" =~ : ]]; then
|
||||||
|
SKIP_DNS="--skip-dns-check"
|
||||||
|
fi
|
||||||
|
$CMDEPLOY run --config "$CHATMAIL_INI" --ssh-host @local $SKIP_DNS
|
||||||
|
|
||||||
|
# Restore the build-time hash
|
||||||
|
cp /etc/chatmail-image-version /etc/chatmail-version
|
||||||
|
echo "$current_fp" > "$FINGERPRINT_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Signal success to Docker healthcheck
|
||||||
|
touch /run/chatmail-init.done
|
||||||
|
|
||||||
|
# Forward journald to console so `docker compose logs` works
|
||||||
|
grep -q '^ForwardToConsole=yes' /etc/systemd/journald.conf \
|
||||||
|
|| echo "ForwardToConsole=yes" >> /etc/systemd/journald.conf
|
||||||
|
systemctl restart systemd-journald
|
||||||
108
docker/chatmail_relay.dockerfile
Normal file
108
docker/chatmail_relay.dockerfile
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM jrei/systemd-debian:12 AS base
|
||||||
|
|
||||||
|
ENV LANG=en_US.UTF-8
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
|
||||||
|
echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommend && \
|
||||||
|
echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/01norecommend && \
|
||||||
|
apt-get update && \
|
||||||
|
DEBIAN_FRONTEND=noninteractive TZ=UTC \
|
||||||
|
apt-get install -y \
|
||||||
|
ca-certificates \
|
||||||
|
gcc \
|
||||||
|
git \
|
||||||
|
python3 \
|
||||||
|
python3-dev \
|
||||||
|
python3-venv \
|
||||||
|
tzdata \
|
||||||
|
locales && \
|
||||||
|
sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale.gen && \
|
||||||
|
dpkg-reconfigure --frontend=noninteractive locales && \
|
||||||
|
update-locale LANG=$LANG
|
||||||
|
|
||||||
|
# --- Build-time: install cmdeploy venv and run install stage ---
|
||||||
|
# Editable install so importlib.resources reads directly from the source tree.
|
||||||
|
# On container start only "configure,activate" stages run.
|
||||||
|
|
||||||
|
# Copy dependency metadata first so pip install layer is cached
|
||||||
|
COPY cmdeploy/pyproject.toml /opt/chatmail/cmdeploy/pyproject.toml
|
||||||
|
COPY chatmaild/pyproject.toml /opt/chatmail/chatmaild/pyproject.toml
|
||||||
|
|
||||||
|
# Dummy scaffolding so editable install can discover packages
|
||||||
|
RUN mkdir -p /opt/chatmail/cmdeploy/src/cmdeploy \
|
||||||
|
/opt/chatmail/chatmaild/src/chatmaild && \
|
||||||
|
touch /opt/chatmail/cmdeploy/src/cmdeploy/__init__.py \
|
||||||
|
/opt/chatmail/chatmaild/src/chatmaild/__init__.py
|
||||||
|
|
||||||
|
# Dummy git repo: .git/ is excluded from the build context (.dockerignore)
|
||||||
|
# but setuptools calls `git ls-files` when building the sdist.
|
||||||
|
WORKDIR /opt/chatmail
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
git init -q && \
|
||||||
|
python3 -m venv /opt/cmdeploy && \
|
||||||
|
/opt/cmdeploy/bin/pip install -e chatmaild/ -e cmdeploy/
|
||||||
|
|
||||||
|
# Full source copy (editable install's .egg-link still points here)
|
||||||
|
COPY . /opt/chatmail/
|
||||||
|
|
||||||
|
# Minimal chatmail.ini
|
||||||
|
RUN printf '[params]\nmail_domain = build.local\n' > /tmp/chatmail.ini
|
||||||
|
|
||||||
|
RUN CMDEPLOY_STAGES=install \
|
||||||
|
CHATMAIL_INI=/tmp/chatmail.ini \
|
||||||
|
/opt/cmdeploy/bin/pyinfra @local \
|
||||||
|
/opt/chatmail/cmdeploy/src/cmdeploy/run.py -y
|
||||||
|
|
||||||
|
RUN cp -a www/ /opt/chatmail-www/
|
||||||
|
|
||||||
|
# Remove build-only packages — not needed at runtime.
|
||||||
|
# Keep git: test_deployed_state needs `git rev-parse HEAD` to verify the
|
||||||
|
# deployed version hash matches /etc/chatmail-version.
|
||||||
|
RUN apt-get purge -y gcc python3-dev && \
|
||||||
|
apt-get autoremove -y && \
|
||||||
|
rm -f /tmp/chatmail.ini
|
||||||
|
|
||||||
|
# Record image version (used in deploy fingerprint at runtime).
|
||||||
|
# GIT_HASH is passed as a build arg (from docker-compose or CI) so that
|
||||||
|
# .git/ can be excluded from the build context via .dockerignore.
|
||||||
|
# Two files: chatmail-image-version is the immutable build hash (survives
|
||||||
|
# deploys); chatmail-version is overwritten by cmdeploy run and restored
|
||||||
|
# from the image version after each deploy in chatmail-init.sh.
|
||||||
|
ARG GIT_HASH=unknown
|
||||||
|
RUN echo "$GIT_HASH" > /etc/chatmail-image-version && \
|
||||||
|
echo "$GIT_HASH" > /etc/chatmail-version
|
||||||
|
|
||||||
|
# Mock git HEAD so `git rev-parse HEAD` returns the source repo's commit hash.
|
||||||
|
# The .git/ dir was created by `git init` earlier (for setuptools); we just
|
||||||
|
# write the build hash into whatever branch HEAD points to.
|
||||||
|
RUN head_ref=$(sed 's/^ref: //' /opt/chatmail/.git/HEAD) && \
|
||||||
|
mkdir -p "/opt/chatmail/.git/$(dirname "$head_ref")" && \
|
||||||
|
echo "$GIT_HASH" > "/opt/chatmail/.git/$head_ref"
|
||||||
|
# --- End build-time install ---
|
||||||
|
|
||||||
|
ENV TZ=:/etc/localtime
|
||||||
|
ENV PATH="/opt/cmdeploy/bin:${PATH}"
|
||||||
|
RUN ln -s /etc/chatmail/chatmail.ini /opt/chatmail/chatmail.ini
|
||||||
|
|
||||||
|
ARG CHATMAIL_INIT_SERVICE_PATH=/lib/systemd/system/chatmail-init.service
|
||||||
|
COPY ./docker/chatmail-init.service "$CHATMAIL_INIT_SERVICE_PATH"
|
||||||
|
RUN ln -sf "$CHATMAIL_INIT_SERVICE_PATH" "/etc/systemd/system/multi-user.target.wants/chatmail-init.service"
|
||||||
|
|
||||||
|
# Remove default nginx site config at build time (not in entrypoint)
|
||||||
|
RUN rm -f /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
|
COPY --chmod=555 ./docker/chatmail-init.sh /chatmail-init.sh
|
||||||
|
COPY --chmod=555 ./docker/entrypoint.sh /entrypoint.sh
|
||||||
|
COPY --chmod=555 ./docker/healthcheck.sh /healthcheck.sh
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=10s --start-period=180s --timeout=10s --retries=3 \
|
||||||
|
CMD /healthcheck.sh
|
||||||
|
|
||||||
|
STOPSIGNAL SIGRTMIN+3
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
|
CMD [ "--default-standard-output=journal+console", \
|
||||||
|
"--default-standard-error=journal+console" ]
|
||||||
70
docker/docker-compose-traefik.yaml
Normal file
70
docker/docker-compose-traefik.yaml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Traefik reverse-proxy example — use as a compose override:
|
||||||
|
#
|
||||||
|
# docker compose -f docker-compose.yaml -f docker-compose-traefik.yaml up -d
|
||||||
|
#
|
||||||
|
# Traefik handles HTTP→HTTPS redirect and ACME certificate issuance.
|
||||||
|
# traefik-certs-dumper extracts the certificates to the filesystem so
|
||||||
|
# chatmail's Postfix/Dovecot/nginx can use them via TLS_EXTERNAL_CERT_AND_KEY.
|
||||||
|
#
|
||||||
|
# Prerequisites:
|
||||||
|
# mkdir -p traefik/data traefik/dynamic-configs
|
||||||
|
# touch traefik/data/acme.json && chmod 600 traefik/data/acme.json
|
||||||
|
# cp traefik/config.yaml.example traefik/config.yaml # see below
|
||||||
|
#
|
||||||
|
# Required .env variables (in addition to MAIL_DOMAIN):
|
||||||
|
# ACME_EMAIL=admin@example.org
|
||||||
|
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
environment:
|
||||||
|
# Point chatmail at the certs dumped by traefik-certs-dumper.
|
||||||
|
# The container's tls-cert-reload.path watches for changes.
|
||||||
|
TLS_EXTERNAL_CERT_AND_KEY: >-
|
||||||
|
/traefik-certs/${MAIL_DOMAIN}/certificate.crt
|
||||||
|
/traefik-certs/${MAIL_DOMAIN}/privatekey.key
|
||||||
|
volumes:
|
||||||
|
- traefik-certs:/traefik-certs:ro
|
||||||
|
depends_on:
|
||||||
|
- traefik-certs-dumper
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.http.services.chatmail.loadbalancer.server.scheme=https
|
||||||
|
- traefik.http.services.chatmail.loadbalancer.server.port=443
|
||||||
|
- traefik.http.routers.chatmail.rule=Host(`${MAIL_DOMAIN}`) || Host(`mta-sts.${MAIL_DOMAIN}`) || Host(`www.${MAIL_DOMAIN}`)
|
||||||
|
- traefik.http.routers.chatmail.tls=true
|
||||||
|
- traefik.http.routers.chatmail.tls.certresolver=letsEncrypt
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
image: traefik:v3.3
|
||||||
|
container_name: traefik
|
||||||
|
restart: unless-stopped
|
||||||
|
network_mode: host
|
||||||
|
command:
|
||||||
|
- "--configFile=/config.yaml"
|
||||||
|
- "--certificatesresolvers.letsEncrypt.acme.email=${ACME_EMAIL}"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
- ./traefik/config.yaml:/config.yaml:ro
|
||||||
|
- ./traefik/data/acme.json:/acme.json
|
||||||
|
- ./traefik/dynamic-configs:/dynamic/conf:ro
|
||||||
|
|
||||||
|
traefik-certs-dumper:
|
||||||
|
image: ldez/traefik-certs-dumper:v2.10.0
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- traefik
|
||||||
|
entrypoint: sh -c '
|
||||||
|
apk add openssl
|
||||||
|
&& while ! [ -e /data/acme.json ]
|
||||||
|
|| ! [ $$(jq ".[] | .Certificates | length" /data/acme.json | jq -s "add") != 0 ]; do
|
||||||
|
sleep 1;
|
||||||
|
done
|
||||||
|
&& traefik-certs-dumper file
|
||||||
|
--version v3 --watch --domain-subdir=true
|
||||||
|
--source /data/acme.json --dest /certs'
|
||||||
|
volumes:
|
||||||
|
- ./traefik/data/acme.json:/data/acme.json:ro
|
||||||
|
- traefik-certs:/certs
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
traefik-certs:
|
||||||
11
docker/docker-compose.ci.yaml
Normal file
11
docker/docker-compose.ci.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Used by .github/workflows/docker-ci.yaml
|
||||||
|
# The GHCR image is set via CHATMAIL_IMAGE env var at deploy time.
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
image: ${CHATMAIL_IMAGE:-chatmail-relay:latest}
|
||||||
|
volumes:
|
||||||
|
- /srv/chatmail/chatmail.ini:/etc/chatmail/chatmail.ini
|
||||||
|
- /srv/chatmail/dkim:/etc/dkimkeys
|
||||||
|
- /srv/chatmail/certs:/var/lib/acme
|
||||||
|
environment:
|
||||||
|
TLS_EXTERNAL_CERT_AND_KEY: /var/lib/acme/live/${MAIL_DOMAIN}/fullchain /var/lib/acme/live/${MAIL_DOMAIN}/privkey
|
||||||
44
docker/docker-compose.override.yaml.example
Normal file
44
docker/docker-compose.override.yaml.example
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Local overrides: copy to docker-compose.override.yaml in this directory.
|
||||||
|
# Compose automatically merges this with docker-compose.yaml.
|
||||||
|
#
|
||||||
|
# cp docker-compose.override.yaml.example docker-compose.override.yaml
|
||||||
|
#
|
||||||
|
# Volumes are APPENDED to the base file's volumes list, environment and other scalar keys are MERGED by key.
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
volumes:
|
||||||
|
## Data paths — bind-mount to host directories for easy access/backup.
|
||||||
|
|
||||||
|
# - ./data/dkim:/etc/dkimkeys
|
||||||
|
# - ./data/certs:/var/lib/acme
|
||||||
|
|
||||||
|
# - ./data/mail:/home/vmail
|
||||||
|
## Or mount from an existing bare-metal install.
|
||||||
|
# - /home/vmail:/home/vmail
|
||||||
|
|
||||||
|
## Mount your own chatmail.ini (skips auto-generation):
|
||||||
|
# - ./chatmail.ini:/etc/chatmail/chatmail.ini
|
||||||
|
|
||||||
|
## Custom website:
|
||||||
|
# - ./custom/www:/opt/chatmail-www
|
||||||
|
|
||||||
|
## Debug — mount scripts for live editing:
|
||||||
|
# - ./chatmail-init.sh:/chatmail-init.sh
|
||||||
|
# - ./entrypoint.sh:/entrypoint.sh
|
||||||
|
|
||||||
|
# environment:
|
||||||
|
## Mount certs (above) and set TLS_EXTERNAL_CERT_AND_KEY to in-container paths.
|
||||||
|
## A tls-cert-reload.path watcher inside the container reloads services
|
||||||
|
## when the cert file changes. However, inotify does not cross bind-mount
|
||||||
|
## boundaries, so host-side renewals (certbot, acmetool, etc.) must
|
||||||
|
## notify the container explicitly. Add this to your renewal hook:
|
||||||
|
##
|
||||||
|
## docker exec chatmail systemctl start tls-cert-reload.service
|
||||||
|
##
|
||||||
|
## Host acmetool (bare-metal migration): create mount above, and
|
||||||
|
## rsync -a /var/lib/acme/live data/certs
|
||||||
|
# TLS_EXTERNAL_CERT_AND_KEY: "/var/lib/acme/live/${MAIL_DOMAIN}/fullchain /var/lib/acme/live/${MAIL_DOMAIN}/privkey"
|
||||||
|
##
|
||||||
|
## (Untested) Traefik certs-dumper (see docker/docker-compose-traefik.yaml) - also add volume:
|
||||||
|
## - traefik-certs:/certs:ro
|
||||||
|
# TLS_EXTERNAL_CERT_AND_KEY: "/certs/${MAIL_DOMAIN}/certificate.crt /certs/${MAIL_DOMAIN}/privatekey.key"
|
||||||
48
docker/docker-compose.yaml
Normal file
48
docker/docker-compose.yaml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Base compose file — do not edit. Put customizations (data paths, extra
|
||||||
|
# volumes, env overrides) in docker-compose.override.yaml instead.
|
||||||
|
# See docker-compose.override.yaml.example in this directory for a starting point.
|
||||||
|
#
|
||||||
|
# Security notes: this container uses
|
||||||
|
# - network_mode:host chatmail needs many ports (25, 53, 80, 143, 443, 465,
|
||||||
|
# 587, 993, 3340, 8443) and needs to operate from the real IP, which bridging
|
||||||
|
# would make tricky
|
||||||
|
# - cgroup:host (required for systemd).
|
||||||
|
# Together these give the container near-host-level access. This is acceptable
|
||||||
|
# for a dedicated mail server, but be aware that the container can bind any
|
||||||
|
# port and see all host network traffic.
|
||||||
|
|
||||||
|
services:
|
||||||
|
chatmail:
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: docker/chatmail_relay.dockerfile
|
||||||
|
args:
|
||||||
|
GIT_HASH: ${GIT_HASH:-unknown}
|
||||||
|
image: chatmail-relay:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
container_name: chatmail
|
||||||
|
# Required for systemd — use only one of the following:
|
||||||
|
cgroup: host # compose v2
|
||||||
|
# privileged: true # compose v1 (less restricted)
|
||||||
|
tty: true # required for logs
|
||||||
|
tmpfs: # required for systemd
|
||||||
|
- /tmp
|
||||||
|
- /run
|
||||||
|
- /run/lock
|
||||||
|
logging:
|
||||||
|
driver: none
|
||||||
|
environment:
|
||||||
|
MAIL_DOMAIN: $MAIL_DOMAIN
|
||||||
|
network_mode: "host"
|
||||||
|
volumes:
|
||||||
|
## system (required)
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
## data (defaults — override in docker-compose.override.yaml)
|
||||||
|
- mail:/home/vmail
|
||||||
|
- dkim:/etc/dkimkeys
|
||||||
|
- certs:/var/lib/acme
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mail:
|
||||||
|
dkim:
|
||||||
|
certs:
|
||||||
9
docker/entrypoint.sh
Executable file
9
docker/entrypoint.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
CHATMAIL_INIT_SERVICE_PATH="${CHATMAIL_INIT_SERVICE_PATH:-/lib/systemd/system/chatmail-init.service}"
|
||||||
|
|
||||||
|
env_vars="MAIL_DOMAIN CMDEPLOY_STAGES CHATMAIL_INI TLS_EXTERNAL_CERT_AND_KEY PATH"
|
||||||
|
sed -i "s|<envs_list>|$env_vars|g" "$CHATMAIL_INIT_SERVICE_PATH"
|
||||||
|
|
||||||
|
exec /lib/systemd/systemd "$@"
|
||||||
1
docker/env.example
Normal file
1
docker/env.example
Normal file
@@ -0,0 +1 @@
|
|||||||
|
MAIL_DOMAIN=chat.example.com
|
||||||
16
docker/healthcheck.sh
Normal file
16
docker/healthcheck.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# returns 0 when chatmail-init succeeded and all expected services are running.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
test -f /run/chatmail-init.done
|
||||||
|
|
||||||
|
# Core services
|
||||||
|
services="chatmail-metadata doveauth dovecot filtermail filtermail-incoming nginx postfix unbound"
|
||||||
|
|
||||||
|
# Optional services
|
||||||
|
for svc in iroh-relay turnserver; do
|
||||||
|
systemctl is-enabled "$svc" 2>/dev/null && services="$services $svc"
|
||||||
|
done
|
||||||
|
|
||||||
|
exec systemctl is-active $services
|
||||||
Reference in New Issue
Block a user