Skip to content

Commit

Permalink
updated bin/setup so that its simpler to install the system
Browse files Browse the repository at this point in the history
  • Loading branch information
briri committed Oct 27, 2022
1 parent 68e914c commit cd6fed4
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 561 deletions.
48 changes: 48 additions & 0 deletions .env.mysql2
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# DMPRoadmap dotenv file

# Rails log level
RAILS_LOG_LEVEL=debug
# Whether or not Rails should log to STDOUT. If false it will log to `./logs/[env].log`
RAILS_LOG_TO_STDOUT=true
# Whether or not Rails will be serving your static assets
RAILS_SERVE_STATIC_FILES=false
# Maximum number of Puma threads
RAILS_MAX_THREADS=5
# Maximum number of Puma workers
WEB_CONCURRENCY=2
# The port puma will use to host the Rails app
PORT=3000

# Rails 6.1+ has a white-list of valid domains. You must set this for your production env!
DMPROADMAP_HOST=localhost

# The location of the wkhtmltopdf app. Once bundler has installed it, you can find it with
# `which wkhtmltopdf` on linux/osx systems.
WICKED_PDF_PATH=/usr/local/bin/wkhtmltopdf

# Database settings.
DB_ADAPTER=mysql2
DB_HOST=localhost
DB_PORT=3306
DB_POOL_SIZE=16
DB_NAME=roadmap

# Whether or not the Dragonfly gem should use AWS S3 to store logos. If 'false' the logos will
# be stored on the local disk. If true, you must provide the `AWS_` prefixed values.
DRAGONFLY_AWS=false
AWS_REGION=
AWS_BUCKET_NAME=

# If you have a Rollbar account and want to redcord errors there, add your token here
ROLLBAR_ACCESS_TOKEN=
ROLLBAR_ENV=

# Translation IO variables. The Domain can be either `app` or `client` and is typically defined
# when running `bin/rails translations:sync DOMAIN=app`. `client` will use any of your
# customized content in ./app/views/branded and `app` is for the core roadmap translations.
# Include your Translation.io API key for the appropriate domains:
# app => TRANSLATION_API_ROADMAP
# client => TRANSLATION_API_CLIENT
# DOMAIN=app
# TRANSLATION_API_ROADMAP=
# TRANSLATION_API_CLIENT=
48 changes: 48 additions & 0 deletions .env.postgresql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# DMPRoadmap dotenv file

# Rails log level
RAILS_LOG_LEVEL=debug
# Whether or not Rails should log to STDOUT. If false it will log to `./logs/[env].log`
RAILS_LOG_TO_STDOUT=true
# Whether or not Rails will be serving your static assets
RAILS_SERVE_STATIC_FILES=false
# Maximum number of Puma threads
RAILS_MAX_THREADS=5
# Maximum number of Puma workers
WEB_CONCURRENCY=2
# The port puma will use to host the Rails app
PORT=3000

# Rails 6.1+ has a white-list of valid domains. You must set this for your production env!
DMPROADMAP_HOST=localhost

# The location of the wkhtmltopdf app. Once bundler has installed it, you can find it with
# `which wkhtmltopdf` on linux/osx systems.
WICKED_PDF_PATH=/usr/local/bin/wkhtmltopdf

# Database settings.
DB_ADAPTER=postgresql
DB_HOST=localhost
DB_PORT=5432
DB_POOL_SIZE=16
DB_NAME=roadmap

# Whether or not the Dragonfly gem should use AWS S3 to store logos. If 'false' the logos will
# be stored on the local disk. If true, you must provide the `AWS_` prefixed values.
DRAGONFLY_AWS=false
AWS_REGION=
AWS_BUCKET_NAME=

# If you have a Rollbar account and want to redcord errors there, add your token here
ROLLBAR_ACCESS_TOKEN=
ROLLBAR_ENV=

