Skip to content

Commit

Permalink
Add: Mail transport agent to enable email notifications in docker
Browse files Browse the repository at this point in the history
This adds the `msmtp` and `msmtp-mta` packages to achieve ability
of sending email notifications from docker container. Default
`gvmd` image has no MTA but tries to send emails via local mailer
(and always fails for sure).

With msmtp user can send emails to a single preferred SMTP server.
  • Loading branch information
castorsky authored and bjoernricks committed Jul 17, 2023
1 parent 149ee59 commit e0b092d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

#!/bin/bash

. setup-mta
exec gosu gvmd "$@"
3 changes: 3 additions & 0 deletions .docker/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ RUN apt-get update && \
libgpgme11 \
libical3 \
libpq5 \
msmtp \
msmtp-mta \
openssh-client \
postgresql-client-13 \
postgresql-client-common \
Expand All @@ -107,6 +109,7 @@ COPY --from=builder /install/ /

COPY .docker/start-gvmd.sh /usr/local/bin/start-gvmd
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint
COPY .docker/setup-mta.sh /usr/local/bin/setup-mta

RUN addgroup --gid 1001 --system gvmd && \
adduser --no-create-home --shell /bin/false --disabled-password --uid 1001 --system --group gvmd
Expand Down
18 changes: 18 additions & 0 deletions .docker/setup-mta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Make any changes only when MTA_HOST has been set
if [ -n MTA_HOST ]; then
echo "setting up configuration file for mail agent"
CONFIG="/etc/msmtprc"
echo "host $MTA_HOST" > $CONFIG
[ -n MTA_PORT ] && echo "port $MTA_PORT" >> $CONFIG
[ -n MTA_TLS ] && echo "tls $MTA_TLS" >> $CONFIG
[ -n MTA_STARTTLS ] && echo "tls_starttls $MTA_STARTTLS" >> $CONFIG
[ -n MTA_AUTH ] && echo "auth $MTA_AUTH" >> $CONFIG
[ -n MTA_USER ] && echo "user $MTA_USER" >> $CONFIG
[ -n MTA_FROM ] && echo "from $MTA_FROM" >> $CONFIG
[ -n MTA_PASSWORD ] && echo "password $MTA_PASSWORD" >> $CONFIG
[ -n MTA_LOGFILE ] && echo "logfile $MTA_LOGFILE" >> $CONFIG
chown gvmd:mail $CONFIG
chmod 750 $CONFIG
fi

0 comments on commit e0b092d

Please sign in to comment.