1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/script/setup
2020-01-17 14:08:45 +05:00

42 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'
puts '== Removing old logs and tempfiles =='
system! 'bundle exec rake log:clear tmp:clear'
puts '== Restarting application server =='
system! 'bundle exec rake restart'
end