From ae85c9073002cde6f7ed821afdc7e8f70366655b Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 29 Dec 2015 03:07:58 -0800 Subject: [PATCH 1/4] add staging environment --- config/deploy.rb | 2 +- config/deploy/nginx_conf.erb | 2 +- config/deploy/staging.rb | 17 +++--- config/environments/staging.rb | 98 ++++++++++++++++++++++++++++++++++ config/secrets.yml | 9 ++++ 5 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 config/environments/staging.rb diff --git a/config/deploy.rb b/config/deploy.rb index 35e19f5..8009818 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,7 +8,7 @@ set :assets_dir, %w(public/assets public/system) # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } -set :deploy_to, '/home/jesse/web/thirteen-tien-len' +set :deploy_to, "/home/jesse/web/thirteen-tien-len_#{fetch(:stage)}" # set :scm, :git # set :format, :pretty diff --git a/config/deploy/nginx_conf.erb b/config/deploy/nginx_conf.erb index 682f213..cb1d3d1 100644 --- a/config/deploy/nginx_conf.erb +++ b/config/deploy/nginx_conf.erb @@ -1,5 +1,5 @@ upstream <%= fetch(:nginx_upstream) %> { - server unix:///home/jesse/web/thirteen-tien-len/shared/tmp/sockets/puma.sock fail_timeout=0; + server unix:///home/jesse/web/thirteen-tien-len_<%= fetch(:stage) %>/shared/tmp/sockets/puma.sock fail_timeout=0; } server { diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index a3e50ce..fac0470 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,13 +1,15 @@ set :stage, :staging +set :nginx_server_name, 'staging.tienlen.ga' # optional, defaults to :application + # Simple Role Syntax # ================== # Supports bulk-adding hosts to roles, the primary # server in each group is considered to be the first # unless any hosts have the primary property set. -role :app, %w{deploy@example.com} -role :web, %w{deploy@example.com} -role :db, %w{deploy@example.com} +role :app, %w{jesse@staging.tienlen.ga} +role :web, %w{jesse@staging.tienlen.ga} +role :db, %w{jesse@staging.tienlen.ga} # Extended Server Syntax # ====================== @@ -15,17 +17,18 @@ role :db, %w{deploy@example.com} # definition into the server list. The second argument # something that quacks like a hash can be used to set # extended properties on the server. -server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value +server 'staging.tienlen.ga', user: 'jesse', roles: %w{web app db}, my_property: :my_value # you can set custom ssh options # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) # set it globally -# set :ssh_options, { + set :ssh_options, { # keys: %w(/home/rlisowski/.ssh/id_rsa), # forward_agent: false, # auth_methods: %w(password) -# } + port: 27997 + } # and/or per server # server 'example.com', # user: 'user_name', @@ -38,5 +41,5 @@ server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value # # password: 'please use keys' # } # setting per server overrides global ssh_options - # fetch(:default_env).merge!(rails_env: :staging) + diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 0000000..4ae8153 --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,98 @@ +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 + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy + # like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # 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 = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved + # to config/initializers/assets.rb + + # 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 + + # Force all access to the app over SSL, use Strict-Transport-Security, + # and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # 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 + + config.action_mailer.smtp_settings = { + address: 'smtp.gmail.com', + port: 587, + domain: Rails.application.secrets.domain_name, + authentication: 'plain', + enable_starttls_auto: true, + user_name: Rails.application.secrets.email_provider_username, + password: Rails.application.secrets.email_provider_password + } + # ActionMailer Config + config.action_mailer.default_url_options = { host: Rails.application.secrets.domain_name } + config.action_mailer.delivery_method = :smtp + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = false + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/secrets.yml b/config/secrets.yml index dff3e59..e49e585 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -23,6 +23,15 @@ test: domain_name: example.com secret_key_base: b293e2494b3116d86fa96a2a68a5a758c0c0c0d78799e7e948f8beea5c6907c7f4fbe299fa4645bdda6b9a61ba8a73af85a97df09167e2976c1eea55116fb4b6 +staging: + admin_name: <%= ENV["ADMIN_NAME"] %> + admin_email: <%= ENV["ADMIN_EMAIL"] %> + admin_password: <%= ENV["ADMIN_PASSWORD"] %> + email_provider_username: <%= ENV["GMAIL_USERNAME"] %> + email_provider_password: <%= ENV["GMAIL_PASSWORD"] %> + domain_name: <%= ENV["DOMAIN_NAME"] %> + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + # Do not keep production secrets in the repository, # instead read values from the environment. production: From 4ac48fa07df69cc60f0bfd3ae250063f8cbfd29a Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 29 Dec 2015 04:40:36 -0800 Subject: [PATCH 2/4] Add capistrano-postgresql gem. Update production deploy --- Capfile | 1 + Gemfile | 1 + Gemfile.lock | 3 +++ config/deploy.rb | 5 ++++- config/deploy/production.rb | 12 ++++++------ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Capfile b/Capfile index c6092be..19dd759 100644 --- a/Capfile +++ b/Capfile @@ -12,6 +12,7 @@ require 'capistrano/bundler' require 'capistrano/nginx' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' +require 'capistrano/postgresql' #require 'capistrano/bower' diff --git a/Gemfile b/Gemfile index 2958540..e2c5c1a 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ group :development do gem 'capistrano-rbenv' gem 'capistrano-nginx', github: 'koenpunt/capistrano-nginx' gem "capistrano-db-tasks", require: false + gem "capistrano-postgresql", '~> 4.2.0' gem 'guard-bundler' gem 'guard-rails' gem 'guard-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index 736d925..ce2d48e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,8 @@ GEM sshkit (~> 1.2) capistrano-db-tasks (0.4) capistrano (>= 3.0.0) + capistrano-postgresql (4.2.1) + capistrano (>= 3.0) capistrano-rails (1.1.5) capistrano (~> 3.1) capistrano-bundler (~> 1.1) @@ -380,6 +382,7 @@ DEPENDENCIES capistrano-bundler capistrano-db-tasks capistrano-nginx! + capistrano-postgresql (~> 4.2.0) capistrano-rails capistrano-rails-console capistrano-rbenv diff --git a/config/deploy.rb b/config/deploy.rb index 8009818..c9d7a0b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,4 +1,4 @@ -set :application, 'thirteen-tien-len' +set :application, "thirteen_tien_len_#{fetch(:stage)}" set :repo_url, 'git@bitbucket.org:jessecfisher/thirteen-tien-len.git' # If you want to import assets, you can change default asset dir (default = system) @@ -34,6 +34,9 @@ set :nginx_template, 'config/deploy/nginx_conf.erb' # configuration template set :nginx_listen, 80 # optional, default is not set set :nginx_roles, :all +## postgresql +#set :pg_user, "thirteen_tien_len_#{fetch(:stage)}" + namespace :db do desc 'Setup the database' task :setup do diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 7d6a7f8..3ca7d47 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,15 +1,15 @@ set :stage, :production -set :nginx_server_name, 'thirteen.cowabon.ga' # optional, defaults to :application +set :nginx_server_name, 'tienlen.ga' # optional, defaults to :application # Simple Role Syntax # ================== # Supports bulk-adding hosts to roles, the primary # server in each group is considered to be the first # unless any hosts have the primary property set. -role :app, %w{jesse@ssh.cowabon.ga} -role :web, %w{jesse@ssh.cowabon.ga} -role :db, %w{jesse@ssh.cowabon.ga} +role :app, %w{jesse@tienlen.ga} +role :web, %w{jesse@tienlen.ga} +role :db, %w{jesse@tienlen.ga} # Extended Server Syntax # ====================== @@ -17,7 +17,7 @@ role :db, %w{jesse@ssh.cowabon.ga} # definition into the server list. The second argument # something that quacks like a hash can be used to set # extended properties on the server. -server 'ssh.cowabon.ga', user: 'jesse', roles: %w{web app db}, my_property: :my_value +server 'tienlen.ga', user: 'jesse', roles: %w{web app db}, my_property: :my_value # you can set custom ssh options # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options @@ -27,7 +27,7 @@ server 'ssh.cowabon.ga', user: 'jesse', roles: %w{web app db}, my_property: :my_ # keys: %w(/home/rlisowski/.ssh/id_rsa), # forward_agent: false, # auth_methods: %w(password) - port: 27997 +# port: 27997 } # and/or per server # server 'example.com', From 87dc772f58b5afe91a358351f4c2eb161652a39f Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 29 Dec 2015 04:41:24 -0800 Subject: [PATCH 3/4] Update ruby to 2.3.0 --- .ruby-version | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 5859406..276cbf9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.2.3 +2.3.0 diff --git a/Gemfile b/Gemfile index e2c5c1a..db0651f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.2.3' +ruby '2.3.0' gem 'rails', '4.1.8' gem 'sass-rails', '~> 4.0.3' gem 'uglifier', '>= 1.3.0' From d05271436556526257de5978393e175e0e4c33e5 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 29 Dec 2015 21:02:48 -0800 Subject: [PATCH 4/4] Configure specs for staging environment --- Gemfile | 4 ++-- config/deploy.rb | 2 +- spec/features/plays_spec.rb | 3 ++- spec/support/capybara.rb | 16 ++++++++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index db0651f..abaceae 100644 --- a/Gemfile +++ b/Gemfile @@ -48,14 +48,14 @@ group :development do gem 'spring-commands-rspec' gem 'guard-ctags-bundler' end -group :development, :test do +group :development, :test, :staging do gem 'factory_girl_rails' gem 'faker' gem 'pry-rails' gem 'pry-rescue' gem 'rspec-rails' end -group :test do +group :test, :staging do gem 'capybara' gem 'database_cleaner' gem "poltergeist" diff --git a/config/deploy.rb b/config/deploy.rb index c9d7a0b..e41442b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -19,7 +19,7 @@ set :linked_files, %w{config/database.yml .env} set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/lift-calculator} set :rbenv_type, :user # or :system, depends on your rbenv setup -set :rbenv_ruby, '2.2.3' +set :rbenv_ruby, '2.3.0' set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" set :rbenv_map_bins, %w{rake gem bundle ruby rails} set :rbenv_roles, :all # default value diff --git a/spec/features/plays_spec.rb b/spec/features/plays_spec.rb index 01e3f19..9fcecd2 100644 --- a/spec/features/plays_spec.rb +++ b/spec/features/plays_spec.rb @@ -7,7 +7,8 @@ feature 'Play a hand', type: :feature, js: true do @game = setup_game @game.reload @player = @game.controlling_player - login_as(@player.user, scope: :user) + signin(@player.user.email,'please123') + #login_as(@player.user, scope: :user) visit game_path @game end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 75cab66..1fca18e 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,3 +1,15 @@ require 'capybara/poltergeist' -Capybara.asset_host = 'http://localhost:3000' -Capybara.javascript_driver = :poltergeist #:selenium + +asset_hosts = { + staging: 'http://staging.tienlen.ga', + development: 'http://localhost:3000', + test: 'http://localhost:3000' +} + +if ENV['RAILS_ENV'] == 'staging' + #Capybara.run_server = false + Capybara.app_host = asset_hosts[ENV['RAILS_ENV'].to_sym] +end +Capybara.asset_host = asset_hosts[ENV['RAILS_ENV'].to_sym] +#Capybara.asset_host = 'http://localhost:3000' +Capybara.javascript_driver = :selenium # :poltergeist