From a13533c92033b67f3397231affe582666629ef44 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Fri, 7 Feb 2020 09:01:59 -0500 Subject: [PATCH] Setup Elasticsearch indexes during Deploy and Local App Setup (#5939) * setup Elasticsearch indexes during deploy and local app setup * cleanup previous duplicate sentence * remove more duplicate docs --- bin/setup | 3 +++ bin/update | 3 +++ docs/deployment.md | 20 +++++++++++--------- release-tasks.sh | 4 +++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bin/setup b/bin/setup index 5ff26024f..9ad525977 100755 --- a/bin/setup +++ b/bin/setup @@ -28,6 +28,9 @@ chdir APP_ROOT do puts "\n== Preparing database ==" system! 'bin/rails db:setup' + puts "\n== Preparing Elasticsearch ==" + system! 'bin/rails search:setup' + puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/bin/update b/bin/update index 6d73559a3..b5dc3d52d 100755 --- a/bin/update +++ b/bin/update @@ -23,6 +23,9 @@ chdir APP_ROOT do puts "\n== Updating database ==" system! 'bin/rails db:migrate' + puts "\n== Update Elasticsearch ==" + system! 'bin/rails search:setup' + puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/docs/deployment.md b/docs/deployment.md index 25beabbe4..1a1b7273b 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -26,7 +26,8 @@ Some of the steps will be parallelized in the future: 1. `bundle-audit` checks for any known vulnerability. 1. Travis builds Storybook to ensure its integrity. 1. Travis deploys code to Heroku. - - Heroku runs the database migrations before deployment. + - Heroku runs the database migrations and Elasticsearch updates before + deployment. 1. Travis notifies the team that the process completed. ## Deploying to Heroku @@ -44,13 +45,14 @@ This will cause the release script to exit with a code of 1 which will halt the deploy. This ensures that we don't accidentally push out code while we are waiting for a fix or running other tasks. Next, we run any outstanding migrations. This ensures that a migration finishes successfully before the code -that uses it goes live. After running migrations, we use the Rails runner to -output a simple string. Executing a Rails runner command ensures that we can -boot up the entire app successfully before it is deployed. We deploy -asynchronously, so the website is running the new code a few minutes after -deploy. A new instance of Heroku Rails console will immediately run a new code. -We deploy asynchronously, so the website is running the new code a few minutes -after deploy. A new instance of Heroku Rails console will immediately run a new -code. +that uses it goes live. After running migrations, we update Elasticsearch. +Elasticsearch contains indexes which have mappings. Mappings are similar to +database schema. The same way we run a migration to update our database we have +to run a setup task to update any Elasticsearch mappings. Following updating all +of our datastores we use the Rails runner to output a simple string. Executing a +Rails runner command ensures that we can boot up the entire app successfully +before it is deployed. We deploy asynchronously, so the website is running the +new code a few minutes after deploy. A new instance of Heroku Rails console will +immediately run a new code. ![](https://devcenter0.assets.heroku.com/article-images/1494371187-release-phase-diagram-3.png) diff --git a/release-tasks.sh b/release-tasks.sh index 0c76f5e51..d18ad7256 100755 --- a/release-tasks.sh +++ b/release-tasks.sh @@ -6,6 +6,8 @@ set -x # abort release if deploy status equals "blocked" [[ $DEPLOY_STATUS = "blocked" ]] && echo "Deploy blocked" && exit 1 -# runs migration and boots the app to check there are no errors +# runs migration for Postgres, setups/updates Elasticsearch +# and boots the app to check there are no errors STATEMENT_TIMEOUT=180000 bundle exec rails db:migrate && \ + bundle exec rake search:setup && \ bundle exec rails runner "puts 'app load success'"