2019-04-27 08:13:37 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
APP_ROOT = File.expand_path('..', __dir__).freeze
|
|
|
|
|
|
|
|
def system!(*args)
|
|
|
|
system(*args) or abort "\n== Command #{args} failed =="
|
|
|
|
end
|
|
|
|
|
2019-04-27 08:45:16 -04:00
|
|
|
postgres_user = ENV['POSTGRES_USER'].to_s.strip
|
|
|
|
postgres_user = nil if postgres_user.empty?
|
|
|
|
|
|
|
|
postgres_db = ENV['POSTGRES_DB'].to_s.strip
|
|
|
|
postgres_db = nil if postgres_db.empty?
|
|
|
|
|
2019-04-27 08:13:37 -04:00
|
|
|
FileUtils.chdir APP_ROOT do
|
|
|
|
puts '== Update RubyGems =='
|
|
|
|
system! 'gem update --system'
|
|
|
|
|
|
|
|
puts '== Update Bundler =='
|
2020-01-17 04:02:40 -05:00
|
|
|
system! "gem install bundler -v '~> 2.0' --conservative"
|
2019-04-27 08:13:37 -04:00
|
|
|
|
|
|
|
puts '== Installing gems =='
|
2020-01-17 04:02:40 -05:00
|
|
|
system 'bundle check' or system! 'bundle install'
|
2019-04-27 08:13:37 -04:00
|
|
|
|
|
|
|
puts '== Install JavaScript dependencies =='
|
2020-01-17 04:02:40 -05:00
|
|
|
system! 'bundle exec rake yarn:install'
|
2019-04-27 08:13:37 -04:00
|
|
|
|
2020-01-17 03:57:04 -05:00
|
|
|
puts '== Preparing database =='
|
|
|
|
if postgres_user && postgres_db
|
2019-04-27 08:45:16 -04:00
|
|
|
system! "psql -U #{postgres_user} -c 'CREATE DATABASE #{postgres_db};'"
|
2019-04-27 08:13:37 -04:00
|
|
|
end
|
2020-01-17 04:02:40 -05:00
|
|
|
system! 'bundle exec rake db:prepare'
|
2020-01-17 04:24:57 -05:00
|
|
|
system! 'bundle exec rake db:prepare RAILS_ENV=test'
|
2019-04-27 08:13:37 -04:00
|
|
|
|
|
|
|
puts '== Removing old logs and tempfiles =='
|
2020-01-17 04:02:40 -05:00
|
|
|
system! 'bundle exec rake log:clear tmp:clear'
|
2019-04-27 08:13:37 -04:00
|
|
|
|
|
|
|
puts '== Restarting application server =='
|
2020-01-17 04:02:40 -05:00
|
|
|
system! 'bundle exec rake restart'
|
2019-04-27 08:13:37 -04:00
|
|
|
end
|