正如标题所说,我正在尝试找到一种方法来运行 liquibase 脚本,我们拥有来自 maven 的新鲜 mysql docker 图像以运行集成测试。
到目前为止,我只找到了用于拉取和运行我的 docker 容器的 maven 插件,并且我设法将我需要的其他项目中的 liquibase xml 和 sql 拉到当前项目中。
<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 插件,但仍然面临 liquibase 在 mysql docker 镜像中更新架构的问题。出现错误:
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 中,这可以使用规则来修复,以等待这样的端口:
<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>
关于java - 在 maven 的 docker 中运行的 mysql 图像上的 liquibase 脚本用于集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45667295/