如标题所述,我正在尝试找到一种方法来运行liquibase脚本,这些脚本已覆盖来自maven的最新mysql docker镜像,以针对其运行集成测试。
到目前为止,我只找到了maven插件来拉并运行我的docker容器,我设法将liquibase xml和sqls从我需要的另一个项目中拉到了当前项目中。
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.13.9</version>
<configuration>
<useColor>true</useColor>
<verbose>true</verbose>
<removeVolumes>true</removeVolumes>
<images>
<image>
<name>mysql:5.7.9</name>
<run>
<env>
<MYSQL_ROOT_PASSWORD>${mypassword}</MYSQL_ROOT_PASSWORD>
</env>
<ports>
<port>3306:3306</port>
</ports>
<volumes>
<bind>
<volume>
${project.build.testOutputDirectory}/db-scripts:/tmp/import:ro
</volume>
</bind>
</volumes>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
但是我仍在努力寻找一种方法,以便在所有集成测试之前,如何将这些脚本应用于在docker中运行的数据库。
有人可以说明这件事。谢谢
UPD:找到了liquibase maven插件,但是仍然面临MySQL docker镜像中liquibase更新架构的问题。发生错误:
Error setting up or running Liquibase: liquibase.exception.DatabaseException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
我的liquibase插件设置:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<changeLogFile>${path_to_changelog}/changelog.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306</url>
<username>${mysql_username}</username>
<password>${mysql_password}</password>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<logging>debug</logging>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
最佳答案
在最新版本的docker-maven-plugin中,可以使用rule在以下端口上等待来解决此问题:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.25.1</version>
<extensions>true</extensions>
<configuration>
<dockerHost>http://10.10.121.137:2376</dockerHost>
<images>
<image>
<alias>docker-mvn-test</alias>
<name>mysql:5.7</name>
<run>
<wait>
<tcp>
<host>10.10.121.137</host>
<ports>
<port>3306</port>
</ports>
</tcp>
<time>20000</time>
</wait>
<env>
<MYSQL_ROOT_PASSWORD>abc123</MYSQL_ROOT_PASSWORD>
<MYSQL_DATABASE>testdb</MYSQL_DATABASE>
<MYSQL_USER>mysql</MYSQL_USER>
<MYSQL_PASSWORD>mysql</MYSQL_PASSWORD>
<MYSQL_ROOT_PASSWORD>123456</MYSQL_ROOT_PASSWORD>
</env>
<ports>
<port>3306:3306</port>
</ports>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>