2

The Xenial (Ubuntu 16.04) image on Travis-CI comes with Elasticsearch-5.5 preinstalled. What should I put in my .travis.yml to run my builds against Elasticsearch-7.0?

3 Answers 3

7

Add these commands to your before_install step:

- curl -s -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.1-amd64.deb
- sudo dpkg -i --force-confnew elasticsearch-7.0.1-amd64.deb
- sudo sed -i.old 's/-Xms1g/-Xms128m/' /etc/elasticsearch/jvm.options
- sudo sed -i.old 's/-Xmx1g/-Xmx128m/' /etc/elasticsearch/jvm.options
- echo -e '-XX:+DisableExplicitGC\n-Djdk.io.permissionsUseCanonicalPath=true\n-Dlog4j.skipJansi=true\n-server\n' | sudo tee -a /etc/elasticsearch/jvm.options
- sudo chown -R elasticsearch:elasticsearch /etc/default/elasticsearch
- sudo systemctl start elasticsearch

The changes to jvm.options are done in an attempt to emulate the existing config for Elasticsearch-5.5, which I assume the Travis peeps have actually thought about.

According to the Travis docs, you should also add this line to your before_script step:

- sleep 10

This is to ensure Elasticsearch is up and running, but I haven't checked if it's actually necessary.

5
  • Is this intentional to have line 3 and 4 duplicate? Commented Jul 22, 2019 at 7:57
  • 1
    They're not duplicates.
    – kthy
    Commented Jul 22, 2019 at 11:19
  • Yeah nvm found the little detail that is different. Got it to work even without these 2 lines. Commented Jul 22, 2019 at 11:44
  • 1
    Thanks for this, it helped me. BTW, the sleep 10 is just in case you start your tests before elastic is ready so just to play safe give some time to start the server.
    – 4NDR01D3
    Commented Aug 21, 2019 at 9:09
  • Worked like a charm! Also remove the entry for elasticsearch under services, like @musicalmindz mentions in his answer.
    – Subhash
    Commented Sep 26, 2019 at 4:38
2

One small addition to @kthy answer that had me stumbling for a bit. You need to remove - elasticsearch from your services: definition in the .travis.yml otherwise no matter what you put in before_install, the default service will override it!

services:
  - elasticsearch

Remove ^^ and then you can proceed with the steps he outlined and it should all work smoothly.

0
2

if you want to wait for the elastic search to start (which may be longer or shorter than 10 seconds) replace the sleep 10 with this:

  host="localhost:9200"
  response=""
  attempt=0

  until [ "$response" = "200" ]; do
      if [ $attempt -ge 25 ]; then
        echo "FAILED. Elasticsearch not responding after $attempt tries."
        exit 1
      fi
      echo "Contacting Elasticsearch on ${host}. Try number ${attempt}"
      response=$(curl --write-out %{http_code} --silent --output /dev/null "$host")

      sleep 1
      attempt=$[$attempt+1]
  done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.