Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use elasticsearch in gitlab-ci

I tried to use the elasticsearch service in gitlab -ci by adding:

image: python:3.6
services:
  - elasticsearch:2.4

in my .gitlab-ci.yml

Unfortunately it doesn't seem to work (I cannot a connection refused on http://127.0.0.1:9200/). Any idea?

I also tried to launch the docker image with:

test:
  script:
  - docker run -d elasticsearch

But docker is not present...

like image 279
millerf Avatar asked Dec 06 '22 14:12

millerf


1 Answers

For Elasticsearch 7, a working config looks like this:

test-elasticsearch:
  stage: test
  services:
    - name: "docker.elastic.co/elasticsearch/elasticsearch:7.10.1"
      alias: "elasticsearch"
      command: [ "bin/elasticsearch", "-Expack.security.enabled=false", "-Ediscovery.type=single-node" ]
  script:
    - curl "http://elasticsearch:9200/_cat/health"

However, you can also have a look whether there is an embedded elasticsearch available for your runtime, e.g. for Java there are "testcontainers": https://www.testcontainers.org/modules/elasticsearch/. That way it's also easier to run tests locally for devs, since they don't need to worry about spinning up elasticsearch first.

like image 165
bersling Avatar answered Dec 22 '22 10:12

bersling