ToolJet/deploy/ec2/setup_app
Deepti Kakade b10d777f63
Fixes Rubocop issues in tests (#359)
* Updated project set up guide for Mac, added node version and Webpack install steps.

* Worked on PR comment i.e Can we change this line to Install Node.js ( version: v14.9.0 )

* Fixed "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping."

* Resolved rubocop comments i.e "Style/FrozenStringLiteralComment: Missing frozen string literal comment." in test folder

Co-authored-by: Deepti Kakade <deepti@saeloun.com>
Co-authored-by: Deepti Kakade <“deepti@saeloun.com”>
2021-07-01 12:54:35 +05:30

58 lines
1.6 KiB
Text
Executable file

# frozen_string_literal: true
#!/usr/bin/env ruby
def ensure_db_connectivity(user = ENV.fetch("PG_USER"), pass = ENV.fetch("PG_PASS"), host = ENV.fetch("PG_HOST"))
cmd = %{psql -d 'postgresql://#{user}:#{pass}@#{host}' -c 'select now()' > /dev/null 2>&1}
res = system(cmd)
if res
puts "Successfully pinged the database!"
else
puts "Can't connect to the database using the credenials provided in the .env file!"
exit(1)
end
end
def install_script_deps
system("gem install bundler")
system("gem install dotenv")
end
def load_env
require "dotenv"
Dir.chdir "/home/ubuntu/app"
Dotenv.load!
Dotenv.require_keys("TOOLJET_HOST", "LOCKBOX_MASTER_KEY", "SECRET_KEY_BASE", "PG_DB", "PG_USER", "PG_HOST", "PG_PASS")
end
def install_be_app_deps
system("RAILS_ENV=production bundle install")
system("RAILS_ENV=production bundle exec dotenv rails db:create")
system("RAILS_ENV=production bundle exec dotenv rails db:migrate")
system("RAILS_ENV=production bundle exec dotenv rails db:seed")
end
def build_fe
backend_url = "#{ENV.fetch("TOOLJET_HOST")}/_backend_"
front_end_working_dir = "/home/ubuntu/app/frontend"
Dir.chdir front_end_working_dir
system("npm install --only=production")
system("NODE_ENV=production TOOLJET_SERVER_URL=#{backend_url} npm run-script build")
end
def start_services
system("sudo systemctl start openresty")
system("bundle binstubs puma && rbenv rehash && sudo systemctl start puma")
end
install_script_deps
load_env
ensure_db_connectivity
install_be_app_deps
build_fe
start_services
puts "The app will be served at #{ENV.fetch("TOOLJET_HOST")}"