Ajout d’une passerelle de messagerie pour les conteneurs.
This commit is contained in:
33
misc/images/mta/containers/Dockerfile
Executable file
33
misc/images/mta/containers/Dockerfile
Executable file
@ -0,0 +1,33 @@
|
||||
FROM debian:buster-slim
|
||||
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y \
|
||||
exim4-daemon-light \
|
||||
tini \
|
||||
; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
ln -svfT /etc/hostname /etc/mailname
|
||||
|
||||
# https://blog.dhampir.no/content/exim4-line-length-in-debian-stretch-mail-delivery-failed-returning-message-to-sender
|
||||
# https://serverfault.com/a/881197
|
||||
# https://bugs.debian.org/828801
|
||||
RUN echo "IGNORE_SMTP_LINE_LENGTH_LIMIT='true'" >> /etc/exim4/exim4.conf.localmacros
|
||||
|
||||
RUN set -eux; \
|
||||
mkdir -p /var/spool/exim4 /var/log/exim4; \
|
||||
chown -R Debian-exim:Debian-exim /var/spool/exim4 /var/log/exim4
|
||||
|
||||
COPY set-exim4-update-conf docker-entrypoint.sh /usr/local/bin/
|
||||
RUN set -eux; \
|
||||
set-exim4-update-conf \
|
||||
dc_eximconfig_configtype 'internet' \
|
||||
dc_hide_mailname 'true' \
|
||||
dc_local_interfaces '0.0.0.0 ; ::0' \
|
||||
dc_other_hostnames '' \
|
||||
dc_relay_nets '0.0.0.0/0' \
|
||||
;
|
||||
|
||||
EXPOSE 25
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
CMD ["exim", "-bd", "-v"]
|
33
misc/images/mta/containers/docker-entrypoint.sh
Normal file
33
misc/images/mta/containers/docker-entrypoint.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [ "$1" = 'exim' ]; then
|
||||
if [ -n "${GMAIL_USER:-}" ] && [ -n "${GMAIL_PASSWORD:-}" ]; then
|
||||
# see https://wiki.debian.org/GmailAndExim4
|
||||
export EXIM4_SMARTHOST='smtp.gmail.com::587' \
|
||||
EXIM4_SMARTHOST_USER="$GMAIL_USER" \
|
||||
EXIM4_SMARTHOST_PASSWORD="$GMAIL_PASSWORD"
|
||||
fi
|
||||
unset GMAIL_USER GMAIL_PASSWORD # scrub env of creds
|
||||
|
||||
if [ -n "${EXIM4_SMARTHOST:-}" ]; then
|
||||
set-exim4-update-conf \
|
||||
dc_eximconfig_configtype 'smarthost' \
|
||||
dc_smarthost "$EXIM4_SMARTHOST"
|
||||
if [ -n "${EXIM4_SMARTHOST_USER:-}" ] && [ -n "${EXIM4_SMARTHOST_PASSWORD:-}" ]; then
|
||||
echo "*:$EXIM4_SMARTHOST_USER:$EXIM4_SMARTHOST_PASSWORD" > /etc/exim4/passwd.client
|
||||
fi
|
||||
fi
|
||||
unset EXIM4_SMARTHOST EXIM4_SMARTHOST_USER EXIM4_SMARTHOST_PASSWORD # scrub env of creds
|
||||
|
||||
if [ "$(id -u)" = '0' ]; then
|
||||
mkdir -p /var/spool/exim4 /var/log/exim4 || :
|
||||
chown -R Debian-exim:Debian-exim /var/spool/exim4 /var/log/exim4 || :
|
||||
fi
|
||||
|
||||
if [ "$$" = 1 ]; then
|
||||
set -- tini -- "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
28
misc/images/mta/containers/set-exim4-update-conf
Normal file
28
misc/images/mta/containers/set-exim4-update-conf
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
conf='/etc/exim4/update-exim4.conf.conf'
|
||||
|
||||
args=()
|
||||
while [ "$#" -gt 0 ]; do
|
||||
key="$1"
|
||||
value="$2"
|
||||
shift 2
|
||||
|
||||
if ! grep -qE "^#?${key}=" "$conf"; then
|
||||
echo >&2 "error: '$key' not found in '$conf'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed_escaped_value="$(sed -e 's/[\/&]/\\&/g' <<<"$value")"
|
||||
args+=( -e "s/^#?(${key})=.*/\1='${sed_escaped_value}'/" )
|
||||
done
|
||||
|
||||
if [ "${#args[@]}" -eq 0 ]; then
|
||||
echo >&2 "error: nothing to do?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -x
|
||||
sed -ri "${args[@]}" "$conf"
|
||||
update-exim4.conf -v
|
Reference in New Issue
Block a user