# Translation IO variables. The Domain can be either `app` or `client` and is typically defined
# when running `bin/rails translations:sync DOMAIN=app`. `client` will use any of your
# customized content in ./app/views/branded and `app` is for the core roadmap translations.
# Include your Translation.io API key for the appropriate domains:
# app => TRANSLATION_API_ROADMAP
# client => TRANSLATION_API_CLIENT
DOMAIN=app
TRANSLATION_API_ROADMAP=
TRANSLATION_API_CLIENT=
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ GEM
mysql2 (0.5.4)
nenv (0.3.0)
nio4r (2.5.8)
nokogiri (1.13.9-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.9-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
Expand Down Expand Up @@ -498,6 +500,7 @@ GEM
zeitwerk (2.6.1)

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -580,4 +583,4 @@ RUBY VERSION
ruby 2.7.6p219

BUNDLED WITH
2.3.15
2.3.24
79 changes: 54 additions & 25 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,61 @@ def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

puts "\n== Copying sample files =="
%w[
config/database.yml.sample
config/initializers/wicked_pdf.rb.example
].each do |file|
new_file = file.gsub('.sample', '').gsub('.example', '')
cp file, new_file unless File.exist?(new_file)
end
valid_db = ARGV.length > 0 && %w[mysql postgres].include?(ARGV[0].to_s.downcase.strip)

puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
if valid_db
db_adapter = ARGV[0].to_s.downcase.strip == 'mysql' ? 'mysql2' : 'postgresql'

puts "\n== Fetching mime types and adding to database =="
system! 'bin/rails mime_types:load'
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
system! 'yarn install'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
puts "\n== Copying sample files =="
cp 'config/database.yml.sample', 'config/database.yml'
cp 'config/initializers/wicked_pdf.rb.example', 'config/initializers/wicked_pdf.rb'
cp ".env.#{db_adapter}", '.env'

puts "\n== Opening .env in editor ... please update as needed =="
puts " In particular make sure your DB settings are correct."
sleep(3)
system! 'vi .env'

puts "\n== Preparing credentials file =="
system! "EDITOR='echo \"$(cat config/credentials.yml.#{db_adapter})\" >' bin/rails credentials:edit"

puts "\n== Opening credentials editor ... please update as needed =="
puts " In particular make sure your DB settings are correct."
sleep(3)
system! 'EDITOR=vi bin/rails credentials:edit'

puts "\n== Preparing database =="
system! 'bin/rails db:prepare'

puts "\n== Populating License table =="
system! 'bin/rails external_api:load_spdx_licenses'

puts "\n== Populating Metadata Standards table =="
system! 'bin/rails external_api:load_rdamsc_standards'

puts "\n== Populating Research Domains table =="
system! 'bin/rails external_api:add_field_of_science_to_research_domains'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'

puts "\n== !!We highly recommend that you populate the Repositories table, but this can take"
puts "in excess of 10 minutes so we do not run it as part of this setup!!"
puts " To run it on your own: `bin/rails external_api:load_re3data_repos`"
end
else
puts "\n== You MUST specify the type of DB you would like to use. Either mysql or postgres =="
puts "== For example: `ruby bin/setup postgres` =="
end
23 changes: 0 additions & 23 deletions config/credentials.yml.example

This file was deleted.

26 changes: 26 additions & 0 deletions config/credentials.yml.mysql2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DMPRoadmap Rails credentials file
# To generate secrets and peppers, run the following in another tab/window `bin/rails secret`

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: my_secret_key

# Database credentials
db_username: root
db_password:

# Devise credentials (used for user password encryption)
secret_key: my_secret_key
devise_pepper: my_pepper

# Used by the Dragonfly gem for creating random hashes for org logos
dragonfly_secret: my_secret_key

# AWS credentials used by the config/initializers/dragonfly.rb to access your S3 bucket (if applicable)
# aws:
# access_key_id: 12345
# secret_access_key: 34567

# Recaptcha credentials
recaptcha:
site_key: 11111
secret_key: 22222
26 changes: 26 additions & 0 deletions config/credentials.yml.postgresql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DMPRoadmap Rails credentials file
# To generate secrets and peppers, run the following in another tab/window `bin/rails secret`

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: my_secret_key

# Database credentials
db_username: postgres
db_password:

# Devise credentials (used for user password encryption)
secret_key: my_secret_key
devise_pepper: my_pepper

# Used by the Dragonfly gem for creating random hashes for org logos
dragonfly_secret: my_secret_key

# AWS credentials used by the config/initializers/dragonfly.rb to access your S3 bucket (if applicable)
# aws:
# access_key_id: 12345
# secret_access_key: 34567

# Recaptcha credentials
recaptcha:
site_key: 11111
secret_key: 22222
13 changes: 8 additions & 5 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
defaults: &defaults
adapter: <%= ENV['DB_ADAPTER'] || 'postgresql' %>
encoding: <%= ENV['DB_ADAPTER'] == "mysql2" ? "utf8mb4" : "" %>
username: <%= ENV["DB_ADAPTER"] == "postgresql" ? 'postgres' : 'root' %>
database: roadmap_<%= ENV['RAILS_ENV'] %>
pool: 16
adapter: <%= ENV.fetch('DB_ADAPTER', 'postgresql') %>
encoding: <%= ENV.fetch('DB_ADAPTER', 'postgresql') == 'mysql2' ? 'utf8mb4' : '' %>
pool: <%= ENV.fetch('DB_POOL_SIZE', 16) %>
host: <%= ENV.fetch('DB_HOST', 'localhost') %>
port: <%= ENV.fetch('DB_PORT', '5432') %>
database: <%= ENV.fetch('DB_NAME', 'roadmap') %>
username: <%= ENV.fetch('DB_USERNAME', Rails.application.credentials.db_username) %>
password: <%= ENV.fetch('DB_PASSWORD', Rails.application.credentials.db_password) %>

development:
<<: *defaults
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/dragonfly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
require 'dragonfly/s3_data_store'
datastore(:s3, {
bucket_name: ENV.fetch('AWS_BUCKET_NAME', nil),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID', nil),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID', Rails.application.credentials.aws.access_key_id),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', Rails.application.credentials.aws.secret_access_key),
region: ENV.fetch('AWS_REGION', nil),
root_path: Rails.env,
url_scheme: 'https'
Expand Down
Loading

0 comments on commit cd6fed4

Please sign in to comment.