Skip to content

Commit 6bf0887

Browse files
authored
Merge pull request #1073 from systemli/improve-docker-dovecot-setup
♻️ Improve docker dovecot setup and mailcrypt integration
2 parents 35d1b0b + c2c1a51 commit 6bf0887

File tree

8 files changed

+300
-70
lines changed

8 files changed

+300
-70
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ indent_style = space
99
insert_final_newline = true
1010
trim_trailing_whitespace = true
1111

12-
[{docker-compose.yml,docker-compose.*.yml}]
12+
[{docker-compose.yml,docker-compose.*.yml,.github/workflows/*.yml}]
1313
indent_size = 2
1414

1515
[*.md]

.github/workflows/mailcrypt.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Mailcrypt
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "contrib/userli-dovecot-adapter.lua"
7+
- "docker/dovecot/**"
8+
- "docker-compose.mailcrypt-test.yml"
9+
- "tests/test_mailcrypt.sh"
10+
- "tests/dovecot-api-mock.py"
11+
- ".github/workflows/mailcrypt.yml"
12+
push:
13+
branches:
14+
- main
15+
paths:
16+
- "contrib/userli-dovecot-adapter.lua"
17+
- "docker/dovecot/**"
18+
- "docker-compose.mailcrypt-test.yml"
19+
- "tests/test_mailcrypt.sh"
20+
- "tests/dovecot-api-mock.py"
21+
- ".github/workflows/mailcrypt.yml"
22+
23+
jobs:
24+
mailcrypt:
25+
runs-on: ubuntu-24.04
26+
name: Dovecot Mailcrypt Integration
27+
28+
env:
29+
COMPOSE_FILE: docker-compose.mailcrypt-test.yml
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v6
34+
35+
- name: Start containers
36+
run: docker compose up -d
37+
38+
- name: Wait for Dovecot to be ready
39+
run: |
40+
for i in $(seq 1 30); do
41+
if docker compose exec dovecot doveadm service status imap-login > /dev/null 2>&1; then
42+
echo "Dovecot is ready"
43+
break
44+
fi
45+
echo "Waiting for Dovecot... ($i/30)"
46+
sleep 2
47+
done
48+
49+
- name: Run mailcrypt tests
50+
run: bash tests/mailcrypt_integration.sh
51+
52+
- name: Dovecot logs
53+
if: failure()
54+
run: docker compose logs dovecot
55+
56+
- name: Mock API logs
57+
if: failure()
58+
run: docker compose logs mock-api
59+
60+
- name: Stop containers
61+
if: always()
62+
run: docker compose down -v

docker-compose.mailcrypt-test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
# Minimal compose file for mailcrypt integration tests.
3+
# Starts only dovecot, a mock Userli API, and a tools container.
4+
#
5+
# Usage:
6+
# docker compose -f docker-compose.mailcrypt-test.yml up -d
7+
# bash tests/mailcrypt_integration.sh
8+
# docker compose -f docker-compose.mailcrypt-test.yml down -v
9+
10+
services:
11+
dovecot:
12+
depends_on:
13+
mock-api:
14+
condition: service_healthy
15+
image: dovecot/dovecot:latest
16+
environment:
17+
MAIL_CRYPT: 2
18+
USERLI_HOST: mock-api
19+
USERLI_API_ACCESS_TOKEN: 727eb7d3ad310bc510f5fa17c223572c
20+
DOVECOT_LUA_INSECURE: "true"
21+
ports:
22+
- "1143:31143"
23+
volumes:
24+
- vmail:/srv/vmail
25+
- ./docker/dovecot/dovecot.conf:/etc/dovecot/dovecot.conf:ro
26+
- ./docker/dovecot/conf.d:/etc/dovecot/conf.d:ro
27+
- ./contrib/userli-dovecot-adapter.lua:/usr/local/bin/userli-dovecot-adapter.lua:ro
28+
29+
mock-api:
30+
image: docker.io/python:3-alpine
31+
working_dir: /app
32+
command: python dovecot-api-mock.py 80
33+
volumes:
34+
- ./tests/dovecot-api-mock.py:/app/dovecot-api-mock.py:ro
35+
healthcheck:
36+
test:
37+
[
38+
"CMD",
39+
"python",
40+
"-c",
41+
"import urllib.request as u; u.urlopen(u.Request('http://localhost/api/dovecot/status', headers={'Authorization': 'Bearer 727eb7d3ad310bc510f5fa17c223572c'}))",
42+
]
43+
interval: 2s
44+
timeout: 3s
45+
retries: 5
46+
47+
tools:
48+
image: busybox:stable
49+
profiles:
50+
- tools
51+
volumes:
52+
- vmail:/srv/vmail:ro
53+
54+
volumes:
55+
vmail:

docker-compose.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ services:
6565
- userli
6666

6767
dovecot:
68-
build:
69-
context: .
70-
dockerfile: docker/dovecot/Dockerfile
68+
depends_on:
69+
- userli
70+
image: dovecot/dovecot:2.4.2
7171
environment:
7272
MAIL_CRYPT: 2
7373
USERLI_HOST: userli
7474
USERLI_API_ACCESS_TOKEN: 727eb7d3ad310bc510f5fa17c223572c
7575
DOVECOT_LUA_INSECURE: "true"
7676
ports:
77-
- "1143:143"
77+
- "1143:31143"
7878
volumes:
79-
- vmail:/var/vmail
79+
- vmail:/srv/vmail
8080
- ./docker/dovecot/dovecot.conf:/etc/dovecot/dovecot.conf:ro
8181
- ./docker/dovecot/conf.d:/etc/dovecot/conf.d:ro
8282
- ./contrib/userli-dovecot-adapter.lua:/usr/local/bin/userli-dovecot-adapter.lua:ro
@@ -96,9 +96,12 @@ services:
9696

9797
roundcube:
9898
image: docker.io/roundcube/roundcubemail:1.6.11-apache
99+
depends_on:
100+
- dovecot
101+
- mailcatcher
99102
environment:
100103
ROUNDCUBEMAIL_DEFAULT_HOST: dovecot
101-
ROUNDCUBEMAIL_DEFAULT_PORT: 143
104+
ROUNDCUBEMAIL_DEFAULT_PORT: 31143
102105
ROUNDCUBEMAIL_SMTP_SERVER: smtp://mailcatcher
103106
ROUNDCUBEMAIL_SMTP_PORT: 1025
104107
ROUNDCUBEMAIL_USERNAME_DOMAIN: example.org
@@ -127,6 +130,15 @@ services:
127130
networks:
128131
- userli
129132

133+
tools:
134+
image: busybox:stable
135+
profiles:
136+
- tools
137+
volumes:
138+
- vmail:/srv/vmail:ro
139+
networks:
140+
- userli
141+
130142
networks:
131143
userli:
132144

docker/dovecot/Dockerfile

Lines changed: 0 additions & 42 deletions
This file was deleted.

docker/dovecot/dovecot.conf

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
## You should mount /etc/dovecot if you want to
2-
## manage this file
1+
## Userli Dovecot configuration
2+
## Mounted into the official dovecot/dovecot Docker image
33

4-
dovecot_config_version = 2.4.0
5-
dovecot_storage_version = 2.4.0
4+
dovecot_config_version = 2.4.2
5+
dovecot_storage_version = 2.4.2
66

7-
mail_home = /var/vmail/%{user|username|lower}
7+
default_login_user = vmail
8+
default_internal_user = vmail
9+
default_internal_group = vmail
10+
11+
mail_home = /srv/vmail/%{user|username|lower}
812
mail_driver = sdbox
913
mail_path = ~/Mail
10-
mail_uid = 5000
11-
mail_gid = 5000
14+
mail_uid = vmail
15+
mail_gid = vmail
1216

1317
mail_plugins {
1418
mail_crypt = yes
@@ -17,12 +21,13 @@ crypt_write_algorithm =
1721

1822
protocols = imap pop3 submission sieve lmtp
1923

20-
first_valid_uid = 5000
21-
last_valid_uid = 5000
24+
first_valid_uid = 1000
25+
last_valid_uid = 1000
2226

23-
ssl = yes
24-
ssl_server_cert_file = cert.pem
25-
ssl_server_key_file = key.pem
27+
ssl_server {
28+
cert_file = /etc/dovecot/ssl/tls.crt
29+
key_file = /etc/dovecot/ssl/tls.key
30+
}
2631

2732
namespace inbox {
2833
inbox = yes
@@ -40,13 +45,17 @@ namespace inbox {
4045

4146
service lmtp {
4247
inet_listener lmtp {
43-
port = 24
48+
port = 31024
4449
}
4550
}
4651

4752
service imap-login {
4853
process_min_avail = 1
4954
client_limit = 1000
55+
56+
inet_listener imap {
57+
port = 31143
58+
}
5059
}
5160

5261
service pop3-login {
@@ -66,9 +75,9 @@ service managesieve-login {
6675

6776
listen = *
6877

69-
log_path=/dev/stdout
70-
info_log_path=/dev/stdout
71-
debug_log_path=/dev/stdout
78+
log_path = /dev/stdout
79+
info_log_path = /dev/stdout
80+
debug_log_path = /dev/stdout
7281

7382
verbose_proctitle = yes
7483

0 commit comments

Comments
 (0)