Make bin/setup predictable and repeatable and remove bin/update (#6566)

* Make bin/setup predictable and remove bin/update

* System not puts

* Give priority to ENV DATABASE_URL
This commit is contained in:
rhymes 2020-03-10 15:46:23 +01:00 committed by GitHub
parent 8ab7a3fb6c
commit 235367e073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 49 deletions

View file

@ -1,16 +1,22 @@
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
DB = if ENV['DATABASE_URL'].to_s.empty?
'PracticalDeveloper_development'
else
ENV['DATABASE_URL']
end
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
FileUtils.chdir APP_ROOT do
# This script is a way to set up or update your development environment automatically.
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
@ -24,16 +30,22 @@ chdir APP_ROOT do
puts "\n== Copying sample files =="
unless File.exist?('config/database.yml')
cp 'config/database.yml.sample', 'config/database.yml'
FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
end
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
command = "psql -o /dev/null -q -n -c 'select 1' #{DB}"
db_exists = system(command)
if db_exists
system! 'bin/rails db:migrate'
else
system! 'bin/rails db:setup'
end
puts "\n== Preparing Elasticsearch =="
system! 'bin/rails search:setup'
puts "\n== Update Data =="
puts "\n== Updating Data =="
system! 'bin/rails data_updates:run'
puts "\n== Removing old logs and tempfiles =="

View file

@ -1,37 +0,0 @@
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
system('bin/yarn')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Update Elasticsearch =="
system! 'bin/rails search:setup'
puts "\n== Update Data =="
system! 'bin/rails data_updates:run'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

View file

@ -41,12 +41,10 @@ end
```
Once your script is in place then you can either run `rails data_updates:run`
manually or you can let our setup and update scripts handle it. In our local
[bin/setup](https://github.com/thepracticaldev/dev.to/blob/master/bin/setup#L36)
and
[bin/update](https://github.com/thepracticaldev/dev.to/blob/master/bin/update#L26)
scripts you will see we have added an additional task to "Update Data". This
kicks off the rake task `data_updates:run` for you.
manually or you can let our setup script handle it. In our local
[bin/setup](https://github.com/thepracticaldev/dev.to/blob/master/bin/setup)
script you will see we have added an additional task to update data. This kicks
off the rake task `data_updates:run` for you.
The rake task itself will check the `lib/data_update_scripts` folder to see if
there are any new scripts that need to be run. It does this by reading all of