|
19 | 19 | import org.springframework.core.env.MapPropertySource; |
20 | 20 | import org.testcontainers.containers.GenericContainer; |
21 | 21 | import org.testcontainers.containers.Network; |
| 22 | +import org.testcontainers.containers.PostgreSQLContainer; |
22 | 23 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; |
23 | 24 | import org.testcontainers.containers.wait.strategy.WaitStrategy; |
24 | 25 | import org.testcontainers.toxiproxy.ToxiproxyContainer; |
|
34 | 35 | @ConditionalOnExpression("${embedded.containers.enabled:true}") |
35 | 36 | @AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class) |
36 | 37 | @ConditionalOnProperty(name = "embedded.artifactory.enabled", matchIfMissing = true) |
37 | | -@EnableConfigurationProperties(ArtifactoryProperties.class) |
| 38 | +@EnableConfigurationProperties({ArtifactoryProperties.class, PostgreSQLProperties.class}) |
38 | 39 | public class EmbeddedArtifactoryBootstrapConfiguration { |
39 | 40 |
|
40 | 41 | private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker"; |
@@ -70,14 +71,33 @@ ToxiproxyClientProxy artifactoryContainerProxy(ToxiproxyClient toxiproxyClient, |
70 | 71 | @Bean(name = ARTIFACTORY_BEAN_NAME, destroyMethod = "stop") |
71 | 72 | public GenericContainer<?> artifactory(ConfigurableEnvironment environment, |
72 | 73 | ArtifactoryProperties properties, |
| 74 | + PostgreSQLProperties postgresqlProperties, |
73 | 75 | WaitStrategy artifactoryWaitStrategy, |
74 | 76 | Optional<Network> network) { |
75 | 77 |
|
| 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 | + |
76 | 91 | GenericContainer<?> container = |
77 | 92 | new GenericContainer<>(ContainerUtils.getDockerImageName(properties)) |
78 | 93 | .withExposedPorts(properties.getRestApiPort(), properties.getGeneralPort()) |
79 | 94 | .withNetwork(Network.SHARED) |
80 | 95 | .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") |
81 | 101 | .waitingFor(artifactoryWaitStrategy); |
82 | 102 |
|
83 | 103 | network.ifPresent(container::withNetwork); |
|
0 commit comments