Skip to content

Commit

Permalink
[squash] bind to localhost only on developer laptops
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsteers committed Sep 10, 2024
1 parent 94bef3f commit 4652f59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
20 changes: 12 additions & 8 deletions src/test/java/uk/gov/pay/connector/rules/PostgresTestDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;

import static java.sql.DriverManager.getConnection;
import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT;

public class PostgresTestDocker {

private static final Logger logger = LoggerFactory.getLogger(PostgresTestDocker.class);

private static final boolean IS_CI = Boolean.parseBoolean(System.getenv("CI"));
private static final String DB_NAME = "connector_test";
private static final String DB_USERNAME = "test";
private static final String DB_PASSWORD = "test";
Expand All @@ -32,12 +32,16 @@ public static void getOrCreate() {
POSTGRES_CONTAINER = new PostgreSQLContainer<>("postgres:15.2")
.withUsername(DB_USERNAME)
.withPassword(DB_PASSWORD)
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(
Ports.Binding.bindIp("127.0.0.1"),
new ExposedPort(POSTGRESQL_PORT)
))
));
.withCreateContainerCmdModifier(cmd -> {
if (!IS_CI) {
cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(
Ports.Binding.bindIp("127.0.0.1"),
new ExposedPort(POSTGRESQL_PORT)
))
);
}
});

POSTGRES_CONTAINER.start();
createDatabase();
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/uk/gov/pay/connector/rules/SqsTestDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class SqsTestDocker {
private static final Logger logger = LoggerFactory.getLogger(SqsTestDocker.class);

private static final boolean IS_CI = Boolean.parseBoolean(System.getenv("CI"));
private static GenericContainer sqsContainer;

public static AmazonSQS initialise(List<String> queueNames) {
Expand All @@ -41,12 +41,16 @@ private static void createContainer() {

sqsContainer = new GenericContainer("softwaremill/elasticmq-native:1.4.2")
.withExposedPorts(9324)
.withCreateContainerCmdModifier((Consumer<CreateContainerCmd>) cmd -> cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(
Ports.Binding.bindIp("127.0.0.1"),
new ExposedPort(9324)
))
))
.withCreateContainerCmdModifier((Consumer<CreateContainerCmd>) cmd -> {
if (!IS_CI) {
cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(
Ports.Binding.bindIp("127.0.0.1"),
new ExposedPort(9324)
))
);
}
})
.waitingFor(Wait.forLogMessage(".*ElasticMQ server.*.*started.*", 1));
sqsContainer.start();
}
Expand Down

0 comments on commit 4652f59

Please sign in to comment.