Skip to content

Commit

Permalink
[UPGRADE] - Docker - SpamAssassin 3.4.6 -> 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vttranlina committed Jul 20, 2023
1 parent 035ebf0 commit 69d8f18
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 323 deletions.
2 changes: 1 addition & 1 deletion third-party/spamassassin/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ services:
- "8000:8000"

spamassassin:
image: instantlinux/spamassassin:3.4.6-1
image: instantlinux/spamassassin:4.0.0-6
ports:
- "783:783"
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,21 @@
import org.junit.jupiter.api.extension.ParameterResolver;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.utility.Base58;

import com.github.fge.lambdas.Throwing;
import com.google.common.collect.ImmutableMap;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

public class SpamAssassinExtension implements BeforeAllCallback, AfterEachCallback, ParameterResolver {
public static final int SPAMASSASSIN_PORT = 783;
private static final Duration STARTUP_TIMEOUT = Duration.ofMinutes(30);
private static final String UNIQUE_IDENTIFIER = Base58.randomString(16).toLowerCase();

private static final boolean DELETE_ON_EXIT = false;
private static final GenericContainer<?> spamAssassinContainer = new GenericContainer<>(
new ImageFromDockerfile("james-spamassassin/" + UNIQUE_IDENTIFIER, DELETE_ON_EXIT)
.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")
.withFileFromClasspath("bayes_pg.sql", "docker/spamassassin/bayes_pg.sql"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("spam-assassin-" + UUID.randomUUID().toString()))
private static final String SPAMASSASSIN_IMAGE = "instantlinux/spamassassin:4.0.0-6";
private static final GenericContainer<?> spamAssassinContainer = new GenericContainer<>(SPAMASSASSIN_IMAGE)
.withCreateContainerCmdModifier(cmd -> cmd.withName("james-spam-assassin-test-" + UUID.randomUUID()))
.withStartupTimeout(STARTUP_TIMEOUT)
.withExposedPorts(783)
.withTmpFs(ImmutableMap.of("/var/lib/postgresql/data", "rw,noexec,nosuid,size=200m"))
.withExposedPorts(SPAMASSASSIN_PORT)
.waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND));

static {
Expand Down Expand Up @@ -106,8 +94,6 @@ public SpamAssassin getSpamAssassin() {
}

public static class SpamAssassin {
private static final int SPAMASSASSIN_PORT = 783;

private final String ip;
private final int bindingPort;
private final GenericContainer<?> spamAssassinContainer;
Expand Down Expand Up @@ -155,7 +141,7 @@ private void train(String user, Path folder, TrainingKind trainingKind) throws I
private enum TrainingKind {
SPAM("--spam"), HAM("--ham");

private String saLearnExtensionName;
private final String saLearnExtensionName;

TrainingKind(String saLearnExtensionName) {
this.saLearnExtensionName = saLearnExtensionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.util.UUID;

import javax.mail.MessagingException;

Expand All @@ -44,8 +43,6 @@
import org.apache.james.modules.protocols.SmtpGuiceProbe;
import org.apache.james.transport.matchers.All;
import org.apache.james.util.Host;
import org.apache.james.util.docker.DockerContainer;
import org.apache.james.util.docker.RateLimiters;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.utils.TestIMAPClient;
Expand All @@ -55,7 +52,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;

import com.google.inject.Binder;
import com.google.inject.Module;
Expand All @@ -64,15 +60,9 @@

class SpamAssassinIntegrationTest {
private static final String SPAM_CONTENT = "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
private static final String SPAMASSASSIN_IMAGE = "instantlinux/spamassassin:3.4.6-1";

@RegisterExtension
public static DockerContainer spamAssassinContainer = DockerContainer.fromName(SPAMASSASSIN_IMAGE)
.withExposedPorts(783)
.withAffinityToContainer()
.waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND))
.withName("james-testing-spamassassin-" + UUID.randomUUID());

public static SpamAssassinExtension spamAssassinExtension = new SpamAssassinExtension();
@RegisterExtension
public TestIMAPClient messageReader = new TestIMAPClient();
@RegisterExtension
Expand Down Expand Up @@ -100,7 +90,7 @@ public void configure(Binder binder) {
@Provides
@Singleton
private SpamAssassinConfiguration provideSpamAssassinConfiguration(){
return new SpamAssassinConfiguration(Host.parseConfString("localhost", spamAssassinContainer.getMappedPort(783)));
return new SpamAssassinConfiguration(Host.parseConfString("localhost", spamAssassinExtension.getSpamAssassin().getBindingPort()));
}
})
.build(temporaryFolder);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 69d8f18

Please sign in to comment.