diff --git a/.travis.yml b/.travis.yml index 6de58c103..bc4ec480d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,7 @@ addons: secure: "PfhLGBKRgNqhKuYCJsK+VPhdAzcgWFGeeOyxC/eS8gtlvIISVdgyZE+r30uIei0DFI6zEiN62eW4d+xtT4j7/e2ZcAcx7U52mza/SnQNuu3nCGQDJB8VOvV5NbnwXfi8vfr4e889Mt7k3ocd2c4gqB4UtRqrzhygj7HN+B/GfEk=" env: matrix: - # - 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 + - ELASTIC_SEARCH_VERSION="7.5.1-amd64" COVERAGE=true RAILS_ENV=test # Future target (production needs upgrading) - STATIC_CHECKS=true global: - secure: "Z5TpM2jEX4UCvNePnk/LwltQX48U2u9BRc+Iypr1x9QW2o228QJhPIOH39a8RMUrepGnkQIq9q3ZRUn98RfrJz1yThtlNFL3NmzdQ57gKgjGwfpa0e4Dwj/ZJqV2D84tDGjvdVYLP7zzaYZxQcwk/cgNpzKf/jq97HLNP7CYuf4=" @@ -32,9 +30,10 @@ before_install: - sudo apt clean - sudo apt update - sudo apt install dpkg + - ./script/install_elasticsearch.sh - sudo apt install google-chrome-stable - ./script/install_linters.sh - - ./script/install_elasticsearch.sh + - ./script/check_elasticsearch.sh script: - > if [ "${STATIC_CHECKS}" = "true" ]; then diff --git a/Gemfile.lock b/Gemfile.lock index 581389884..82d139dc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -183,8 +183,8 @@ GEM factory_bot_rails (5.1.1) factory_bot (~> 5.1.0) railties (>= 4.2.0) - faker (2.10.0) - i18n (>= 1.6, < 1.8) + faker (2.10.1) + i18n (>= 1.6, < 2) faraday (0.17.3) multipart-post (>= 1.2, < 3) faraday_middleware (0.13.1) @@ -241,7 +241,7 @@ GEM httparty (0.17.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.7.1) + i18n (1.8.2) concurrent-ruby (~> 1.0) i18n-tasks (0.9.30) activesupport (>= 4.0.2) diff --git a/app/models/concerns/search_crops.rb b/app/models/concerns/search_crops.rb index dc5da769f..4a072ef99 100644 --- a/app/models/concerns/search_crops.rb +++ b/app/models/concerns/search_crops.rb @@ -10,7 +10,7 @@ module SearchCrops searchable: %i(name descriptions alternate_names scientific_names), case_sensitive: false, merge_mappings: true, - settings: { number_of_shards: 1 }, + settings: { number_of_shards: 1, number_of_replicas: 0 }, mappings: { properties: { created_at: { type: :integer }, diff --git a/app/models/concerns/search_harvests.rb b/app/models/concerns/search_harvests.rb index a87901670..79b7c9796 100644 --- a/app/models/concerns/search_harvests.rb +++ b/app/models/concerns/search_harvests.rb @@ -5,7 +5,7 @@ module SearchHarvests included do searchkick merge_mappings: true, - settings: { number_of_shards: 1 }, + settings: { number_of_shards: 1, number_of_replicas: 0 }, mappings: { properties: { harvests_count: { type: :integer }, diff --git a/app/models/concerns/search_photos.rb b/app/models/concerns/search_photos.rb index 7a9880b84..786d7c34c 100644 --- a/app/models/concerns/search_photos.rb +++ b/app/models/concerns/search_photos.rb @@ -5,7 +5,7 @@ module SearchPhotos included do searchkick merge_mappings: true, - settings: { number_of_shards: 1 }, + settings: { number_of_shards: 1, number_of_replicas: 0 }, mappings: { properties: { title: { type: :text }, diff --git a/app/models/concerns/search_plantings.rb b/app/models/concerns/search_plantings.rb index dbedd7ab4..680b4a1d7 100644 --- a/app/models/concerns/search_plantings.rb +++ b/app/models/concerns/search_plantings.rb @@ -5,7 +5,7 @@ module SearchPlantings included do searchkick merge_mappings: true, - settings: { number_of_shards: 1 }, + settings: { number_of_shards: 1, number_of_replicas: 0 }, mappings: { properties: { active: { type: :boolean }, diff --git a/app/models/concerns/search_seeds.rb b/app/models/concerns/search_seeds.rb index 9662ef763..f9866383e 100644 --- a/app/models/concerns/search_seeds.rb +++ b/app/models/concerns/search_seeds.rb @@ -5,7 +5,7 @@ module SearchSeeds included do searchkick merge_mappings: true, - settings: { number_of_shards: 1 }, + settings: { number_of_shards: 1, number_of_replicas: 0 }, mappings: { properties: { id: { type: :integer }, diff --git a/script/check_elasticsearch.sh b/script/check_elasticsearch.sh new file mode 100755 index 000000000..5f1c45a50 --- /dev/null +++ b/script/check_elasticsearch.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [[ -z "$ELASTIC_SEARCH_VERSION" ]]; then + echo "ELASTIC_SEARCH_VERSION variable not set" +else + 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 + + echo "SUCCESS. Elasticsearch is responding." +fi diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh index ba533782e..d040e241a 100755 --- a/script/install_elasticsearch.sh +++ b/script/install_elasticsearch.sh @@ -12,33 +12,19 @@ else 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" + if [[ $ELASTIC_SEARCH_VERSION == 7\.* ]]; then + # https://stackoverflow.com/questions/55951531/running-elasticsearch-7-0-on-a-travis-xenial-build-host + 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 + fi + 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."