From 8385db15386200e34568aa016c22d706f456e472 Mon Sep 17 00:00:00 2001 From: Casper Date: Sat, 1 Oct 2022 00:07:06 +0200 Subject: [PATCH] Dockerfile: use heredocs (#2805) --- Dockerfile | 157 +++++++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 71 deletions(-) diff --git a/Dockerfile b/Dockerfile index e30d589c..44c5b57e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ARG DEBIAN_FRONTEND=noninteractive ARG DOVECOT_COMMUNITY_REPO=0 ARG LOG_LEVEL=trace -SHELL ["/bin/bash", "-o", "pipefail", "-c"] +SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] # ----------------------------------------------- # --- Install Basic Software -------------------- @@ -26,18 +26,18 @@ RUN /bin/bash /build/packages.sh COPY target/bin/sedfile /usr/local/bin/sedfile RUN chmod +x /usr/local/bin/sedfile - # ----------------------------------------------- # --- ClamAV & FeshClam ------------------------- # ----------------------------------------------- -RUN \ - echo '0 */6 * * * clamav /usr/bin/freshclam --quiet' >/etc/cron.d/clamav-freshclam && \ - chmod 644 /etc/clamav/freshclam.conf && \ - sedfile -i 's/Foreground false/Foreground true/g' /etc/clamav/clamd.conf && \ - mkdir /var/run/clamav && \ - chown -R clamav:root /var/run/clamav && \ +RUN </etc/cron.d/clamav-freshclam + chmod 644 /etc/clamav/freshclam.conf + sedfile -i 's/Foreground false/Foreground true/g' /etc/clamav/clamd.conf + mkdir /var/run/clamav + chown -R clamav:root /var/run/clamav rm -rf /var/log/clamav/ +EOF # Copy over latest DB updates from official ClamAV image. Better than running `freshclam` (which requires extra RAM during build) # hadolint ignore=DL3021 @@ -54,14 +54,15 @@ RUN chmod 0 /etc/cron.d/dovecot-purge.disabled WORKDIR /usr/share/dovecot # hadolint ignore=SC2016,SC2086,SC2069 -RUN \ - sedfile -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/etc\/dovecot\/protocols\.d/g' /etc/dovecot/dovecot.conf && \ - sedfile -i -e 's/#mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/15-lda.conf && \ - sedfile -i -e 's/^.*lda_mailbox_autocreate.*/lda_mailbox_autocreate = yes/g' /etc/dovecot/conf.d/15-lda.conf && \ - sedfile -i -e 's/^.*lda_mailbox_autosubscribe.*/lda_mailbox_autosubscribe = yes/g' /etc/dovecot/conf.d/15-lda.conf && \ - sedfile -i -e 's/^.*postmaster_address.*/postmaster_address = '${POSTMASTER_ADDRESS:="postmaster@domain.com"}'/g' /etc/dovecot/conf.d/15-lda.conf && \ - mkdir -p /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global && \ +RUN </etc/aliases && \ - sedfile -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail && \ +RUN </etc/aliases + sedfile -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail mkdir /var/run/fetchmail && chown fetchmail /var/run/fetchmail +EOF # ----------------------------------------------- # --- Logs -------------------------------------- # ----------------------------------------------- -RUN \ - sedfile -i -r "/^#?compress/c\compress\ncopytruncate" /etc/logrotate.conf && \ - mkdir -p /var/log/mail && \ - chown syslog:root /var/log/mail && \ - touch /var/log/mail/clamav.log && \ - chown -R clamav:root /var/log/mail/clamav.log && \ - touch /var/log/mail/freshclam.log && \ - chown -R clamav:root /var/log/mail/freshclam.log && \ - sedfile -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/rsyslog.conf && \ - sedfile -i -r 's|;auth,authpriv.none|;mail.none;mail.error;auth,authpriv.none|g' /etc/rsyslog.conf && \ - sedfile -i -r 's|LogFile /var/log/clamav/|LogFile /var/log/mail/|g' /etc/clamav/clamd.conf && \ - sedfile -i -r 's|UpdateLogFile /var/log/clamav/|UpdateLogFile /var/log/mail/|g' /etc/clamav/freshclam.conf && \ - sedfile -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-daemon && \ - sedfile -i -r 's|invoke-rc.d.*|/usr/bin/supervisorctl signal hup clamav >/dev/null \|\| true|g' /etc/logrotate.d/clamav-daemon && \ - sedfile -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-freshclam && \ - sedfile -i -r '/postrotate/,/endscript/d' /etc/logrotate.d/clamav-freshclam && \ - sedfile -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/logrotate.d/rsyslog && \ - sedfile -i -r '/\/var\/log\/mail\/mail.log/d' /etc/logrotate.d/rsyslog && \ +RUN </dev/null \|\| true|g' /etc/logrotate.d/clamav-daemon + sedfile -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-freshclam + sedfile -i -r '/postrotate/,/endscript/d' /etc/logrotate.d/clamav-freshclam + sedfile -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/logrotate.d/rsyslog + sedfile -i -r '/\/var\/log\/mail\/mail.log/d' /etc/logrotate.d/rsyslog # prevent syslog logrotate warnings - sedfile -i -e 's/\(printerror "could not determine current runlevel"\)/#\1/' /usr/sbin/invoke-rc.d && \ - sedfile -i -e 's/^\(POLICYHELPER=\).*/\1/' /usr/sbin/invoke-rc.d && \ + sedfile -i -e 's/\(printerror "could not determine current runlevel"\)/#\1/' /usr/sbin/invoke-rc.d + sedfile -i -e 's/^\(POLICYHELPER=\).*/\1/' /usr/sbin/invoke-rc.d # prevent syslog warning about imklog permissions - sedfile -i -e 's/^module(load=\"imklog\")/#module(load=\"imklog\")/' /etc/rsyslog.conf && \ + sedfile -i -e 's/^module(load=\"imklog\")/#module(load=\"imklog\")/' /etc/rsyslog.conf # prevent email when /sbin/init or init system is not existing sedfile -i -e 's|invoke-rc.d rsyslog rotate > /dev/null|/usr/bin/supervisorctl signal hup rsyslog >/dev/null|g' /usr/lib/rsyslog/rsyslog-rotate +EOF # ----------------------------------------------- # --- Logwatch ---------------------------------- @@ -209,14 +223,15 @@ COPY target/supervisor/conf.d/* /etc/supervisor/conf.d/ # --- Scripts & Miscellaneous-------------------- # ----------------------------------------------- -RUN \ - rm -rf /usr/share/locale/* && \ - rm -rf /usr/share/man/* && \ - rm -rf /usr/share/doc/* && \ - touch /var/log/auth.log && \ - update-locale && \ - rm /etc/postsrsd.secret && \ +RUN <