0

I am running elasticsearch inside a docker container. Dockerfile for the image looks like this:

# Dockerfile.ruby-2.4.1-elasticsearch-1.4.4
FROM ruby:2.4.1

# Install Java 8
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \
  echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \
  apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \
  apt-get update && \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
  apt-get install -y oracle-java8-installer && \
  apt-get clean

# Download and unpack elasticsearch 1.4.4
RUN wget -q -O elasticsearch-1.4.4.tar.gz https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.4.4.tar.gz && \
  tar -xzf elasticsearch-1.4.4.tar.gz && \
  mv elasticsearch-1.4.4 $HOME/.elasticsearch && \
  ln -s $HOME/.elasticsearch/bin/elasticsearch /usr/local/bin/elasticsearch && \
  mkdir -p /usr/local/share/elasticsearch/ && \
  cp $HOME/.elasticsearch/bin/elasticsearch.in.sh /usr/local/share/elasticsearch/ && \
  rm elasticsearch-1.4.4.tar.gz

When I build it

docker build - < .gitlab-ci/Dockerfile.ruby-2.4.1-elasticsearch-1.4.4 -t hirurg103/ruby-2.4.1-elasticsearch-1.4.4

and start an interactive bash session

docker run -i -t hirurg103/ruby-2.4.1-elasticsearch-1.4.4 bash

and run elasticsearch --version inside the container I get

/usr/local/bin/elasticsearch: 168: shift: can't shift that many

The elasticsearch bin script on the line 168 looks the following way:

...
# Parse any long getopt options and put them into properties before calling getopt below
# Be dash compatible to make sure running under ubuntu works
ARGV=""
while [ $# -gt 0 ]
do
    case $1 in
      --*=*) properties="$properties -Des.${1#--}"
           shift 1
           ;;
      --*) properties="$properties -Des.${1#--}=$2"
           shift 2
           ;;
      *) ARGV="$ARGV $1" ; shift
    esac
done
...

Actual problem happens when I start my rspec tests and they fail with

/usr/local/bin/elasticsearch: 168: shift: can't shift that many
rake aborted!
Cannot determine Elasticsearch version from [elasticsearch --version] or [elasticsearch -v]

elasticsearch --version is being called from elasticsearch-extensions ruby gem

What is wrong with this script? How can I fix this error?

BTW on my local machine Mac OS 10.14.1 Mojave and zsh 5.6.2 tests run smoothly

Hirurg103
  • 4,783
  • 2
  • 34
  • 50
  • You can't shift when you run out of arguments. The real question should be "How to resolve “shift: can't shift that many” error while running a shell script?" and it has been already answered: https://stackoverflow.com/questions/38216468/how-to-resolve-shift-cant-shift-that-many-error-while-running-a-shell-script – gile Dec 29 '18 at 14:20
  • @gile the problem is that this elasticsearch bin script is being called by `elasticsearch-extensions` library and fails at runtime. See source https://github.com/elastic/elasticsearch-ruby/blob/v0.0.30/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb#L487. It is not in my source code and I cannot fix it – Hirurg103 Dec 29 '18 at 14:29
  • I don't think --version is a valid option for elasticsearch script. Giving a quick look at the script, it seems is waiting for --option=value or something similar. Starting elasticsearch script with good options, I'm able to get 1.4.4 version from my browser, calling bound ip and port 9200. – gile Dec 29 '18 at 15:09
  • Do you think there is a bug in the [elasticsearch-extensions](https://github.com/elastic/elasticsearch-ruby/blob/v0.0.30/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb#L487) library and I need to add an issue on Github? – Hirurg103 Dec 29 '18 at 15:12

1 Answers1

0

For now I was able to resolve this error by specifying the elasticsearch version directly when initializing Elasticsearch::Extensions::Test::Cluster:

require 'elasticsearch/extensions/test/cluster'
Elasticsearch::Extensions::Test::Cluster.start(
  port: 9250,
  version: '1.0'
)
Hirurg103
  • 4,783
  • 2
  • 34
  • 50