java - 使用插件启动 ElasticSearch 的测试容器
问题描述
我正在使用 testcontainers.orgdocker.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")
但是容器已经启动并且弹性搜索已经在运行,所以插件不会被加载,所以我需要杀死它并复制它的创建方式,听起来像是很多黑客攻击。有没有更好的方法来做到这一点?
解决方案
我通过使用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);
推荐阅读
- java - 如何使用嵌套的 json 数组反序列化 json 对象
- c# - 无法在 Web 服务 wcf 中发送或接收大尺寸数组
- java - 我在哪里可以在 Eclipse 中找到这个小部件?
- linux - 非法选项 -p /bin/sh: 1: Usage:: not found
- java - Gigya SDK v4 Facebook 登录问题
- c# - 如何使用功能区上的按钮在资源管理器中对电子邮件进行绿色检查?
- corda - Corda — 使用 FilteredTransaction 与交易对手共享状态子集
- angular - 如何使用 TypeScript 提取接口的属性(最好没有 3rd 方库)
- acumos - 关系状态为待处理
- java - Android 上未安装 Android 应用程序错误