docker-maven-plugin
docker-maven-plugin copied to clipboard
How can i get a container host name in a CI runner?
I'm setting up an integration testing environment for my springboot Java app. So I'm spinning off a postgresql DB using docker-maven-plugin , which my application is supposed to call into. This setup works ok when running maven verify on my local system, but on the gitlab CI runner, is failing, because the postgresql hostname doesn't match anymore. My question is, how can i get the host name of the DB container in the CI pipeline?
My .pom plugin definition, looks something like this:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.maven.plugin.version}</version>
<executions>
<execution>
<id>prepare-it-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<name>postgres:9.6.14</name>
<alias>it-database</alias>
<run>
<ports>
<port>it-database.port:5432</port>
</ports>
<wait>
<log>(?s)database system is ready to accept connections.*database system is ready to accept connections</log>
<time>20000</time>
</wait>
<log>
<prefix>POSTGRESQL-TEST</prefix>
<date>ISO8601</date>
<color>blue</color>
</log>
</run>
</image>
</images>
</configuration>
</execution>
<execution>
<id>remove-it-database</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Eventually, I will have to pass that DB hostname in my application yaml:
spring:
datasource:
platform: postgresql
url: jdbc:postgresql://<db_host_name_here_once_i_get_it>:${it-database.port}/postgres
username: postgres
password: postgres
schema: classpath:schema-postgresql.sql
data: classpath:data-postgresql.sql
driver-class-name: org.postgresql.Driver
initialization-mode: always
Thanks
I have the same problem. Did you find a solution?