houdini/bin/setup

49 lines
1.5 KiB
Text
Raw Normal View History

2019-01-29 20:13:52 +00:00
#!/usr/bin/env ruby
2019-02-01 17:54:16 +00:00
require 'fileutils'
require 'securerandom'
2019-01-29 20:13:52 +00:00
# path to your application root.
2020-05-20 20:36:31 +00:00
APP_ROOT = File.expand_path('..', __dir__)
2019-01-29 20:13:52 +00:00
2019-02-01 17:54:16 +00:00
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
2020-05-20 20:36:31 +00:00
FileUtils.chdir APP_ROOT do
2021-01-05 21:56:13 +00:00
# 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 any time and get an expectable outcome.
2019-02-01 17:54:16 +00:00
# Add necessary setup steps to this file.
# we don't install dependencies on ci because it's been done already
if ARGV.length == 0 || (ARGV.length > 0 && ARGV[0] != 'ci')
puts '== Installing dependencies (Ruby) =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
2019-01-29 20:13:52 +00:00
puts "\n== Installing dependencies (JS) =="
system!('yarn -s')
2020-06-04 16:19:29 +00:00
end
2020-06-04 16:19:29 +00:00
if ARGV.length == 0 || (ARGV.length > 0 && ARGV[0] != 'ci')
puts "\n== Copying env file =="
unless File.exist?('.env')
FileUtils.cp '.env.template', '.env'
end
puts "\n== Create new secrets =="
File.write('.env', File.read('.env').gsub(/-- secret string --/) { SecureRandom.hex(64) })
else
puts "\n== Copying env file =="
FileUtils.cp '.env.test', '.env'
end
2019-01-29 20:13:52 +00:00
puts "\n== Preparing database =="
2020-06-22 21:48:59 +00:00
system! 'bin/rails db:prepare db:seed'
2019-01-29 20:13:52 +00:00
puts "\n== Removing old logs and tempfiles =="
2019-02-01 17:54:16 +00:00
system! 'bin/rails log:clear tmp:clear'
2019-01-29 20:13:52 +00:00
puts "\n== Restarting application server =="
2019-02-01 17:54:16 +00:00
system! 'bin/rails restart'
2019-01-29 20:13:52 +00:00
end