我需要为 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 服务以启用脚本?
最佳答案
看起来像 command
下 image
相当于 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/