From f0bbb2862617d3ea787abed06f53e3193503f640 Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Wed, 7 Dec 2022 15:21:30 +0100 Subject: [PATCH] feat: make smtp settings configurable in .env --- .env.sample | 11 +++++++++++ abra.sh | 2 +- compose.smtp.yml | 19 +++++++++++++++++++ compose.yml | 4 ---- entrypoint.sh.tmpl | 27 +++++++++++++++++++++++++++ releases/next | 14 ++++++++++++++ 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 compose.smtp.yml create mode 100644 releases/next diff --git a/.env.sample b/.env.sample index 6c95e1b..131d164 100644 --- a/.env.sample +++ b/.env.sample @@ -19,6 +19,17 @@ SECRET_BBB_SECRET_VERSION=v1 EXTRA_VOLUME=/dev/null:/tmp/.dummy +# COMPOSE_FILE="$COMPOSE_FILE:compose.smtp.yml" +# See https://github.com/nextcloud/docker#auto-configuration-via-environment-variables for default values +# SMTP_AUTHTYPE= +# SMTP_HOST= +# SMTP_SECURE= +# SMTP_NAME= +# SMTP_PORT= +# MAIL_FROM_ADDRESS= +# MAIL_DOMAIN= +# SECRET_SMTP_PASSWORD_VERSION=v1 + # X_FRAME_OPTIONS_ENABLED=1 # X_FRAME_OPTIONS_ALLOW_FROM=embedding-site.example.org # APPS="calendar sociallogin onlyoffice" diff --git a/abra.sh b/abra.sh index 7c12215..8f018e4 100644 --- a/abra.sh +++ b/abra.sh @@ -3,7 +3,7 @@ export FPM_TUNE_VERSION=v4 export NGINX_CONF_VERSION=v4 export MY_CNF_VERSION=v4 -export ENTRYPOINT_VERSION=v2 +export ENTRYPOINT_VERSION=v3 run_occ(){ su -p www-data -s /bin/sh -c "/var/www/html/occ $@" diff --git a/compose.smtp.yml b/compose.smtp.yml new file mode 100644 index 0000000..cd7436b --- /dev/null +++ b/compose.smtp.yml @@ -0,0 +1,19 @@ +version: "3.8" +services: + app: + secrets: + - smtp_password + environment: + - SMTP_AUTHTYPE + - SMTP_HOST + - SMTP_SECURE + - SMTP_NAME + - SMTP_PORT + - SMTP_PASSWORD_FILE=/run/secrets/smtp_password + - MAIL_FROM_ADDRESS + - MAIL_DOMAIN + +secrets: + smtp_password: + external: true + name: ${STACK_NAME}_smtp_password_${SECRET_SMTP_PASSWORD_VERSION} diff --git a/compose.yml b/compose.yml index 2e249cf..c9f733e 100644 --- a/compose.yml +++ b/compose.yml @@ -61,10 +61,6 @@ services: - NEXTCLOUD_TRUSTED_DOMAINS=${DOMAIN} - TRUSTED_PROXIES=traefik - REDIS_HOST=cache - - SMTP_HOST - - MAIL_FROM_ADDRESS - - MAIL_DOMAIN - - SMTP_AUTHTYPE=PLAIN - OVERWRITEPROTOCOL=https - PHP_MEMORY_LIMIT=1G - ONLYOFFICE_URL diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl index 30d21e8..742ccb9 100644 --- a/entrypoint.sh.tmpl +++ b/entrypoint.sh.tmpl @@ -1,5 +1,30 @@ #!/bin/bash +set -eu + +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +file_env "SMTP_PASSWORD" + echo "Giving the db container some time to come up"; sleep 20 # see this issue with postgres db https://github.com/nextcloud/docker/issues/1204 @@ -9,4 +34,6 @@ if ! [[ $(grep {{ env "X_FRAME_OPTIONS_ALLOW_FROM" }} lib/public/AppFramework/Ht fi {{ end }} + + /entrypoint.sh php-fpm diff --git a/releases/next b/releases/next new file mode 100644 index 0000000..f55314a --- /dev/null +++ b/releases/next @@ -0,0 +1,14 @@ +Add SMTP Config to your .env file: + +``` +# COMPOSE_FILE="$COMPOSE_FILE:compose.smtp.yml" +# See https://github.com/nextcloud/docker#auto-configuration-via-environment-variables for default values +# SMTP_AUTHTYPE= +# SMTP_HOST= +# SMTP_SECURE= +# SMTP_NAME= +# SMTP_PORT= +# MAIL_FROM_ADDRESS= +# MAIL_DOMAIN= +# SECRET_SMTP_PASSWORD_VERSION=v1 +```