elasticsearch - 使用 gitlab runner 在服务中运行配置命令

标签 elasticsearch gitlab-ci gitlab-ci-runner

我需要为 elasticsearch 服务启用脚本以运行我的 rspec 测试

# config/elasticsearch.yml
script.inline: on
script.indexed: on

我尝试在我的 .gitlab-ci.yml 中按以下方式更改 docker 容器内的 elasticsearch 配置:
rspec:
  stage: test
  services:
    - mysql:5.6.42
    - name: elasticsearch:1.6.1
      command: ["echo 'script.inline: on' >> /etc/elasticsearch/elasticsearch.yml", "echo 'script.indexed: on' >> /etc/elasticsearch/elasticsearch.yml", "systemctl restart elasticsearch"]
  ...

但是服务容器启动失败
*** WARNING: Service runner-6JNFXPMk-project-9870108-concurrent-0-elasticsearch-1 probably didn't start properly.

Health check error:
ContainerStart: Error response from daemon: Cannot link to a non running container: /runner-6LBTXPMk-project-13870108-concurrent-0-elasticsearch-1 AS /runner-6LBTXPMk-project-13870108-concurrent-0-elasticsearch-1-wait-for-service/service (executor_docker.go:1318:0s)

Service container logs:
2018-12-26T11:07:47.604151437Z /docker-entrypoint.sh: line 20: /echo 'script.inline: on' >> /etc/elasticsearch/elasticsearch.yml: No such file or directory

*********

如何在 gitlab CI 上配置 elasticsearch 服务以启用脚本?

最佳答案

看起来像 commandimage相当于 CMD在 Dockerfile 中。如 using docker images with Gitlab CI文档说:

Command or script that should be used as the container’s command. It will be translated to arguments passed to Docker after the image’s name. The syntax is similar to Dockerfile’s CMD directive, where each shell token is a separate string in the array.



我设法通过添加从 elasticsearch:1.6.1 继承的自定义 docker 图像来解决我的问题。 :
# Dockerfile
FROM elasticsearch:1.6.1

RUN echo 'script.disable_dynamic: false' >> /etc/elasticsearch/elasticsearch.yml
RUN echo 'script.inline: on' >> /etc/elasticsearch/elasticsearch.yml
RUN echo 'script.indexed: on' >> /etc/elasticsearch/elasticsearch.yml

CMD ["elasticsearch"]

我构建了这个 docker 镜像并推送到 docker hub .现在我使用它以下列方式生成 elasticsearch 服务:
# .gitlab-ci.yml
services:
  - hirurg103/elasticsearch-1.6.1-with-scripring-enabled:1.0
...

关于elasticsearch - 使用 gitlab runner 在服务中运行配置命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53931463/

相关文章:

Elasticsearch 第一个查询很慢,其余查询很快

elasticsearch - 在Elasticsearch模板中创建Geoip字段

gitlab-ci - 如何将运行者限制在特定分支并锁定 .gitlab-ci.yml 免受更改?

python - 如何使用 python 检查来自 API 的数据是否在 elasticsearch 索引中,如果不在,则将其插入

elasticsearch - fluentd 和 grok 解析器,添加一个键值

docker - Gitlab-CI:跨服务通信

ansible - 使用 Gitlab CI 中的 Ansible 进行部署,处理密码

docker - 从图像流中部署 OpenShift Origin 中的特定图像标签

git - 更改 gitlab CI 的根目录

linux - centos docker镜像在gitlab docker runner上不起作用