亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用插件啟動ElasticSearch的測試容器

使用插件啟動ElasticSearch的測試容器

揚帆大魚 2023-09-06 15:01:07
我正在使用 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")但是容器已經啟動并且彈性搜索已經在運行,所以插件不會被加載,所以我需要殺死它并復制它的創建方式,聽起來像是很多黑客攻擊。有更好的方法來做到這一點嗎?
查看完整描述

3 回答

?
皈依舞

TA貢獻1851條經驗 獲得超3個贊

例如,以下代碼片段對我有用:

@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);


查看完整回答
反對 回復 2023-09-06
?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

對我來說這有效:


private static final String DOCKER_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch:6.8.5"

private static final ElasticsearchContainer container = new ElasticsearchContainer(DOCKER_IMAGE);


static {

    container.withCreateContainerCmdModifier((cmd) -> {

        cmd.withCmd(

            "bash", "-c", "./bin/elasticsearch-plugin install analysis-icu && docker-entrypoint.sh eswrapper");


    });

    container.withStartupTimeout(Duration.ofSeconds(60));

}



@BeforeClass

public static void start() {

    container.start();

}


@AfterClass

public static void stop() {

    container.stop();

}

請注意,本示例中的 Elasticsearch 版本 6.8.5 較舊,您可能應該使用較新的版本。


查看完整回答
反對 回復 2023-09-06
?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

我能夠通過這種方式啟動帶有插件的 Elasticsearch 測試容器(這是 Kotlin 代碼):


ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.10.0").apply {

    withCreateContainerCmdModifier { cmd ->

        cmd.withCmd(

            *arrayOf(

                "bash",

                "-c",

                """/usr/share/elasticsearch/bin/elasticsearch-plugin install <URL> &&

                   su elasticsearch -s /usr/share/elasticsearch/bin/elasticsearch

                """.trimIndent()

            )

        )

    }

    start()

}


查看完整回答
反對 回復 2023-09-06
  • 3 回答
  • 0 關注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號