55 lines
1.4 KiB
Ruby
Executable file
55 lines
1.4 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?
|
|
|
|
initial = !!ARGV.delete('--initial')
|
|
travis = !!ARGV.delete('--travis')
|
|
|
|
raise 'Select single option' if initial && travis
|
|
|
|
raise 'Set env var POSTGRES_USER' if travis && postgres_user.nil?
|
|
raise 'Set env var POSTGRES_DB' if travis && postgres_db.nil?
|
|
|
|
FileUtils.chdir APP_ROOT do
|
|
puts '== Update RubyGems =='
|
|
system! 'gem update --system'
|
|
|
|
puts '== Update Bundler =='
|
|
system! "gem install bundler -v '~> 2.0'"
|
|
|
|
puts '== Installing gems =='
|
|
system 'bin/bundle check' or system! 'bin/bundle install'
|
|
|
|
puts '== Install JavaScript dependencies =='
|
|
system! 'bin/rake yarn:install'
|
|
|
|
if initial
|
|
puts '== Preparing database =='
|
|
system! 'bin/rails db:setup'
|
|
elsif travis
|
|
puts '== Preparing database =='
|
|
system! "psql -U #{postgres_user} -c 'CREATE DATABASE #{postgres_db};'"
|
|
else
|
|
puts '== Updating database =='
|
|
system! 'bin/rails db:migrate'
|
|
end
|
|
|
|
puts '== Removing old logs and tempfiles =='
|
|
system! 'bin/rails log:clear tmp:clear'
|
|
|
|
puts '== Restarting application server =='
|
|
system! 'bin/rails restart'
|
|
end
|