Got*_*nal 5 java elasticsearch testcontainers
我正在使用 testcontainers.org docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.2
,我想用它来测试我正在更新的插件,但我找不到在测试环境中安装它的方法。
我可以尝试复制里面的文件并安装它
ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:$ELASTIC_VERSION")
String pluginPath = "/usr/share/elasticsearch/$PLUGIN_FILE_NAME"
container.start()
container.copyFileToContainer(MountableFile.forHostPath(new File(PLUGIN_PLUGIN_PATH).toPath()), pluginPath)
ExecResult result = container.execInContainer("bin/elasticsearch-plugin", "install", "file://$pluginPath")
Run Code Online (Sandbox Code Playgroud)
但是容器已经启动并且弹性搜索已经在运行,所以插件不会被加载,所以我需要杀死它并复制它的创建方式,听起来像是很多黑客攻击。有更好的方法来做到这一点吗?
我通过使用Testcontainers Dockerfile DSL解决了这个问题
例如,以下代码片段对我有用:
@ClassRule
public static GenericContainer elastic = new GenericContainer(new ImageFromDockerfile()
.withDockerfileFromBuilder(
builder -> builder.from("elasticsearch:6.8.4")
.run("bin/elasticsearch-plugin", "install", "analysis-icu")
.run("bin/elasticsearch-plugin", "install", "analysis-smartcn")
.build()
)).withExposedPorts(9200);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1599 次 |
最近记录: |