Gitlab CI, how to get a container host name, started with docker-maven-plugin

343 views Asked by At

I'm setting up an integration testing environment for my Spring Boot Java application. So I'm spinning off a PostgreSQL database using docker-maven-plugin, which my application is supposed to call into.

This setup works ok when running mvn 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 hostname of the database container in the CI pipeline?

My plugin configuration 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 database 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
0

There are 0 answers