Use the container gateway address as the SMTP host

The value 172.17.0.1 is the default gateway on the default Docker
network. However, when using this image with 'docker-compose', a
new network is created, which means that the IP address of the
gateway is different by definition. Because the network is created
at the same time as the containers, the IP address isn't available
when the YAML definition is created.

This approach replaces the static approach with a dynamic approach
executed at first container startup.
This commit is contained in:
Erik Huelsmann 2023-12-22 13:03:09 +01:00
parent d5661d029f
commit 5a1fd390f1
2 changed files with 10 additions and 3 deletions

View File

@ -78,7 +78,7 @@ RUN set -x ; \
DEBIAN_FRONTEND="noninteractive" apt-get -y update && \
DEBIAN_FRONTEND="noninteractive" apt-get -y upgrade && \
DEBIAN_FRONTEND="noninteractive" apt-get -y install \
wget ca-certificates gnupg \
wget ca-certificates gnupg iproute2 \
$( cat /tmp/derived-deps ) \
libclass-c3-xs-perl \
texlive-plain-generic texlive-latex-recommended texlive-fonts-recommended \
@ -110,7 +110,9 @@ WORKDIR /srv/ledgersmb
# Configure outgoing mail to use host, other run time variable defaults
## MAIL
ENV LSMB_MAIL_SMTPHOST 172.17.0.1
# '__CONTAINER_GATEWAY__' is a magic value which will be substituted
# with the actual gateway IP address
ENV LSMB_MAIL_SMTPHOST __CONTAINER_GATEWAY__
#ENV LSMB_MAIL_SMTPPORT 25
#ENV LSMB_MAIL_SMTPSENDER_HOSTNAME (container hostname)
#ENV LSMB_MAIL_SMTPTLS

View File

@ -67,7 +67,6 @@ if [[ -n "$LSMB_HAVE_DEPRECATED" ]]; then
echo "!!! DEPRECATED \$SSMTP_* PARAMETERS WILL BE REMOVED in the 1.9 image!!!"
fi
if [[ ! -f ./local/conf/ledgersmb.yaml ]]; then
cat <<EOF >./local/conf/ledgersmb.yaml
paths:
@ -105,6 +104,12 @@ EOF
if [[ -n "$LSMB_MAIL_SMTPHOST" ]]
then
if [[ "$LSMB_MAIL_SMTPHOST" == "__CONTAINER_GATEWAY__" ]]
then
LSMB_MAIL_SMTPHOST="$(ip route | awk '/default/ { print $3 }')"
export LSMB_MAIL_SMTPHOST
fi
cat <<EOF >./local/conf/ledgersmb.000.yaml
mail:
transport: