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