diff --git a/.travis.yml b/.travis.yml index f0b53ec77..6de58c103 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ sudo: required language: ruby -dist: trusty +dist: bionic +services: + - postgresql + - xvfb cache: bundler: true directories: @@ -16,26 +19,28 @@ addons: secure: "PfhLGBKRgNqhKuYCJsK+VPhdAzcgWFGeeOyxC/eS8gtlvIISVdgyZE+r30uIei0DFI6zEiN62eW4d+xtT4j7/e2ZcAcx7U52mza/SnQNuu3nCGQDJB8VOvV5NbnwXfi8vfr4e889Mt7k3ocd2c4gqB4UtRqrzhygj7HN+B/GfEk=" env: matrix: - - COVERAGE=true + # - ELASTIC_SEARCH_VERSION="7.5.1-amd64" COVERAGE=true RAILS_ENV=test # Future target (production needs upgrading) + # - ELASTIC_SEARCH_VERSION="6.7.1" COVERAGE=true RAILS_ENV=test # last 6.x release + - ELASTIC_SEARCH_VERSION="6.2.3" COVERAGE=true RAILS_ENV=test # matches productions - STATIC_CHECKS=true global: - secure: "Z5TpM2jEX4UCvNePnk/LwltQX48U2u9BRc+Iypr1x9QW2o228QJhPIOH39a8RMUrepGnkQIq9q3ZRUn98RfrJz1yThtlNFL3NmzdQ57gKgjGwfpa0e4Dwj/ZJqV2D84tDGjvdVYLP7zzaYZxQcwk/cgNpzKf/jq97HLNP7CYuf4=" - - GROWSTUFF_EMAIL="noreply@test.growstuff.org" + - GROWSTUFF_EMAIL="noreply@test.growstuff.org"g - GROWSTUFF_SITE_NAME="Growstuff (travis)" - RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' before_install: - sudo apt clean - # - sudo apt update + - sudo apt update - sudo apt install dpkg - sudo apt install google-chrome-stable - ./script/install_linters.sh - - ELASTIC_SEARCH_VERSION="6.2.3" ./script/install_elasticsearch.sh + - ./script/install_elasticsearch.sh script: - > if [ "${STATIC_CHECKS}" = "true" ]; then ./script/check_static.rb else - RAILS_ENV=test bundle exec rake db:create db:migrate search:reindex assets:precompile; + bundle exec rake db:create db:migrate search:reindex assets:precompile; npx percy exec -- bundle exec rspec spec fi; after_script: diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh index d3a36cfc6..ba533782e 100755 --- a/script/install_elasticsearch.sh +++ b/script/install_elasticsearch.sh @@ -3,14 +3,42 @@ if [[ -z "$ELASTIC_SEARCH_VERSION" ]]; then echo "ELASTIC_SEARCH_VERSION variable not set" else - set -euv + echo "Downloading Elasticsearch ${ELASTIC_SEARCH_VERSION}" sudo dpkg -r elasticsearch + + wget "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTIC_SEARCH_VERSION}.deb" wget "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTIC_SEARCH_VERSION}.deb.sha512" + shasum -a 512 -c "elasticsearch-${ELASTIC_SEARCH_VERSION}.deb.sha512" + + echo "Installing Elasticsearch ${ELASTIC_SEARCH_VERSION}" sudo dpkg -i --force-confnew "elasticsearch-${ELASTIC_SEARCH_VERSION}.deb" - sudo service elasticsearch start - sleep 10 - curl -v localhost:9200 + echo "Starting Elasticsearch ${ELASTIC_SEARCH_VERSION}" + # sudo service elasticsearch start + sudo systemctl start elasticsearch + + host="localhost:9200" + response="" + attempt=0 + maxattempts=25 + + # this would wait forever + # until curl --silent -XGET --fail ${host} do printf '.'; sleep 1; done + + until [ "$response" = "200" ]; do + if [ $attempt -ge ${maxattempts} ]; then + echo "FAILED. Elasticsearch not responding after $attempt tries." + sudo tail /var/log/elasticsearch/*.log + 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 fi + +echo "SUCCESS. Elasticsearch is responding."