Skip to content

Commit bfe5f71

Browse files
author
admitrov
committed
add postgres
1 parent 7dbf852 commit bfe5f71

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
@@ -23,6 +23,10 @@
2323
<groupId>com.playtika.testcontainers</groupId>
2424
<artifactId>embedded-toxiproxy</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.testcontainers</groupId>
28+
<artifactId>postgresql</artifactId>
29+
</dependency>
2630

2731
<dependency>
2832
<groupId>io.rest-assured</groupId>
@@ -41,4 +45,4 @@
4145
</exclusions>
4246
</dependency>
4347
</dependencies>
44-
</project>
48+
</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
@@ -19,6 +19,7 @@
1919
import org.springframework.core.env.MapPropertySource;
2020
import org.testcontainers.containers.GenericContainer;
2121
import org.testcontainers.containers.Network;
22+
import org.testcontainers.containers.PostgreSQLContainer;
2223
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
2324
import org.testcontainers.containers.wait.strategy.WaitStrategy;
2425
import org.testcontainers.toxiproxy.ToxiproxyContainer;
@@ -34,7 +35,7 @@
3435
@ConditionalOnExpression("${embedded.containers.enabled:true}")
3536
@AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class)
3637
@ConditionalOnProperty(name = "embedded.artifactory.enabled", matchIfMissing = true)
37-
@EnableConfigurationProperties(ArtifactoryProperties.class)
38+
@EnableConfigurationProperties({ArtifactoryProperties.class, PostgreSQLProperties.class})
3839
public class EmbeddedArtifactoryBootstrapConfiguration {
3940

4041
private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker";
@@ -70,14 +71,33 @@ ToxiproxyClientProxy artifactoryContainerProxy(ToxiproxyClient toxiproxyClient,
7071
@Bean(name = ARTIFACTORY_BEAN_NAME, destroyMethod = "stop")
7172
public GenericContainer<?> artifactory(ConfigurableEnvironment environment,
7273
ArtifactoryProperties properties,
74+
PostgreSQLProperties postgresqlProperties,
7375
WaitStrategy artifactoryWaitStrategy,
7476
Optional<Network> network) {
7577

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

83103
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)