Skip to content

Commit d8ba596

Browse files
author
admitrov
committed
add postgres
1 parent 8cf4633 commit d8ba596

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

embedded-artifactory/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<groupId>com.playtika.testcontainers</groupId>
2323
<artifactId>embedded-toxiproxy</artifactId>
2424
</dependency>
25+
<dependency>
26+
<groupId>org.testcontainers</groupId>
27+
<artifactId>postgresql</artifactId>
28+
</dependency>
2529

2630
<dependency>
2731
<groupId>io.rest-assured</groupId>
@@ -46,4 +50,4 @@
4650
</exclusions>
4751
</dependency>
4852
</dependencies>
49-
</project>
53+
</project>

embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.springframework.core.env.MapPropertySource;
1717
import org.testcontainers.containers.GenericContainer;
1818
import org.testcontainers.containers.Network;
19+
import org.testcontainers.containers.PostgreSQLContainer;
1920
import org.testcontainers.containers.ToxiproxyContainer;
2021
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
2122
import org.testcontainers.containers.wait.strategy.WaitStrategy;
@@ -32,7 +33,7 @@
3233
@ConditionalOnExpression("${embedded.containers.enabled:true}")
3334
@AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class)
3435
@ConditionalOnProperty(name = "embedded.artifactory.enabled", matchIfMissing = true)
35-
@EnableConfigurationProperties(ArtifactoryProperties.class)
36+
@EnableConfigurationProperties({ArtifactoryProperties.class, PostgreSQLProperties.class})
3637
public class EmbeddedArtifactoryBootstrapConfiguration {
3738

3839
private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker";
@@ -69,14 +70,33 @@ ToxiproxyContainer.ContainerProxy artifactoryContainerProxy(ToxiproxyContainer t
6970
@Bean(name = ARTIFACTORY_BEAN_NAME, destroyMethod = "stop")
7071
public GenericContainer<?> artifactory(ConfigurableEnvironment environment,
7172
ArtifactoryProperties properties,
73+
PostgreSQLProperties postgresqlProperties,
7274
WaitStrategy artifactoryWaitStrategy,
7375
Optional<Network> network) {
7476

77+
PostgreSQLContainer postgresql =
78+
new PostgreSQLContainer<>(ContainerUtils.getDockerImageName(postgresqlProperties))
79+
.withNetwork(Network.SHARED)
80+
.withUsername(postgresqlProperties.getUser())
81+
.withPassword(postgresqlProperties.getPassword())
82+
.withDatabaseName(postgresqlProperties.getDatabase())
83+
.withInitScript(postgresqlProperties.initScriptPath)
84+
.withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS)
85+
.withNetworkAliases(ARTIFACTORY_NETWORK_ALIAS);
86+
87+
network.ifPresent(postgresql::withNetwork);
88+
configureCommonsAndStart(postgresql, postgresqlProperties, log);
89+
7590
GenericContainer<?> container =
7691
new GenericContainer<>(ContainerUtils.getDockerImageName(properties))
7792
.withExposedPorts(properties.getRestApiPort(), properties.getGeneralPort())
7893
.withNetwork(Network.SHARED)
7994
.withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS)
95+
.withEnv("username", postgresqlProperties.user)
96+
.withEnv("password", postgresqlProperties.password)
97+
.withEnv("url", "jdbc:postgresql://localhost:5432/" + postgresqlProperties.database)
98+
.withEnv("type", "postgresql")
99+
.withEnv("driver", "org.postgresql.Driver")
80100
.waitingFor(artifactoryWaitStrategy);
81101

82102
network.ifPresent(container::withNetwork);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.playtika.testcontainer.artifactory;
2+
3+
import com.playtika.testcontainer.common.properties.CommonContainerProperties;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import org.springframework.boot.context.properties.ConfigurationProperties;
7+
8+
@Data
9+
@EqualsAndHashCode(callSuper = true)
10+
@ConfigurationProperties("embedded.artifactory.postgresql")
11+
public class PostgreSQLProperties extends CommonContainerProperties {
12+
static final String BEAN_NAME_EMBEDDED_POSTGRESQL = "embeddedPostgreSql";
13+
14+
String user = "artifactory";
15+
String password = "artifactory";
16+
String database = "artifactory";
17+
String startupLogCheckRegex;
18+
/**
19+
* The SQL file path to execute after the container starts to initialize the database.
20+
*/
21+
String initScriptPath;
22+
23+
// https://hub.docker.com/_/postgres
24+
@Override
25+
public String getDefaultDockerImage() {
26+
// Please don`t remove this comment.
27+
// renovate: datasource=docker
28+
return "postgres:17-alpine";
29+
}
30+
}

0 commit comments

Comments
 (0)