2017-10-04 67 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我同意。如果模板不進化,那麼這將是有用的。我在答案中添加註釋。 –

相關問題