From e8e46135bed8fb6a1b99e0cb8e920ce92e512108 Mon Sep 17 00:00:00 2001 From: Ignacio Galindo Date: Wed, 17 Aug 2016 09:15:21 +0200 Subject: [PATCH 1/4] Test review apps --- Gemfile | 18 ++++--- app.json | 55 ++++++++++++++++++++ config/environments/review.rb | 90 +++++++++++++++++++++++++++++++++ config/initializers/omniauth.rb | 10 +++- 4 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 app.json create mode 100644 config/environments/review.rb diff --git a/Gemfile b/Gemfile index 6ff1d5b..1539b63 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,14 @@ gem 'lograge', '~> 0.4.1' gem 'omniauth-github', '~> 1.1.2' gem 'rake', '~> 10.5.0 ' +group :development do + gem 'dotenv-rails', '~> 2.0.0' + gem 'powder', '~> 0.3.0' + gem 'rails_best_practices', '~> 1.16.0' + gem 'spring', '~> 1.7.2' + gem 'spring-commands-rspec', '~> 1.0.4' +end + group :development, :test do gem 'capybara', '~> 2.4.4' gem 'capybara-webkit', '~> 1.4.1' @@ -37,17 +45,13 @@ group :development, :test do gem 'rspec-rails', '~> 3.5.1', require: false end -group :development do - gem 'dotenv-rails', '~> 2.0.0' - gem 'powder', '~> 0.3.0' - gem 'rails_best_practices', '~> 1.16.0' - gem 'spring', '~> 1.7.2' - gem 'spring-commands-rspec', '~> 1.0.4' -end group :production do gem 'airbrake', '~> 5.4.3' gem 'newrelic_rpm', '~> 3.16.0.318' +end + +group :production, :review do gem 'rails_12factor', '~> 0.0.3' end diff --git a/app.json b/app.json new file mode 100644 index 0000000..42a0665 --- /dev/null +++ b/app.json @@ -0,0 +1,55 @@ +{ + "name": "wdt-stage", + "description": "", + "scripts": { + "postdeploy": "rake db:setup" + }, + "env": { + "DATABASE_URL": { + "required": true + }, + "GITHUB_APP_NAME": { + "required": true + }, + "GITHUB_CLIENT_ID": { + "required": true + }, + "GITHUB_CLIENT_SECRET": { + "required": true + }, + "GOOGLE_MAPS_API_KEY": { + "required": true + }, + "LANG": { + "required": true + }, + "MAINTENANCE_PAGE_URL": { + "required": true + }, + "RACK_ENV": { + "required": true + }, + "RAILS_ENV": { + "required": "review" + }, + "RAILS_SERVE_STATIC_FILES": { + "required": true + }, + "SECRET_KEY_BASE": { + "generator": "secret" + } + }, + "formation": { + "web": { + "quantity": 1 + } + }, + "addons": [ + "heroku-postgresql" + ], + "buildpacks": [ + { + "url": "heroku/ruby" + } + ] +} diff --git a/config/environments/review.rb b/config/environments/review.rb new file mode 100644 index 0000000..c15015a --- /dev/null +++ b/config/environments/review.rb @@ -0,0 +1,90 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "wdt_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 4d42557..2a3b163 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -4,8 +4,16 @@ config.path_prefix = '/admin/auth' end + options = { + scope: 'user:email,read:org' + } + + if Rails.env.review? + options[:redirect_uri] = "#{Rails.application.routes.url_helpers.root_url}/admin/auth/github/callback" + end + provider :github, Rails.application.secrets.github_client_id, Rails.application.secrets.github_client_secret, - scope: 'user:email,read:org' + options end From a5306639b11a35d6171483bb4b6c978cdaab7346 Mon Sep 17 00:00:00 2001 From: Ignacio Galindo Date: Wed, 17 Aug 2016 09:21:09 +0200 Subject: [PATCH 2/4] Ignore config analysis from codeclimate --- .codeclimate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index 4112980..b8f2cec 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -30,6 +30,7 @@ exclude_paths: - app/assets/javascripts/app.js - bin/** - db/** + - config/** - public/assets/** - spec/** - UI/** From b8965dec3fcaa646fbab3df14e8d21c4eb18f598 Mon Sep 17 00:00:00 2001 From: Ignacio Galindo Date: Wed, 17 Aug 2016 09:31:19 +0200 Subject: [PATCH 3/4] Fix review apps rails environment --- app.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app.json b/app.json index 42a0665..1911078 100644 --- a/app.json +++ b/app.json @@ -29,9 +29,7 @@ "RACK_ENV": { "required": true }, - "RAILS_ENV": { - "required": "review" - }, + "RAILS_ENV": "review", "RAILS_SERVE_STATIC_FILES": { "required": true }, From a3a29006cb964f15aedca6392dcd4dbc503b810e Mon Sep 17 00:00:00 2001 From: Ignacio Galindo Date: Wed, 17 Aug 2016 10:08:46 +0200 Subject: [PATCH 4/4] Fixes --- Gemfile | 1 - Rakefile | 2 +- app.json | 20 +++++---------- config/initializers/omniauth.rb | 4 +-- config/secrets.yml | 3 +++ db/seeds.rb | 45 ++++++++++++++++++++------------- 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index 1539b63..bf2c3f7 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,6 @@ group :development, :test do gem 'rspec-rails', '~> 3.5.1', require: false end - group :production do gem 'airbrake', '~> 5.4.3' gem 'newrelic_rpm', '~> 3.16.0.318' diff --git a/Rakefile b/Rakefile index 3f4fbcc..a5989df 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,6 @@ require File.expand_path('../config/application', __FILE__) -require 'rspec-rails' unless Rails.env.production? +require 'rspec-rails' unless Rails.env.in?(%w{production review}) Rails.application.load_tasks diff --git a/app.json b/app.json index 1911078..42a6a90 100644 --- a/app.json +++ b/app.json @@ -1,13 +1,10 @@ { "name": "wdt-stage", - "description": "", + "image": "heroku/ruby", "scripts": { - "postdeploy": "rake db:setup" + "postdeploy": "rake db:migrate db:seed" }, "env": { - "DATABASE_URL": { - "required": true - }, "GITHUB_APP_NAME": { "required": true }, @@ -20,6 +17,9 @@ "GOOGLE_MAPS_API_KEY": { "required": true }, + "HEROKU_APP_NAME": { + "required": true + }, "LANG": { "required": true }, @@ -30,9 +30,6 @@ "required": true }, "RAILS_ENV": "review", - "RAILS_SERVE_STATIC_FILES": { - "required": true - }, "SECRET_KEY_BASE": { "generator": "secret" } @@ -43,11 +40,6 @@ } }, "addons": [ - "heroku-postgresql" - ], - "buildpacks": [ - { - "url": "heroku/ruby" - } + "heroku-postgresql:hobby-dev" ] } diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 2a3b163..5513486 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,4 +1,4 @@ -WDT::Application.config.middleware.use OmniAuth::Builder do +Rails.application.config.middleware.use OmniAuth::Builder do configure do |config| config.path_prefix = '/admin/auth' @@ -9,7 +9,7 @@ } if Rails.env.review? - options[:redirect_uri] = "#{Rails.application.routes.url_helpers.root_url}/admin/auth/github/callback" + options[:redirect_uri] = "https://#{ENV.fetch('HEROKU_APP_NAME')}.herokuapp.com/admin/auth/github/callback" end provider :github, diff --git a/config/secrets.yml b/config/secrets.yml index e312fff..47d9b3d 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,5 +12,8 @@ production: <<: *development secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> +review: + <<: *development + test: <<: *development diff --git a/db/seeds.rb b/db/seeds.rb index 3d878c9..c89b384 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,36 +2,47 @@ Faker::Config.locale = 'es' puts 'Creating location' - location = Location.create! city: 'Colima', state: 'Colima', country: 'México' + location = Location.create!( + city: 'Colima', + state: 'Colima', + country: 'México' + ) puts 'Creating venue' - venue = Venue.create! location: location, - name: Faker::Company.name, - address: "#{Faker::Address.street_suffix} #{Faker::Address.street_address}, #{location.name}, #{Faker::Address.postcode}", - description: Faker::Lorem.paragraphs.join + venue = Venue.create!( + location: location, + name: Faker::Company.name, + address: "#{Faker::Address.street_suffix} #{Faker::Address.street_address}, #{location.name}, #{Faker::Address.postcode}", + description: Faker::Lorem.paragraphs.join + ) puts 'Creating event' - event = Event.create! venue: venue, - date: 15.days.from_now, - theme: "#{Faker::Hacker.adjective.titleize} #{Faker::Hacker.noun}" + event = Event.create!( + venue: venue, + date: 15.days.from_now, + theme: "#{Faker::Hacker.adjective.titleize} #{Faker::Hacker.noun}" + ) puts 'Creating speakers' speakers = [] 4.times do - u = User.create! name: Faker::Name.name, - email: Faker::Internet.email, - profile_photo_url: Faker::Avatar.image(nil, '200x200', 'jpg').gsub('http', 'https'), - twitter: Faker::Internet.user_name - speakers << u + speakers << User.create!( + name: Faker::Name.name, + email: Faker::Internet.email, + photo_url: Faker::Avatar.image(nil, '200x200', 'jpg').gsub('http', 'https'), + twitter: Faker::Internet.user_name + ) end puts 'Creating event talk proposals' speakers.each do |speaker| - speaker.talks.create! event: event, - title: "#{Faker::Hacker.ingverb.titleize} #{Faker::Hacker.adjective} #{Faker::Hacker.noun}", - description: Faker::Lorem.paragraphs.join, - status: :proposal + speaker.talks.create!( + event: event, + title: "#{Faker::Hacker.ingverb.titleize} #{Faker::Hacker.adjective} #{Faker::Hacker.noun}", + description: Faker::Lorem.paragraphs.join, + status: :proposal + ) end puts 'Accepting event talks'