Run configuration commands inside a service with gitlab runner

Viewed 1624

I need to enable scripting for the elasticsearch service to run my rspec tests

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

I try change elasticsearch config inside a docker container the following way in my .gitlab-ci.yml:

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"]
  ...

But service container startup fails with

*** 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

*********

How can I configure elasticsearch service on gitlab CI to enable scripting?

1 Answers

Looks like command under image is equivalent to CMD in Dockerfile. As using docker images with Gitlab CI documentation says:

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.

I managed to solve my problem by adding a custom docker image inherited from elasticsearch:1.6.1:

# 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"]

I built this docker image and pushed to the docker hub. Now I use it to spawn elasticsearch service the following way:

# .gitlab-ci.yml
services:
  - hirurg103/elasticsearch-1.6.1-with-scripring-enabled:1.0
...
Related