[deploy] Consolidate Setup Tasks to a Single Rake Task (#8065)
This commit is contained in:
parent
26c66b34d2
commit
182faa0289
6 changed files with 31 additions and 18 deletions
|
|
@ -9,8 +9,8 @@ echo "== Ensuring Elasticsearch data directory is owned by the correct uid =="
|
|||
docker-compose run elasticsearch chown elasticsearch:elasticsearch /usr/share/elasticsearch/data
|
||||
|
||||
echo "== Setting up database =="
|
||||
on_db_setup_failed() {
|
||||
echo "Database setup failed with exit code $1." >&2
|
||||
on_app_setup_failed() {
|
||||
echo "Application setup failed with exit code $1." >&2
|
||||
echo "" >&2
|
||||
echo "Check the Docker logs using:" >&2
|
||||
echo " docker-compose logs" >&2
|
||||
|
|
@ -20,7 +20,7 @@ on_db_setup_failed() {
|
|||
echo " docker-compose down -v && sudo rm -rf docker_data" >&2
|
||||
exit $1
|
||||
}
|
||||
docker-compose run web sh -c 'yarn global add wait-on && wait-on -t 30000 http-get://elasticsearch:9200/ && rails search:setup db:setup db:migrate data_updates:run' || on_db_setup_failed $?
|
||||
docker-compose run web sh -c 'yarn global add wait-on && wait-on -t 30000 http-get://elasticsearch:9200/ && rails app_initializer:setup' || on_app_setup_failed $?
|
||||
|
||||
echo "== Starting app =="
|
||||
docker-compose up
|
||||
|
|
|
|||
11
bin/setup
11
bin/setup
|
|
@ -28,17 +28,10 @@ FileUtils.chdir APP_ROOT do
|
|||
FileUtils.cp "config/database.yml.sample", "config/database.yml"
|
||||
end
|
||||
|
||||
puts "\n== Preparing Elasticsearch =="
|
||||
system! "bin/rails search:setup"
|
||||
puts "\n== Preparing Test Elasticsearch =="
|
||||
system! 'RAILS_ENV="test" bin/rails search:setup'
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
unless system("bin/rails db:migrate")
|
||||
system! "bin/rails db:setup"
|
||||
end
|
||||
|
||||
puts "\n== Updating Data =="
|
||||
system! "bin/rails data_updates:run"
|
||||
system! "bin/rails app_initializer:setup"
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system! "bin/rails log:clear tmp:clear"
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ and start the container again_
|
|||
The script executes the following steps:
|
||||
|
||||
1. `docker-compose build`
|
||||
2. `docker-compose run web rails db:setup db:migrate search:setup`
|
||||
2. `docker-compose run web rails app_initializer:setup`
|
||||
3. `docker-compose up`
|
||||
|
||||
## Running the Docker app (advanced)
|
||||
|
|
|
|||
18
lib/tasks/app_setup.rake
Normal file
18
lib/tasks/app_setup.rake
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace :app_initializer do
|
||||
desc "Prepare Application on Boot Up"
|
||||
task setup: :environment do
|
||||
puts "\n== Preparing Elasticsearch =="
|
||||
Rake::Task["search:setup"].execute
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
begin
|
||||
Rake::Task["db:migrate"].execute
|
||||
rescue ActiveRecord::NoDatabaseError
|
||||
puts "\n== Creating and Seeding database =="
|
||||
system("bin/rails db:setup")
|
||||
end
|
||||
|
||||
puts "\n== Updating Data =="
|
||||
Rake::Task["data_updates:enqueue_data_update_worker"].execute
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
namespace :data_updates do
|
||||
desc "Enqueue Sidekiq worker to handle data updates"
|
||||
task enqueue_data_update_worker: :environment do
|
||||
# Ensure new code has been deployed before we run our update scripts
|
||||
DataUpdateWorker.perform_in(10.minutes)
|
||||
if Rails.env.development?
|
||||
Rake::Task["data_updates:run"].execute
|
||||
else
|
||||
# Ensure new code has been deployed before we run our update scripts
|
||||
DataUpdateWorker.perform_in(10.minutes)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run data updates"
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ set -Eex
|
|||
|
||||
# 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
|
||||
STATEMENT_TIMEOUT=180000 bundle exec rails app_initializer:setup
|
||||
bundle exec rake fastly:update_configs
|
||||
bundle exec rake search:setup
|
||||
bundle exec rake data_updates:enqueue_data_update_worker
|
||||
bundle exec rails runner "puts 'app load success'"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue