From ea572cb82a9fe3c6d27a5996f77c7e56617331cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Thu, 2 Jan 2025 16:54:24 +0100 Subject: [PATCH] feat: add support for sending email to the docker image --- docker/Dockerfile.game | 15 ++++++++++++--- docker/compose.yml | 12 +++++++++++- docker/env.example | 15 +++++++++++++++ game/run-lwb5.sh | 24 ++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile.game b/docker/Dockerfile.game index 682b7b5..e7b3752 100644 --- a/docker/Dockerfile.game +++ b/docker/Dockerfile.game @@ -1,6 +1,8 @@ FROM debian:12-slim RUN < /etc/apt/sources.list.d/php.list apt-get update - apt-get install -y apache2 libapache2-mod-php8.3 \ - php8.3-cli php8.3-opcache php8.3-pgsql \ - php8.3-xml socat + apt-get install -y apache2 libapache2-mod-php${PHP_VERSION} msmtp \ + php${PHP_VERSION}-cli php${PHP_VERSION}-opcache \ + php${PHP_VERSION}-pgsql php${PHP_VERSION}-xml socat adduser --system --ingroup www-data \ --shell '/bin/false' \ @@ -23,6 +25,13 @@ RUN </etc/php/${PHP_VERSION}/${what}/conf.d/99-smtp.ini < /etc/apache2/ports.conf diff --git a/docker/compose.yml b/docker/compose.yml index 7aea935..4f6d588 100644 --- a/docker/compose.yml +++ b/docker/compose.yml @@ -44,14 +44,22 @@ services: - planets:/opt/lwb5/site/static/beta5/pics/pl:ro - pgen:/var/spool/pgen:rw environment: - LW_DB_HOST: db LW_DB_ADMIN_PASS_FILE: /run/secrets/lw_db_admin_pass + LW_DB_HOST: db LW_DB_USER_PASS_FILE: /run/secrets/lw_db_user_pass + LW_MAIL_FROM: ${LW_MAIL_FROM} LW_SEND_MAIL: ${LW_SEND_MAIL} LW_STATIC_URL: ${LW_STATIC_URL} + SMTP_AUTH: ${SMTP_AUTH} + SMTP_ENVFROM: ${SMTP_ENVFROM} + SMTP_HOST: ${SMTP_HOST} + SMTP_PORT: ${SMTP_PORT} + SMTP_TLS: ${SMTP_TLS} + SMTP_USER: ${SMTP_USER} secrets: - lw_db_user_pass - lw_db_admin_pass + - smtp_password planetgen: build: @@ -81,3 +89,5 @@ secrets: environment: LW_ADMIN_PASSWORD lw_peacekeepers_password: environment: LW_PEACEKEEPERS_PASSWORD + smtp_password: + environment: SMTP_PASSWORD diff --git a/docker/env.example b/docker/env.example index 4c1da2d..4f2b605 100644 --- a/docker/env.example +++ b/docker/env.example @@ -1,10 +1,25 @@ # Password for the database superuser DB_PASSWORD=... +# SMTP - Outgoing server +SMTP_HOST=smtp.example.org +# SMTP - Port number +SMTP_PORT=587 +# SMTP - Enable TLS? (on/off) +SMTP_TLS=on +# SMTP - Authenticate to outgoing server? (on/off) +SMTP_AUTH=on +# SMTP - User name +SMTP_USER=... +# SMTP - Password +SMTP_PASSWORD=... + # URL of the static assets from an external perspective LW_STATIC_URL=http://localhost/static # Send email? (yes or no) LW_SEND_MAIL=no +# Source address for LW mails +LW_MAIL_FROM=legacyworlds@example.org # Legacyworlds database - Main user LW_DB_USER_PASS=... diff --git a/game/run-lwb5.sh b/game/run-lwb5.sh index 68c83a0..f30da44 100755 --- a/game/run-lwb5.sh +++ b/game/run-lwb5.sh @@ -1,5 +1,29 @@ #!/bin/bash +( + cat < /etc/msmtprc + socat -u \ UNIX-LISTEN:/dev/log,reuseaddr,mode=666,fork \ SYSTEM:"(sed -z 's/$/\\\\n/'; /bin/echo)" \