-
-
Notifications
You must be signed in to change notification settings - Fork 39
Rebased PR: add docker compose for installing a chatmail relay #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
97dd5dc
5c12f3b
57598db
c83d1cf
54e268f
ce2b536
c7a3168
128cca0
c0efe81
a67184c
ea53327
c1c07de
8537a07
8541139
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,3 +164,9 @@ cython_debug/ | |
| #.idea/ | ||
|
|
||
| chatmail.zone | ||
|
|
||
| # docker | ||
| /data/ | ||
| /custom/ | ||
| docker-compose.yaml | ||
| .env | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| FROM jrei/systemd-debian:12 AS base | ||
|
|
||
| ENV LANG=en_US.UTF-8 | ||
|
|
||
| RUN 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 && \ | ||
| apt-get install -y \ | ||
| ca-certificates && \ | ||
| DEBIAN_FRONTEND=noninteractive \ | ||
| TZ=Europe/London \ | ||
| apt-get install -y tzdata && \ | ||
| apt-get install -y locales && \ | ||
| sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale.gen && \ | ||
| dpkg-reconfigure --frontend=noninteractive locales && \ | ||
| update-locale LANG=$LANG \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install -y \ | ||
| git \ | ||
| python3 \ | ||
| python3-venv \ | ||
| python3-virtualenv \ | ||
| gcc \ | ||
| python3-dev \ | ||
| opendkim \ | ||
| opendkim-tools \ | ||
| curl \ | ||
| rsync \ | ||
| unbound \ | ||
| unbound-anchor \ | ||
| dnsutils \ | ||
| postfix \ | ||
| acl \ | ||
| nginx \ | ||
| libnginx-mod-stream \ | ||
| fcgiwrap \ | ||
| cron \ | ||
| && for pkg in core imapd lmtpd; do \ | ||
| case "$pkg" in \ | ||
| core) sha256="43f593332e22ac7701c62d58b575d2ca409e0f64857a2803be886c22860f5587" ;; \ | ||
| imapd) sha256="8d8dc6fc00bbb6cdb25d345844f41ce2f1c53f764b79a838eb2a03103eebfa86" ;; \ | ||
| lmtpd) sha256="2f69ba5e35363de50962d42cccbfe4ed8495265044e244007d7ccddad77513ab" ;; \ | ||
| esac; \ | ||
| url="https://download.delta.chat/dovecot/dovecot-${pkg}_2.3.21%2Bdfsg1-3_amd64.deb"; \ | ||
| file="/tmp/$(basename "$url")"; \ | ||
| curl -fsSL "$url" -o "$file"; \ | ||
| echo "$sha256 $file" | sha256sum -c -; \ | ||
| apt-get install -y "$file"; \ | ||
| rm -f "$file"; \ | ||
| done \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /opt/chatmail | ||
|
|
||
| ARG SETUP_CHATMAIL_SERVICE_PATH=/lib/systemd/system/setup_chatmail.service | ||
| COPY ./files/setup_chatmail.service "$SETUP_CHATMAIL_SERVICE_PATH" | ||
| RUN ln -sf "$SETUP_CHATMAIL_SERVICE_PATH" "/etc/systemd/system/multi-user.target.wants/setup_chatmail.service" | ||
|
|
||
| COPY --chmod=555 ./files/setup_chatmail_docker.sh /setup_chatmail_docker.sh | ||
| COPY --chmod=555 ./files/update_ini.sh /update_ini.sh | ||
| COPY --chmod=555 ./files/entrypoint.sh /entrypoint.sh | ||
|
|
||
| ## TODO: add git clone. | ||
| ## Problem: how correct save only required files inside container.... | ||
| # RUN git clone https://github.com/chatmail/relay.git -b master . \ | ||
| # && ./scripts/initenv.sh | ||
|
|
||
| # EXPOSE 443 25 587 143 993 | ||
|
|
||
| VOLUME ["/sys/fs/cgroup", "/home"] | ||
|
|
||
| STOPSIGNAL SIGRTMIN+3 | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] | ||
|
|
||
| CMD [ "--default-standard-output=journal+console", \ | ||
| "--default-standard-error=journal+console" ] | ||
|
|
||
| ## TODO: Add installation and configuration of chatmaild inside the Dockerfile. | ||
| ## This is required to ensure repeatable deployment. | ||
| ## In the current MVP, the chatmaild server is updated on every container restart. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| services: | ||
| chatmail: | ||
| build: | ||
| context: ./docker | ||
| dockerfile: chatmail_relay.dockerfile | ||
| tags: | ||
| - chatmail-relay:latest | ||
| image: chatmail-relay:latest | ||
| restart: unless-stopped | ||
| container_name: chatmail | ||
| cgroup: host # required for systemd | ||
| tty: true # required for logs | ||
| tmpfs: # required for systemd | ||
| - /tmp | ||
| - /run | ||
| - /run/lock | ||
| logging: | ||
| driver: json-file | ||
| options: | ||
| max-size: "10m" | ||
| max-file: "3" | ||
| environment: | ||
| MAIL_DOMAIN: $MAIL_DOMAIN | ||
| CHANGE_KERNEL_SETTINGS: "False" | ||
| ACME_EMAIL: $ACME_EMAIL | ||
| # RECREATE_VENV: "false" | ||
| # MAX_MESSAGE_SIZE: "50M" | ||
| # DEBUG_COMMANDS_ENABLED: "true" | ||
| # FORCE_REINIT_INI_FILE: "true" | ||
| # USE_FOREIGN_CERT_MANAGER: "True" | ||
| # ENABLE_CERTS_MONITORING: "true" | ||
| # CERTS_MONITORING_TIMEOUT: 10 | ||
| # IS_DEVELOPMENT_INSTANCE: "True" | ||
| ports: | ||
| - "80:80" | ||
| - "443:443" | ||
| - "25:25" | ||
| - "587:587" | ||
| - "143:143" | ||
| - "465:465" | ||
| - "993:993" | ||
| volumes: | ||
| ## system | ||
| - /sys/fs/cgroup:/sys/fs/cgroup:rw # required for systemd | ||
| - ./:/opt/chatmail | ||
|
|
||
| ## data | ||
| - ./data/chatmail:/home | ||
| - ./data/chatmail-dkimkeys:/etc/dkimkeys | ||
| - ./data/chatmail-echobot:/run/echobot | ||
| - ./data/chatmail-acme:/var/lib/acme | ||
|
|
||
| ## custom resources | ||
| # - ./custom/www/src/index.md:/opt/chatmail/www/src/index.md | ||
|
|
||
| ## debug | ||
| # - ./docker/files/setup_chatmail_docker.sh:/setup_chatmail_docker.sh | ||
| # - ./docker/files/entrypoint.sh:/entrypoint.sh | ||
| # - ./docker/files/update_ini.sh:/update_ini.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| MAIL_DOMAIN="chat.example.com" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| set -eo pipefail | ||
|
|
||
| unlink /etc/nginx/sites-enabled/default || true | ||
|
|
||
| SETUP_CHATMAIL_SERVICE_PATH="${SETUP_CHATMAIL_SERVICE_PATH:-/lib/systemd/system/setup_chatmail.service}" | ||
|
|
||
| env_vars=$(printenv | cut -d= -f1 | xargs) | ||
| sed -i "s|<envs_list>|$env_vars|g" $SETUP_CHATMAIL_SERVICE_PATH | ||
|
|
||
| exec /lib/systemd/systemd $@ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [Unit] | ||
| Description=Run container setup commands | ||
| After=multi-user.target | ||
| ConditionPathExists=/setup_chatmail_docker.sh | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/bin/bash /setup_chatmail_docker.sh | ||
| RemainAfterExit=true | ||
| WorkingDirectory=/opt/chatmail | ||
| PassEnvironment=<envs_list> | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| set -eo pipefail | ||||||
| export INI_FILE="${INI_FILE:-chatmail.ini}" | ||||||
| export ENABLE_CERTS_MONITORING="${ENABLE_CERTS_MONITORING:-true}" | ||||||
| export CERTS_MONITORING_TIMEOUT="${CERTS_MONITORING_TIMEOUT:-60}" | ||||||
| export PATH_TO_SSL="${PATH_TO_SSL:-/var/lib/acme/live/${MAIL_DOMAIN}}" | ||||||
| export CHANGE_KERNEL_SETTINGS=${CHANGE_KERNEL_SETTINGS:-"False"} | ||||||
| export RECREATE_VENV=${RECREATE_VENV:-"false"} | ||||||
|
|
||||||
| if [ -z "$MAIL_DOMAIN" ]; then | ||||||
| echo "ERROR: Environment variable 'MAIL_DOMAIN' must be set!" >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| debug_commands() { | ||||||
| echo "Executing debug commands" | ||||||
| # git config --global --add safe.directory /opt/chatmail | ||||||
| # ./scripts/initenv.sh | ||||||
| } | ||||||
|
|
||||||
| calculate_hash() { | ||||||
| find "$PATH_TO_SSL" -type f -exec sha1sum {} \; | sort | sha1sum | awk '{print $1}' | ||||||
| } | ||||||
|
|
||||||
| monitor_certificates() { | ||||||
| if [ "$ENABLE_CERTS_MONITORING" != "true" ]; then | ||||||
| echo "Certs monitoring disabled." | ||||||
| exit 0 | ||||||
| fi | ||||||
|
|
||||||
| current_hash=$(calculate_hash) | ||||||
| previous_hash=$current_hash | ||||||
|
|
||||||
| while true; do | ||||||
| current_hash=$(calculate_hash) | ||||||
| if [[ "$current_hash" != "$previous_hash" ]]; then | ||||||
| # TODO: add an option to restart at a specific time interval | ||||||
| echo "[INFO] Certificate's folder hash was changed, reloading nginx, dovecot and postfix services." | ||||||
| systemctl reload nginx.service | ||||||
| systemctl reload dovecot.service | ||||||
| systemctl reload postfix.service | ||||||
| previous_hash=$current_hash | ||||||
| fi | ||||||
| sleep $CERTS_MONITORING_TIMEOUT | ||||||
| done | ||||||
| } | ||||||
|
|
||||||
| ### MAIN | ||||||
|
|
||||||
| if [ "$DEBUG_COMMANDS_ENABLED" == "true" ]; then | ||||||
| debug_commands | ||||||
| fi | ||||||
|
|
||||||
| if [ "$FORCE_REINIT_INI_FILE" == "true" ]; then | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| INI_CMD_ARGS=--force | ||||||
| fi | ||||||
|
|
||||||
| /usr/sbin/opendkim-genkey -D /etc/dkimkeys -d $MAIL_DOMAIN -s opendkim | ||||||
| chown opendkim:opendkim /etc/dkimkeys/opendkim.private | ||||||
| chown opendkim:opendkim /etc/dkimkeys/opendkim.txt | ||||||
|
|
||||||
| # TODO: Move to debug_commands after git clone is moved to dockerfile. | ||||||
| git config --global --add safe.directory /opt/chatmail | ||||||
| if [ "$RECREATE_VENV" == "true" ]; then | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| rm -rf venv | ||||||
| fi | ||||||
| ./scripts/initenv.sh | ||||||
|
|
||||||
| ./scripts/cmdeploy init --config "${INI_FILE}" $INI_CMD_ARGS $MAIL_DOMAIN | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| bash /update_ini.sh | ||||||
|
|
||||||
| ./scripts/cmdeploy run --ssh-host docker | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| echo "ForwardToConsole=yes" >> /etc/systemd/journald.conf | ||||||
| systemctl restart systemd-journald | ||||||
|
|
||||||
| monitor_certificates & | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.