From 7dbf852a8ad01467f1a31057cadaffd33c728a66 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 4 Dec 2024 10:59:03 +0000 Subject: [PATCH 1/4] chore(deps): update releases-docker.jfrog.io/jfrog/artifactory-oss docker tag to v7.98.9 | datasource | package | from | to | | ---------- | ---------------------------------------------- | ------- | ------ | | docker | releases-docker.jfrog.io/jfrog/artifactory-oss | 7.77.12 | 7.98.9 | --- embedded-artifactory/README.adoc | 2 +- .../testcontainer/artifactory/ArtifactoryProperties.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/embedded-artifactory/README.adoc b/embedded-artifactory/README.adoc index 82199d363..1cd9ae808 100644 --- a/embedded-artifactory/README.adoc +++ b/embedded-artifactory/README.adoc @@ -16,7 +16,7 @@ * `embedded.artifactory.enabled` `(true|false, default is true)` * `embedded.artifactory.reuseContainer` `(true|false, default is false)` -* `embedded.artifactory.dockerImage` `(default is 'releases-docker.jfrog.io/jfrog/artifactory-oss:7.77.12')` +* `embedded.artifactory.dockerImage` `(default is 'releases-docker.jfrog.io/jfrog/artifactory-oss:7.98.9')` ** Release notes on https://www.jfrog.com/confluence/display/JFROG/Artifactory+Release+Notes[jfrog.com] * `embedded.artifactory.networkAlias` `(default is 'artifactory')` * `embedded.artifactory.username` `(default is 'admin')` diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java index b34370d49..2d1e60c4b 100644 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java @@ -27,6 +27,6 @@ public ArtifactoryProperties() { public String getDefaultDockerImage() { // Please don`t remove this comment. // renovate: datasource=docker - return "releases-docker.jfrog.io/jfrog/artifactory-oss:7.77.12"; + return "releases-docker.jfrog.io/jfrog/artifactory-oss:7.98.9"; } } From bfe5f71e201f9db176108a362be0863103118502 Mon Sep 17 00:00:00 2001 From: admitrov Date: Wed, 4 Dec 2024 13:16:19 +0000 Subject: [PATCH 2/4] add postgres --- embedded-artifactory/pom.xml | 6 +++- ...ddedArtifactoryBootstrapConfiguration.java | 22 +++++++++++++- .../artifactory/PostgreSQLProperties.java | 30 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java diff --git a/embedded-artifactory/pom.xml b/embedded-artifactory/pom.xml index 34832c79c..b44753b37 100644 --- a/embedded-artifactory/pom.xml +++ b/embedded-artifactory/pom.xml @@ -23,6 +23,10 @@ com.playtika.testcontainers embedded-toxiproxy + + org.testcontainers + postgresql + io.rest-assured @@ -41,4 +45,4 @@ - \ No newline at end of file + diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java index bf93fa58c..a21e1bdfd 100644 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java @@ -19,6 +19,7 @@ import org.springframework.core.env.MapPropertySource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; +import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; import org.testcontainers.containers.wait.strategy.WaitStrategy; import org.testcontainers.toxiproxy.ToxiproxyContainer; @@ -34,7 +35,7 @@ @ConditionalOnExpression("${embedded.containers.enabled:true}") @AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class) @ConditionalOnProperty(name = "embedded.artifactory.enabled", matchIfMissing = true) -@EnableConfigurationProperties(ArtifactoryProperties.class) +@EnableConfigurationProperties({ArtifactoryProperties.class, PostgreSQLProperties.class}) public class EmbeddedArtifactoryBootstrapConfiguration { private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker"; @@ -70,14 +71,33 @@ ToxiproxyClientProxy artifactoryContainerProxy(ToxiproxyClient toxiproxyClient, @Bean(name = ARTIFACTORY_BEAN_NAME, destroyMethod = "stop") public GenericContainer artifactory(ConfigurableEnvironment environment, ArtifactoryProperties properties, + PostgreSQLProperties postgresqlProperties, WaitStrategy artifactoryWaitStrategy, Optional network) { + PostgreSQLContainer postgresql = + new PostgreSQLContainer<>(ContainerUtils.getDockerImageName(postgresqlProperties)) + .withNetwork(Network.SHARED) + .withUsername(postgresqlProperties.getUser()) + .withPassword(postgresqlProperties.getPassword()) + .withDatabaseName(postgresqlProperties.getDatabase()) + .withInitScript(postgresqlProperties.initScriptPath) + .withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS) + .withNetworkAliases(ARTIFACTORY_NETWORK_ALIAS); + + network.ifPresent(postgresql::withNetwork); + configureCommonsAndStart(postgresql, postgresqlProperties, log); + GenericContainer container = new GenericContainer<>(ContainerUtils.getDockerImageName(properties)) .withExposedPorts(properties.getRestApiPort(), properties.getGeneralPort()) .withNetwork(Network.SHARED) .withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS) + .withEnv("username", postgresqlProperties.user) + .withEnv("password", postgresqlProperties.password) + .withEnv("url", "jdbc:postgresql://localhost:5432/" + postgresqlProperties.database) + .withEnv("type", "postgresql") + .withEnv("driver", "org.postgresql.Driver") .waitingFor(artifactoryWaitStrategy); network.ifPresent(container::withNetwork); diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java new file mode 100644 index 000000000..eaa8f7c80 --- /dev/null +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java @@ -0,0 +1,30 @@ +package com.playtika.testcontainer.artifactory; + +import com.playtika.testcontainer.common.properties.CommonContainerProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Data +@EqualsAndHashCode(callSuper = true) +@ConfigurationProperties("embedded.artifactory.postgresql") +public class PostgreSQLProperties extends CommonContainerProperties { + static final String BEAN_NAME_EMBEDDED_POSTGRESQL = "embeddedPostgreSql"; + + String user = "artifactory"; + String password = "artifactory"; + String database = "artifactory"; + String startupLogCheckRegex; + /** + * The SQL file path to execute after the container starts to initialize the database. + */ + String initScriptPath; + + // https://hub.docker.com/_/postgres + @Override + public String getDefaultDockerImage() { + // Please don`t remove this comment. + // renovate: datasource=docker + return "postgres:17-alpine"; + } +} From eaeae2ee93f762b5a30b40d96f06221644a3fd1b Mon Sep 17 00:00:00 2001 From: admitrov Date: Thu, 7 May 2026 22:13:30 +0100 Subject: [PATCH 3/4] chore: migrate embedded-artifactory to use embedded-postgresql module - Replace direct PostgreSQL container with embedded-postgresql dependency - Remove PostgreSQLProperties class in favor of shared module - Add system.yaml configuration for database connection - Increase default wait timeout from 120 to 300 seconds - Update README with PostgreSQL configuration options --- embedded-artifactory/README.adoc | 18 ++++++ embedded-artifactory/pom.xml | 4 +- .../artifactory/ArtifactoryProperties.java | 2 +- ...ddedArtifactoryBootstrapConfiguration.java | 63 ++++++++++++------- .../artifactory/PostgreSQLProperties.java | 30 --------- ...eddedPostgreSQLBootstrapConfiguration.java | 4 +- testcontainers-spring-boot-parent/pom.xml | 5 ++ 7 files changed, 68 insertions(+), 58 deletions(-) delete mode 100644 embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java diff --git a/embedded-artifactory/README.adoc b/embedded-artifactory/README.adoc index 1cd9ae808..cc2848d4a 100644 --- a/embedded-artifactory/README.adoc +++ b/embedded-artifactory/README.adoc @@ -23,6 +23,24 @@ * `embedded.artifactory.password` `(default is 'password')` * `embedded.toxiproxy.proxies.artifactory.enabled` Enables both creation of the container with ToxiProxy TCP proxy and a proxy to the `embedded-artifactory` container. +==== PostgreSQL backing store + +Artifactory uses PostgreSQL as its backing database, provided by the `embedded-postgresql` module. +Configure the database via `embedded.postgresql.*` properties: + +* `embedded.postgresql.user` `(default is 'postgresql')` +* `embedded.postgresql.password` `(default is 'letmein')` +* `embedded.postgresql.database` `(default is 'test_db')` +* `embedded.postgresql.dockerImage` `(default is 'postgres:18-alpine')` + +Example override in `bootstrap.properties`: +[source,properties] +---- +embedded.postgresql.user=artifactory +embedded.postgresql.password=artifactory +embedded.postgresql.database=artifactory +---- + ==== Produces * `embedded.artifactory.host` diff --git a/embedded-artifactory/pom.xml b/embedded-artifactory/pom.xml index b44753b37..70468786d 100644 --- a/embedded-artifactory/pom.xml +++ b/embedded-artifactory/pom.xml @@ -24,8 +24,8 @@ embedded-toxiproxy - org.testcontainers - postgresql + com.playtika.testcontainers + embedded-postgresql diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java index 2d1e60c4b..b750bc02d 100644 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/ArtifactoryProperties.java @@ -20,7 +20,7 @@ public class ArtifactoryProperties extends CommonContainerProperties { int generalPort = 8082; public ArtifactoryProperties() { - setWaitTimeoutInSeconds(120); + setWaitTimeoutInSeconds(300); } @Override diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java index a21e1bdfd..0cc282b53 100644 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java @@ -2,11 +2,14 @@ import com.playtika.testcontainer.common.spring.DockerPresenceBootstrapConfiguration; import com.playtika.testcontainer.common.utils.ContainerUtils; +import com.playtika.testcontainer.postgresql.EmbeddedPostgreSQLBootstrapConfiguration; +import com.playtika.testcontainer.postgresql.PostgreSQLProperties; import com.playtika.testcontainer.toxiproxy.ToxiproxyClientProxy; import com.playtika.testcontainer.toxiproxy.ToxiproxyHelper; import com.playtika.testcontainer.toxiproxy.condition.ConditionalOnToxiProxyEnabled; import eu.rekawek.toxiproxy.ToxiproxyClient; import lombok.extern.slf4j.Slf4j; +import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -22,24 +25,35 @@ import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; import org.testcontainers.containers.wait.strategy.WaitStrategy; +import org.testcontainers.images.builder.Transferable; +import org.testcontainers.postgresql.PostgreSQLContainer; import org.testcontainers.toxiproxy.ToxiproxyContainer; +import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; -import java.util.Optional; import static com.playtika.testcontainer.artifactory.ArtifactoryProperties.ARTIFACTORY_BEAN_NAME; import static com.playtika.testcontainer.common.utils.ContainerUtils.configureCommonsAndStart; +import static org.testcontainers.postgresql.PostgreSQLContainer.POSTGRESQL_PORT; @Slf4j @Configuration @ConditionalOnExpression("${embedded.containers.enabled:true}") -@AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class) +@AutoConfigureAfter({DockerPresenceBootstrapConfiguration.class, EmbeddedPostgreSQLBootstrapConfiguration.class}) @ConditionalOnProperty(name = "embedded.artifactory.enabled", matchIfMissing = true) -@EnableConfigurationProperties({ArtifactoryProperties.class, PostgreSQLProperties.class}) +@EnableConfigurationProperties(ArtifactoryProperties.class) public class EmbeddedArtifactoryBootstrapConfiguration { private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker"; + @Bean + @ConditionalOnMissingBean(Network.class) + Network artifactoryNetwork() { + Network network = Network.newNetwork(); + log.info("Created docker Network with id={}", network.getId()); + return network; + } + @Bean @ConditionalOnMissingBean(name = "artifactoryWaitStrategy") public WaitStrategy artifactoryWaitStrategy(ArtifactoryProperties properties) { @@ -71,36 +85,23 @@ ToxiproxyClientProxy artifactoryContainerProxy(ToxiproxyClient toxiproxyClient, @Bean(name = ARTIFACTORY_BEAN_NAME, destroyMethod = "stop") public GenericContainer artifactory(ConfigurableEnvironment environment, ArtifactoryProperties properties, + PostgreSQLContainer postgreSQLContainer, PostgreSQLProperties postgresqlProperties, WaitStrategy artifactoryWaitStrategy, - Optional network) { + Network network) { - PostgreSQLContainer postgresql = - new PostgreSQLContainer<>(ContainerUtils.getDockerImageName(postgresqlProperties)) - .withNetwork(Network.SHARED) - .withUsername(postgresqlProperties.getUser()) - .withPassword(postgresqlProperties.getPassword()) - .withDatabaseName(postgresqlProperties.getDatabase()) - .withInitScript(postgresqlProperties.initScriptPath) - .withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS) - .withNetworkAliases(ARTIFACTORY_NETWORK_ALIAS); - - network.ifPresent(postgresql::withNetwork); - configureCommonsAndStart(postgresql, postgresqlProperties, log); + String systemYaml = getSystemYaml(postgresqlProperties,postgreSQLContainer); GenericContainer container = new GenericContainer<>(ContainerUtils.getDockerImageName(properties)) .withExposedPorts(properties.getRestApiPort(), properties.getGeneralPort()) - .withNetwork(Network.SHARED) + .withNetwork(network) .withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS) - .withEnv("username", postgresqlProperties.user) - .withEnv("password", postgresqlProperties.password) - .withEnv("url", "jdbc:postgresql://localhost:5432/" + postgresqlProperties.database) - .withEnv("type", "postgresql") - .withEnv("driver", "org.postgresql.Driver") + .withCopyToContainer( + Transferable.of(systemYaml.getBytes(StandardCharsets.UTF_8), 0666), + "/opt/jfrog/artifactory/var/etc/system.yaml") .waitingFor(artifactoryWaitStrategy); - network.ifPresent(container::withNetwork); configureCommonsAndStart(container, properties, log); registerEnvironment(container, environment, properties); @@ -108,6 +109,22 @@ public GenericContainer artifactory(ConfigurableEnvironment environment, return container; } + private static @NonNull String getSystemYaml(PostgreSQLProperties postgresqlProperties, + PostgreSQLContainer postgreSQLContainer) { + String jdbcUrl = "jdbc:postgresql://%s:%d/%s" + .formatted(postgreSQLContainer.getNetwork(), POSTGRESQL_PORT, postgresqlProperties.getDatabase()); + + return """ + shared: + database: + type: "postgresql" + driver: "org.postgresql.Driver" + url: "%s" + username: "%s" + password: "%s" + """.formatted(jdbcUrl, postgreSQLContainer.getUsername(), postgreSQLContainer.getPassword()); + } + private void registerEnvironment(GenericContainer artifactory, ConfigurableEnvironment environment, ArtifactoryProperties properties) { diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java deleted file mode 100644 index eaa8f7c80..000000000 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/PostgreSQLProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.playtika.testcontainer.artifactory; - -import com.playtika.testcontainer.common.properties.CommonContainerProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Data -@EqualsAndHashCode(callSuper = true) -@ConfigurationProperties("embedded.artifactory.postgresql") -public class PostgreSQLProperties extends CommonContainerProperties { - static final String BEAN_NAME_EMBEDDED_POSTGRESQL = "embeddedPostgreSql"; - - String user = "artifactory"; - String password = "artifactory"; - String database = "artifactory"; - String startupLogCheckRegex; - /** - * The SQL file path to execute after the container starts to initialize the database. - */ - String initScriptPath; - - // https://hub.docker.com/_/postgres - @Override - public String getDefaultDockerImage() { - // Please don`t remove this comment. - // renovate: datasource=docker - return "postgres:17-alpine"; - } -} diff --git a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java index c54728895..cb56f1477 100644 --- a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java +++ b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java @@ -18,9 +18,9 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.util.StringUtils; import org.testcontainers.containers.Network; -import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; import org.testcontainers.containers.wait.strategy.WaitStrategy; +import org.testcontainers.postgresql.PostgreSQLContainer; import org.testcontainers.toxiproxy.ToxiproxyContainer; import java.util.LinkedHashMap; @@ -63,7 +63,7 @@ public PostgreSQLContainer postgresql(ConfigurableEnvironment environment, Optional network) { PostgreSQLContainer postgresql = - new PostgreSQLContainer<>(ContainerUtils.getDockerImageName(properties)) + new PostgreSQLContainer(ContainerUtils.getDockerImageName(properties)) .withUsername(properties.getUser()) .withPassword(properties.getPassword()) .withDatabaseName(properties.getDatabase()) diff --git a/testcontainers-spring-boot-parent/pom.xml b/testcontainers-spring-boot-parent/pom.xml index a622ab945..14181b76e 100644 --- a/testcontainers-spring-boot-parent/pom.xml +++ b/testcontainers-spring-boot-parent/pom.xml @@ -80,6 +80,11 @@ embedded-toxiproxy ${project.version} + + com.playtika.testcontainers + embedded-postgresql + ${project.version} + com.playtika.testcontainers embedded-aerospike From 1060b5ae4c2dc7b2f6226819be4bd9c8dc9222d7 Mon Sep 17 00:00:00 2001 From: admitrov Date: Mon, 11 May 2026 13:11:01 +0100 Subject: [PATCH 4/4] feat: add configurable network alias for PostgreSQL container - Add `embedded.postgresql.networkAlias` property (default: 'postgresql.testcontainer.docker') - Use configured network alias in Artifactory system.yaml JDBC URL - Add test to verify network alias configuration in system.yaml - Update README documentation with new property --- embedded-artifactory/README.adoc | 1 + ...ddedArtifactoryBootstrapConfiguration.java | 9 +++--- ...yBootstrapConfigurationSystemYamlTest.java | 31 +++++++++++++++++++ .../src/test/resources/bootstrap.properties | 3 ++ embedded-postgresql/README.adoc | 1 + ...eddedPostgreSQLBootstrapConfiguration.java | 6 ++-- .../postgresql/PostgreSQLProperties.java | 2 ++ ...itional-spring-configuration-metadata.json | 5 +++ 8 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 embedded-artifactory/src/test/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfigurationSystemYamlTest.java create mode 100644 embedded-artifactory/src/test/resources/bootstrap.properties diff --git a/embedded-artifactory/README.adoc b/embedded-artifactory/README.adoc index cc2848d4a..78effeab6 100644 --- a/embedded-artifactory/README.adoc +++ b/embedded-artifactory/README.adoc @@ -31,6 +31,7 @@ Configure the database via `embedded.postgresql.*` properties: * `embedded.postgresql.user` `(default is 'postgresql')` * `embedded.postgresql.password` `(default is 'letmein')` * `embedded.postgresql.database` `(default is 'test_db')` +* `embedded.postgresql.networkAlias` `(default is 'postgresql.testcontainer.docker')` * `embedded.postgresql.dockerImage` `(default is 'postgres:18-alpine')` Example override in `bootstrap.properties`: diff --git a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java index 0cc282b53..b61ab4fca 100644 --- a/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java +++ b/embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java @@ -22,7 +22,6 @@ import org.springframework.core.env.MapPropertySource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; import org.testcontainers.containers.wait.strategy.WaitStrategy; import org.testcontainers.images.builder.Transferable; @@ -90,7 +89,7 @@ public GenericContainer artifactory(ConfigurableEnvironment environment, WaitStrategy artifactoryWaitStrategy, Network network) { - String systemYaml = getSystemYaml(postgresqlProperties,postgreSQLContainer); + String systemYaml = getSystemYaml(postgresqlProperties, postgreSQLContainer); GenericContainer container = new GenericContainer<>(ContainerUtils.getDockerImageName(properties)) @@ -109,10 +108,10 @@ public GenericContainer artifactory(ConfigurableEnvironment environment, return container; } - private static @NonNull String getSystemYaml(PostgreSQLProperties postgresqlProperties, - PostgreSQLContainer postgreSQLContainer) { + static @NonNull String getSystemYaml(PostgreSQLProperties postgresqlProperties, + PostgreSQLContainer postgreSQLContainer) { String jdbcUrl = "jdbc:postgresql://%s:%d/%s" - .formatted(postgreSQLContainer.getNetwork(), POSTGRESQL_PORT, postgresqlProperties.getDatabase()); + .formatted(postgresqlProperties.getNetworkAlias(), POSTGRESQL_PORT, postgresqlProperties.getDatabase()); return """ shared: diff --git a/embedded-artifactory/src/test/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfigurationSystemYamlTest.java b/embedded-artifactory/src/test/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfigurationSystemYamlTest.java new file mode 100644 index 000000000..3a2ae6ac1 --- /dev/null +++ b/embedded-artifactory/src/test/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfigurationSystemYamlTest.java @@ -0,0 +1,31 @@ +package com.playtika.testcontainer.artifactory; + +import com.playtika.testcontainer.postgresql.PostgreSQLProperties; +import org.junit.jupiter.api.Test; +import org.testcontainers.postgresql.PostgreSQLContainer; + +import static org.assertj.core.api.Assertions.assertThat; + +class EmbeddedArtifactoryBootstrapConfigurationSystemYamlTest { + + @Test + void shouldUseConfiguredPostgresqlNetworkAliasInSystemYaml() { + PostgreSQLProperties postgresqlProperties = new PostgreSQLProperties(); + postgresqlProperties.setDatabase("artifactory"); + postgresqlProperties.setNetworkAlias("postgresql.internal"); + + PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:18-alpine") + .withNetworkAliases("postgresql.internal") + .withUsername("artifactory") + .withPassword("secret"); + + String systemYaml = EmbeddedArtifactoryBootstrapConfiguration.getSystemYaml( + postgresqlProperties, + postgreSQLContainer); + + assertThat(systemYaml) + .contains("url: \"jdbc:postgresql://postgresql.internal:5432/artifactory\"") + .contains("username: \"artifactory\"") + .contains("password: \"secret\""); + } +} diff --git a/embedded-artifactory/src/test/resources/bootstrap.properties b/embedded-artifactory/src/test/resources/bootstrap.properties new file mode 100644 index 000000000..3f07a7265 --- /dev/null +++ b/embedded-artifactory/src/test/resources/bootstrap.properties @@ -0,0 +1,3 @@ +embedded.postgresql.user=artifactory +embedded.postgresql.password=artifactory +embedded.postgresql.database=artifactory diff --git a/embedded-postgresql/README.adoc b/embedded-postgresql/README.adoc index 35b9ccf6c..1d5f19d88 100644 --- a/embedded-postgresql/README.adoc +++ b/embedded-postgresql/README.adoc @@ -22,6 +22,7 @@ * `embedded.postgresql.database` * `embedded.postgresql.user` * `embedded.postgresql.password` +* `embedded.postgresql.networkAlias` `(default is 'postgresql.testcontainer.docker')` * `embedded.postgresql.initScriptPath` `(default is null)` * `embedded.postgresql.startupLogCheckRegex` `(default is null)` * `embedded.postgresql.mountVolumes` `(default is empty list)` diff --git a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java index cb56f1477..5b9d7eef5 100644 --- a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java +++ b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java @@ -37,8 +37,6 @@ @EnableConfigurationProperties(PostgreSQLProperties.class) public class EmbeddedPostgreSQLBootstrapConfiguration { - private static final String POSTGRESQL_NETWORK_ALIAS = "postgresql.testcontainer.docker"; - @Bean @ConditionalOnToxiProxyEnabled(module = "postgresql") ToxiproxyClientProxy postgresqlContainerProxy(ToxiproxyClient toxiproxyClient, @@ -68,7 +66,7 @@ public PostgreSQLContainer postgresql(ConfigurableEnvironment environment, .withPassword(properties.getPassword()) .withDatabaseName(properties.getDatabase()) .withInitScript(properties.initScriptPath) - .withNetworkAliases(POSTGRESQL_NETWORK_ALIAS); + .withNetworkAliases(properties.getNetworkAlias()); network.ifPresent(postgresql::withNetwork); @@ -96,7 +94,7 @@ private void registerPostgresqlEnvironment(PostgreSQLContainer postgresql, map.put("embedded.postgresql.schema", properties.getDatabase()); map.put("embedded.postgresql.user", properties.getUser()); map.put("embedded.postgresql.password", properties.getPassword()); - map.put("embedded.postgresql.networkAlias", POSTGRESQL_NETWORK_ALIAS); + map.put("embedded.postgresql.networkAlias", properties.getNetworkAlias()); map.put("embedded.postgresql.internalPort", PostgreSQLContainer.POSTGRESQL_PORT); String jdbcURL = "jdbc:postgresql://{}:{}/{}"; diff --git a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/PostgreSQLProperties.java b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/PostgreSQLProperties.java index 951bfcc06..e6436b75f 100644 --- a/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/PostgreSQLProperties.java +++ b/embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/PostgreSQLProperties.java @@ -10,10 +10,12 @@ @ConfigurationProperties("embedded.postgresql") public class PostgreSQLProperties extends CommonContainerProperties { static final String BEAN_NAME_EMBEDDED_POSTGRESQL = "embeddedPostgreSql"; + static final String DEFAULT_NETWORK_ALIAS = "postgresql.testcontainer.docker"; String user = "postgresql"; String password = "letmein"; String database = "test_db"; + String networkAlias = DEFAULT_NETWORK_ALIAS; String startupLogCheckRegex; /** * The SQL file path to execute after the container starts to initialize the database. diff --git a/embedded-postgresql/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/embedded-postgresql/src/main/resources/META-INF/additional-spring-configuration-metadata.json index dd067aaad..bfe1af239 100644 --- a/embedded-postgresql/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/embedded-postgresql/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -17,6 +17,11 @@ "type": "java.lang.String", "defaultValue": "null", "description": "The SQL file path to execute after the container starts to initialize the database." + }, + { + "name": "embedded.postgresql.network-alias", + "type": "java.lang.String", + "defaultValue": "postgresql.testcontainer.docker" } ], "hints": [