JAMES-2341 SpamAssassin should be created from a Dockerfile directly It avoids relying on an external repository for the image.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ce46d339 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ce46d339 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ce46d339 Branch: refs/heads/master Commit: ce46d33972c2fd3e35811cc488b7c71965667cdb Parents: 0d607c1 Author: benwa <[email protected]> Authored: Wed Mar 7 10:14:33 2018 +0700 Committer: Antoine Duprat <[email protected]> Committed: Thu Mar 8 10:36:37 2018 +0100 ---------------------------------------------------------------------- .../util/scanner/SpamAssassinExtension.java | 9 +- .../resources/docker/spamassassin/Dockerfile | 28 ++++++ .../test/resources/docker/spamassassin/local.cf | 94 ++++++++++++++++++++ .../docker/spamassassin/rule-update.sh | 7 ++ .../test/resources/docker/spamassassin/run.sh | 9 ++ .../test/resources/docker/spamassassin/spamd.sh | 11 +++ 6 files changed, 157 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/java/org/apache/james/util/scanner/SpamAssassinExtension.java ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/java/org/apache/james/util/scanner/SpamAssassinExtension.java b/server/container/util/src/test/java/org/apache/james/util/scanner/SpamAssassinExtension.java index 9d5c3f9..754c83f 100644 --- a/server/container/util/src/test/java/org/apache/james/util/scanner/SpamAssassinExtension.java +++ b/server/container/util/src/test/java/org/apache/james/util/scanner/SpamAssassinExtension.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.images.builder.ImageFromDockerfile; import com.github.fge.lambdas.Throwing; @@ -43,7 +44,13 @@ public class SpamAssassinExtension implements BeforeAllCallback, AfterAllCallbac private SpamAssassin spamAssassin; public SpamAssassinExtension() { - spamAssassinContainer = new GenericContainer<>("linagora/spamassassin:latest"); + spamAssassinContainer = new GenericContainer<>( + new ImageFromDockerfile() + .withFileFromClasspath("Dockerfile", "docker/spamassassin/Dockerfile") + .withFileFromClasspath("local.cf", "docker/spamassassin/local.cf") + .withFileFromClasspath("run.sh", "docker/spamassassin/run.sh") + .withFileFromClasspath("spamd.sh", "docker/spamassassin/spamd.sh") + .withFileFromClasspath("rule-update.sh", "docker/spamassassin/rule-update.sh")); spamAssassinContainer.waitingFor(new SpamAssassinWaitStrategy()); } http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/resources/docker/spamassassin/Dockerfile ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/resources/docker/spamassassin/Dockerfile b/server/container/util/src/test/resources/docker/spamassassin/Dockerfile new file mode 100644 index 0000000..4a5b24d --- /dev/null +++ b/server/container/util/src/test/resources/docker/spamassassin/Dockerfile @@ -0,0 +1,28 @@ +FROM debian:stretch + +ENV SPAMASSASSIN_VERSION 3.4.1 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ + gpg \ + libio-socket-ip-perl \ + libmail-dkim-perl \ + libnet-ident-perl \ + libsocket-getaddrinfo-perl \ + spamassassin=${SPAMASSASSIN_VERSION}* && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir /etc/mail/spamassassin/bayes_db && \ + chmod -R 777 /etc/mail/spamassassin/bayes_db + +COPY spamd.sh / +COPY rule-update.sh / +COPY run.sh / +RUN chmod 755 /spamd.sh /rule-update.sh /run.sh + +COPY local.cf /etc/spamassassin/ + +EXPOSE 783 + +ENTRYPOINT /spamd.sh http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/resources/docker/spamassassin/local.cf ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/resources/docker/spamassassin/local.cf b/server/container/util/src/test/resources/docker/spamassassin/local.cf new file mode 100644 index 0000000..6263270 --- /dev/null +++ b/server/container/util/src/test/resources/docker/spamassassin/local.cf @@ -0,0 +1,94 @@ +# This is the right place to customize your installation of SpamAssassin. +# +# See 'perldoc Mail::SpamAssassin::Conf' for details of what can be +# tweaked. +# +# Only a small subset of options are listed below +# +########################################################################### + +# Add *****SPAM***** to the Subject header of spam e-mails +# +# rewrite_header Subject *****SPAM***** + + +# Save spam messages as a message/rfc822 MIME attachment instead of +# modifying the original message (0: off, 2: use text/plain instead) +# +# report_safe 1 + + +# Set which networks or hosts are considered 'trusted' by your mail +# server (i.e. not spammers) +# +# trusted_networks 212.17.35. + + +# Set file-locking method (flock is not safe over NFS, but is faster) +# +# lock_method flock + + +# Set the threshold at which a message is considered spam (default: 5.0) +# +# required_score 5.0 + + +# Use Bayesian classifier (default: 1) +# +use_bayes 1 + + +# Bayesian classifier auto-learning (default: 1) +# +#bayes_auto_learn 1 + +bayes_path /etc/mail/spamassassin/bayes_db/bayes +bayes_file_mode 0777 +bayes_min_spam_num 1 +bayes_min_ham_num 1 + + +# Set headers which may provide inappropriate cues to the Bayesian +# classifier +# +# bayes_ignore_header X-Bogosity +# bayes_ignore_header X-Spam-Flag +# bayes_ignore_header X-Spam-Status + + +# Whether to decode non- UTF-8 and non-ASCII textual parts and recode +# them to UTF-8 before the text is given over to rules processing. +# +# normalize_charset 1 + +# Some shortcircuiting, if the plugin is enabled +# +ifplugin Mail::SpamAssassin::Plugin::Shortcircuit +# +# default: strongly-whitelisted mails are *really* whitelisted now, if the +# shortcircuiting plugin is active, causing early exit to save CPU load. +# Uncomment to turn this on +# +# shortcircuit USER_IN_WHITELIST on +# shortcircuit USER_IN_DEF_WHITELIST on +# shortcircuit USER_IN_ALL_SPAM_TO on +# shortcircuit SUBJECT_IN_WHITELIST on + +# the opposite; blacklisted mails can also save CPU +# +# shortcircuit USER_IN_BLACKLIST on +# shortcircuit USER_IN_BLACKLIST_TO on +# shortcircuit SUBJECT_IN_BLACKLIST on + +# if you have taken the time to correctly specify your "trusted_networks", +# this is another good way to save CPU +# +# shortcircuit ALL_TRUSTED on + +# and a well-trained bayes DB can save running rules, too +# +# shortcircuit BAYES_99 spam +# shortcircuit BAYES_00 ham + +endif # Mail::SpamAssassin::Plugin::Shortcircuit http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/resources/docker/spamassassin/rule-update.sh ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/resources/docker/spamassassin/rule-update.sh b/server/container/util/src/test/resources/docker/spamassassin/rule-update.sh new file mode 100755 index 0000000..2867735 --- /dev/null +++ b/server/container/util/src/test/resources/docker/spamassassin/rule-update.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +while true; do + sleep 1m + su debian-spamd -c 'sa-update' && kill -HUP `cat /var/run/spamd.pid` + sleep 1d +done http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/resources/docker/spamassassin/run.sh ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/resources/docker/spamassassin/run.sh b/server/container/util/src/test/resources/docker/spamassassin/run.sh new file mode 100755 index 0000000..b4a1351 --- /dev/null +++ b/server/container/util/src/test/resources/docker/spamassassin/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -m + +/rule-update.sh & +/spamd.sh & + +pids=`jobs -p` + +wait http://git-wip-us.apache.org/repos/asf/james-project/blob/ce46d339/server/container/util/src/test/resources/docker/spamassassin/spamd.sh ---------------------------------------------------------------------- diff --git a/server/container/util/src/test/resources/docker/spamassassin/spamd.sh b/server/container/util/src/test/resources/docker/spamassassin/spamd.sh new file mode 100755 index 0000000..251e981 --- /dev/null +++ b/server/container/util/src/test/resources/docker/spamassassin/spamd.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +spamd --username debian-spamd \ + --nouser-config \ + --syslog stderr \ + --pidfile /var/run/spamd.pid \ + --helper-home-dir /var/lib/spamassassin \ + --ip-address \ + --allowed-ips 0.0.0.0/0 \ + --allow-tell \ + --debug bayes,learn --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
