43 lines
1.1 KiB
Ruby
Executable file
43 lines
1.1 KiB
Ruby
Executable file
#!/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
|
|
|
|
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?
|
|
|
|
FileUtils.chdir APP_ROOT do
|
|
puts '== Update RubyGems =='
|
|
system! 'gem update --system'
|
|
|
|
puts '== Update Bundler =='
|
|
system! "gem install bundler -v '~> 2.0' --conservative"
|
|
|
|
puts '== Installing gems =='
|
|
system 'bundle check' or system! 'bundle install'
|
|
|
|
puts '== Install JavaScript dependencies =='
|
|
system! 'bundle exec rake yarn:install'
|
|
|
|
puts '== Preparing database =='
|
|
if postgres_user && postgres_db
|
|
system! "psql -U #{postgres_user} -c 'CREATE DATABASE #{postgres_db};'"
|
|
end
|
|
system! 'bundle exec rake db:prepare'
|
|
system! 'bundle exec rake db:prepare RAILS_ENV=test'
|
|
|
|
puts '== Removing old logs and tempfiles =='
|
|
system! 'bundle exec rake log:clear tmp:clear'
|
|
|
|
puts '== Restarting application server =='
|
|
system! 'bundle exec rake restart'
|
|
end
|