使用gitlabRunner在服务中运行配置命令

时间:2018-12-26 11:28:56

标签: 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服务以启用脚本?

1 个答案:

答案 0 :(得分:0)

command下的image类似于Dockerfile中的CMD。正如using docker images with Gitlab CI文档所说:

  

应该用作容器命令的命令或脚本。它将转换为映像名称后传递给Docker的参数。语法类似于Dockerfile的CMD指令,其中每个shell令牌都是数组中的单独字符串。

我设法通过添加从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
...