2017-10-04 70 views
0

我目前正在构建一个用于集成测试的自定义泊坞窗镜像。我的要求是使用默认的ingester管道和模板映射进行自定义配置。如何将elasticsearch模板与docker映像捆绑在一起?

Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch:5.6.2 
ADD config /usr/share/elasticsearch/config/ 
USER root 
RUN chown -R elasticsearch:elasticsearch config 
RUN chmod +x config/setup.sh 
USER elasticsearch 
RUN elasticsearch-plugin remove x-pack 
EXPOSE 9200 
EXPOSE 9300 

其中配置是包含目录:

> elasticsearch.yml for the configuration 
> templates in the form of json files 
> setup.sh - script which executes curl to es in order to register pipelines to _ingester and template mappings 

安装脚本是这样的:

#!/bin/bash 
# This script sets up the es5 docker instance with the correct pipelines and templates 

baseUrl='127.0.0.1:9200' 
contentType='Content-Type:application/json' 


# filebeat 
filebeatUrl=$baseUrl'/_ingest/pipeline/filebeat-pipeline?pretty' 
filebeatPayload='@pipeline/filebeat-pipeline.json' 

echo 'setting filebeat pipeline...' 
filebeatResult=$(curl -XPUT $filebeatUrl -H$contentType -d$filebeatPayload) 
echo -e "filebeat pipeline setup result: \n$filebeatResult" 

# template 
echo -e "\n\nsetting up templates..." 
sleep 1 

cd template 
for f in *.json 
do 
    templateName="${f%.*}" 
    templateUrl=$baseUrl'/_template/'$templateName 

    echo -e "\ncreating index template for $templateName..." 
    templateResult=$(curl -XPUT $templateUrl -H$contentType [email protected]$f) 
    echo -e "$templateName result: $templateResult" 
    sleep 1 
done 

echo -e "\n\n\nCompleted ES5 Setup, refer to logs for details" 

如何构建和运行该图像以这样的方式在脚本之后执行弹性是否正在运转?

+0

你的'setup.sh'脚本是怎么样的? – Val

回答

0

我通常会做的是包括一个像你这样的温暖的脚本,并在开头添加以下几行。还有,我知道在码头工人等待底层服务推出

# wait until ES is up 
until $(curl -o /dev/null -s --head --fail $baseUrl); do 
    echo "Waiting for ES to start..." 
    sleep 5 
done 
+0

谢谢瓦尔。我结束了一个有点类似于这个的解决方案。 – geneqew

+0

太棒了,很高兴它帮助! – Val

0

如果模板映射不经常不断变化的,那么你可以试试下面的解决方案没有其他办法:

您可以在您的自定义嵌入模板通过保存容器状态图像使用下列步骤(创建新的图像):

  1. 运行图像按您的dockerfile(elasticsearch会在它被盯着)
  2. 泊坞窗使用exec命令来运行你的模板(curl命令或脚本)
  3. 使用泊坞窗提交保存容器状态和创造,这将已经有模板的新形象

使用已模板mapping.You并不需要运行新创建的图像模板映射作为脚本的一部分,因为您的图像本身会拥有它。

+1

这也是一个好主意,但是如果模板经常发展,那么部署容器的步骤很多。 – Val

+1

@Val我同意。如果模板不进化,那么这将是有用的。我在答案中添加注释。 –

相关问题