From 96e5f2816e261acdbe3a242ea27db57c39398548 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 6 May 2015 11:57:00 +0200 Subject: [PATCH 1/8] Add some deploy magic untested --- Capfile | 1 + Gemfile | 13 +++++++------ config/deploy.rb | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Capfile b/Capfile index 07e8f85e..f5832739 100644 --- a/Capfile +++ b/Capfile @@ -20,6 +20,7 @@ require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' +require "airbrussh/capistrano" # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index 146c5686..33fb1d78 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,10 @@ source 'https://rails-assets.org' source 'https://rubygems.org' gem 'rails', '4.2.0' -gem 'rack-cors', :require => 'rack/cors' +gem 'rack-cors', require: 'rack/cors' # Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' +# gem 'rails', git: 'git://github.com/rails/rails.git' # gem 'sqlite3' @@ -31,9 +31,10 @@ group :assets do gem 'js-routes' gem "font-awesome-rails" gem 'capistrano-local-precompile', require: false + gem "airbrussh", require: false # See https://github.com/sstephenson/execjs#readme for more supported runtimes - #gem 'therubyracer', :platforms => :ruby + #gem 'therubyracer', platforms: :ruby gem 'uglifier', '>= 1.0.3' #gem "emblem-source", github: "machty/emblem.js" @@ -43,7 +44,7 @@ group :assets do gem 'foundation-rails' #, github: 'bterkuile/foundation-rails' gem 'ace-rails-ap' - #gem 'mustache' #, :require => 'mustache/railtie' + #gem 'mustache' #, require: 'mustache/railtie' end #gem 'less-rails' @@ -79,7 +80,7 @@ gem 'sucker_punch' #gem 'geokit' gem 'iso_country_codes' -#gem "less-rails-bootstrap-devise", :git => 'git://github.com/bigbento/less-rails-bootstrap-devise.git' +#gem "less-rails-bootstrap-devise", git: 'git://github.com/bigbento/less-rails-bootstrap-devise.git' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' @@ -125,7 +126,7 @@ group :test do gem 'launchy' gem 'fuubar' gem 'webmock' - #gem 'rb-fsevent', :require => false #if RUBY_PLATFORM =~ /darwin/i + #gem 'rb-fsevent', require: false #if RUBY_PLATFORM =~ /darwin/i gem 'simplecov', require: false end diff --git a/config/deploy.rb b/config/deploy.rb index 5a375d41..131629be 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,6 +1,6 @@ # config valid only for Capistrano 3.1 # lock '3.2.1' -#require 'capistrano/local_precompile' +require 'capistrano/local_precompile' set :application, 'mozo.bar' #set :repo_url, 'root@uflows.com:/var/git/qwaiter.git' From 2b9edb6bdd7acd94e932ca3c35c30ca6f434ee85 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 14:52:38 +0200 Subject: [PATCH 2/8] Puma magick --- Capfile | 1 + Gemfile | 3 ++- Gemfile.lock | 16 ++++++++++------ config/deploy.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Capfile b/Capfile index f5832739..6b226745 100644 --- a/Capfile +++ b/Capfile @@ -20,6 +20,7 @@ require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' +require 'capistrano/puma' require "airbrussh/capistrano" # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. diff --git a/Gemfile b/Gemfile index 33fb1d78..4c92a021 100644 --- a/Gemfile +++ b/Gemfile @@ -109,11 +109,11 @@ group :development do gem 'capistrano', '~> 3.0', require: false gem 'capistrano-rvm', '~> 0.1', require: false gem 'capistrano-rails', '~> 1.1', require: false + gem 'capistrano3-puma', require: false gem 'spring' gem 'spring-commands-rspec' gem 'web-console', '~> 2.0.0' gem 'foreman' - gem 'thin' end group :test do @@ -132,6 +132,7 @@ end # Use unicorn as the app server # gem 'unicorn' +gem 'puma' # Deploy with Capistrano # gem 'capistrano' diff --git a/Gemfile.lock b/Gemfile.lock index d57d770f..c9433350 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,8 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.7) + airbrussh (0.4.1) + sshkit (>= 1.6.1, != 1.7.0) arel (6.0.0) barber (0.6.0) ember-source @@ -121,6 +123,9 @@ GEM capistrano-rvm (0.1.2) capistrano (~> 3.0) sshkit (~> 1.2) + capistrano3-puma (1.0.0) + capistrano (~> 3.0) + puma (>= 2.6) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -157,7 +162,6 @@ GEM rest-client (~> 1.6.1) crack (0.4.2) safe_yaml (~> 1.0.0) - daemons (1.1.9) debug_inspector (0.0.2) devise (3.4.1) bcrypt (~> 3.0) @@ -320,6 +324,8 @@ GEM slop (~> 3.4) pry-rails (0.3.3) pry (>= 0.9.10) + puma (2.11.3) + rack (>= 1.1, < 2.0) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) rack (1.6.0) @@ -435,10 +441,6 @@ GEM temple (0.7.5) test_squad (0.0.1) rails - thin (1.6.3) - daemons (~> 1.0, >= 1.0.9) - eventmachine (~> 1.0) - rack (~> 1.0) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) @@ -479,12 +481,14 @@ DEPENDENCIES active_attr active_decorator active_model_serializers (= 0.9.0) + airbrussh bourbon cancancan capistrano (~> 3.0) capistrano-local-precompile capistrano-rails (~> 1.1) capistrano-rvm (~> 0.1) + capistrano3-puma capybara-screenshot cmtool! coffee-rails @@ -518,6 +522,7 @@ DEPENDENCIES paperclip poltergeist pry-rails + puma quiet_assets rack-cors rails (= 4.2.0) @@ -535,7 +540,6 @@ DEPENDENCIES spring-commands-rspec sucker_punch test_squad - thin turnip uglifier (>= 1.0.3) web-console (~> 2.0.0) diff --git a/config/deploy.rb b/config/deploy.rb index 131629be..594d4f2e 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -38,6 +38,17 @@ set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/sys # set :default_env, { path: "/opt/ruby/bin:$PATH" } set :default_env, {'DEPLOY' => 'yes'} +set :puma_threads, [4, 16] +set :puma_workers, 2 +set :puma_bind, "unix://#{shared_path}/tmp/sockets/app.sock" +set :puma_state, "#{shared_path}/tmp/pids/puma.state" +set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" +set :puma_access_log, "#{release_path}/log/puma.error.log" +set :puma_error_log, "#{release_path}/log/puma.access.log" +set :puma_preload_app, true +set :puma_worker_timeout, nil +set :puma_init_active_record, false # Change to true if using ActiveRecord + # Default value for keep_releases is 5 # set :keep_releases, 5 From 98ee17ca9ecb64174cb102da829e51bf7d3adb02 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 15:23:06 +0200 Subject: [PATCH 3/8] Add capistrano bundler gem --- Gemfile | 1 + Gemfile.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 4c92a021..c6e7c00d 100644 --- a/Gemfile +++ b/Gemfile @@ -107,6 +107,7 @@ group :development do # gem 'thin' gem 'faye' gem 'capistrano', '~> 3.0', require: false + gem 'capistrano-bundler', require: false gem 'capistrano-rvm', '~> 0.1', require: false gem 'capistrano-rails', '~> 1.1', require: false gem 'capistrano3-puma', require: false diff --git a/Gemfile.lock b/Gemfile.lock index c9433350..6d041673 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -485,6 +485,7 @@ DEPENDENCIES bourbon cancancan capistrano (~> 3.0) + capistrano-bundler capistrano-local-precompile capistrano-rails (~> 1.1) capistrano-rvm (~> 0.1) From 710fee280b6ca244ceee61d5607bf2d807e77cd6 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 16:17:49 +0200 Subject: [PATCH 4/8] Deploy updates --- .ruby-version | 1 - Capfile | 2 +- Gemfile | 2 +- Gemfile.lock | 5 +---- config/deploy.rb | 42 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 39 insertions(+), 13 deletions(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index ccbccc3d..00000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.2.0 diff --git a/Capfile b/Capfile index 6b226745..da709e35 100644 --- a/Capfile +++ b/Capfile @@ -17,7 +17,7 @@ require 'capistrano/deploy' require 'capistrano/rvm' # require 'capistrano/rbenv' # require 'capistrano/chruby' -require 'capistrano/bundler' +require 'capistrano-bundler' require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' require 'capistrano/puma' diff --git a/Gemfile b/Gemfile index c6e7c00d..3989f70a 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,7 @@ group :assets do #gem 'compass-rails' gem 'js-routes' gem "font-awesome-rails" - gem 'capistrano-local-precompile', require: false + #gem 'capistrano-local-precompile', require: false gem "airbrussh", require: false # See https://github.com/sstephenson/execjs#readme for more supported runtimes diff --git a/Gemfile.lock b/Gemfile.lock index 6d041673..6479d2ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,8 +115,6 @@ GEM capistrano-bundler (1.1.4) capistrano (~> 3.1) sshkit (~> 1.2) - capistrano-local-precompile (0.0.2) - capistrano capistrano-rails (1.1.2) capistrano (~> 3.1) capistrano-bundler (~> 1.1) @@ -154,7 +152,7 @@ GEM execjs coffee-script-source (1.9.1) colored (1.2) - colorize (0.7.5) + colorize (0.7.7) cookiejar (0.3.2) couchrest (1.2.0) mime-types (~> 1.15) @@ -486,7 +484,6 @@ DEPENDENCIES cancancan capistrano (~> 3.0) capistrano-bundler - capistrano-local-precompile capistrano-rails (~> 1.1) capistrano-rvm (~> 0.1) capistrano3-puma diff --git a/config/deploy.rb b/config/deploy.rb index 594d4f2e..d7bb87f8 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,6 +1,6 @@ # config valid only for Capistrano 3.1 # lock '3.2.1' -require 'capistrano/local_precompile' +#require 'capistrano/local_precompile' set :application, 'mozo.bar' #set :repo_url, 'root@uflows.com:/var/git/qwaiter.git' @@ -60,12 +60,12 @@ namespace :deploy do # Your restart mechanism here, for example: within release_path do #execute :rake, 'cache:clear', as: 'www-data' - with rails_env: fetch(:rails_env) do - execute :rake, 'dedigest_assets', as: 'www-data' - end + #with rails_env: fetch(:rails_env) do + #execute :rake, 'dedigest_assets', as: 'www-data' + #end end - execute :chown, "-R www-data:www-data", release_path - execute :chown, "-R www-data:www-data", release_path.join('public/assets/') + #execute :chown, "-R www-data:www-data", release_path + #execute :chown, "-R www-data:www-data", release_path.join('public/assets/') #execute :kill, capture("lsof -i:9022 -t") # kill counters, will reboot itself execute :touch, release_path.join('tmp/restart.txt') end @@ -83,6 +83,36 @@ namespace :deploy do end + namespace :assets do + + Rake::Task['deploy:assets:precompile'].clear_actions + Rake::Task['deploy:assets:backup_manifest'].clear_actions + + desc 'Precompile assets locally and upload to servers' + task :precompile do + on roles(fetch(:assets_roles)) do + run_locally do + with rails_env: fetch(:rails_env) do + #execute 'bin/rake assets:precompile' + #execute 'bin/rake dedigest_assets' + end + end + + #within release_path do + #with rails_env: fetch(:rails_env) do + #upload!('./public/assets/', "#{shared_path}/public/", recursive: true) + #end + #end + rsync_host = host + run_locally { execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/" } + execute :chown, "-R www-data:www-data", shared_path.join('public/assets/') + + #run_locally { execute 'rm -rf public/assets' } + end + end + + end + after :publishing, :restart do #deploy.update_remote_cache end From c29f89354fcd144316d6f45f404b2c48e0b4cc99 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 16:27:07 +0200 Subject: [PATCH 5/8] Add puma file --- config/deploy.rb | 7 +++++++ config/puma.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 config/puma.rb diff --git a/config/deploy.rb b/config/deploy.rb index d7bb87f8..c69ad356 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -112,6 +112,13 @@ namespace :deploy do end end + desc 'Set config/puma.rb-symlink for upstart' + task :puma_config do + on roles(:app) do + execute "ln -s #{shared_path}/puma.rb #{release_path}/config/puma.rb" + end + end + after :finishing, :puma_config after :publishing, :restart do #deploy.update_remote_cache diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 00000000..0ffefd1a --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,29 @@ +# Change to match your CPU core count +workers 2 + +# Min and Max threads per worker +threads 1, 6 + +app_dir = File.expand_path("../..", __FILE__) +shared_dir = "#{app_dir}/shared" + +# Default to production +rails_env = ENV['RAILS_ENV'] || "production" +environment rails_env + +# Set up socket location +bind "unix://#{shared_dir}/sockets/puma.sock" + +# Logging +stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true + +# Set master PID and state locations +pidfile "#{shared_dir}/pids/puma.pid" +state_path "#{shared_dir}/pids/puma.state" +activate_control_app + +#on_worker_boot do + #require "active_record" + #ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished + #ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env]) +#end From ec03e8cf4b1868811892db00990d026fed37320d Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 16:41:21 +0200 Subject: [PATCH 6/8] Fix asset deployment and remove puma config, since it is not used anyway --- Capfile | 2 +- config/deploy.rb | 16 ++++++++-------- config/puma.rb | 29 ----------------------------- 3 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 config/puma.rb diff --git a/Capfile b/Capfile index da709e35..6b226745 100644 --- a/Capfile +++ b/Capfile @@ -17,7 +17,7 @@ require 'capistrano/deploy' require 'capistrano/rvm' # require 'capistrano/rbenv' # require 'capistrano/chruby' -require 'capistrano-bundler' +require 'capistrano/bundler' require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' require 'capistrano/puma' diff --git a/config/deploy.rb b/config/deploy.rb index c69ad356..89fe7d6c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -32,7 +32,7 @@ set :deploy_to, '/var/www/mozo.bar' # set :linked_files, %w{config/database.yml} # Default value for linked_dirs is [] -set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} +set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/assets} # Default value for default_env is {} # set :default_env, { path: "/opt/ruby/bin:$PATH" } @@ -112,13 +112,13 @@ namespace :deploy do end end - desc 'Set config/puma.rb-symlink for upstart' - task :puma_config do - on roles(:app) do - execute "ln -s #{shared_path}/puma.rb #{release_path}/config/puma.rb" - end - end - after :finishing, :puma_config + #desc 'Set config/puma.rb-symlink for upstart' + #task :puma_config do + #on roles(:app) do + #execute "ln -sf #{shared_path}/puma.rb #{release_path}/config/puma.rb" + #end + #end + #after :finishing, :puma_config after :publishing, :restart do #deploy.update_remote_cache diff --git a/config/puma.rb b/config/puma.rb deleted file mode 100644 index 0ffefd1a..00000000 --- a/config/puma.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Change to match your CPU core count -workers 2 - -# Min and Max threads per worker -threads 1, 6 - -app_dir = File.expand_path("../..", __FILE__) -shared_dir = "#{app_dir}/shared" - -# Default to production -rails_env = ENV['RAILS_ENV'] || "production" -environment rails_env - -# Set up socket location -bind "unix://#{shared_dir}/sockets/puma.sock" - -# Logging -stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true - -# Set master PID and state locations -pidfile "#{shared_dir}/pids/puma.pid" -state_path "#{shared_dir}/pids/puma.state" -activate_control_app - -#on_worker_boot do - #require "active_record" - #ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished - #ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env]) -#end From be3f5e6f8b10c627e1ea57027448170a5a857acb Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 16:48:31 +0200 Subject: [PATCH 7/8] Reactivate local asset stuff for deployment --- config/deploy.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 89fe7d6c..5e7e4115 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -93,8 +93,8 @@ namespace :deploy do on roles(fetch(:assets_roles)) do run_locally do with rails_env: fetch(:rails_env) do - #execute 'bin/rake assets:precompile' - #execute 'bin/rake dedigest_assets' + execute 'bin/rake assets:precompile' + execute 'bin/rake dedigest_assets' end end @@ -107,7 +107,7 @@ namespace :deploy do run_locally { execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/" } execute :chown, "-R www-data:www-data", shared_path.join('public/assets/') - #run_locally { execute 'rm -rf public/assets' } + run_locally { execute 'rm -rf public/assets' } end end From 1313fdda9bb8476d6c87c829c446877c3e4bd8ab Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 26 May 2015 17:22:51 +0200 Subject: [PATCH 8/8] Gemfile refactor --- Gemfile | 8 ++++---- Gemfile.lock | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 3989f70a..7efb48d8 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,6 @@ group :assets do gem 'js-routes' gem "font-awesome-rails" #gem 'capistrano-local-precompile', require: false - gem "airbrussh", require: false # See https://github.com/sstephenson/execjs#readme for more supported runtimes #gem 'therubyracer', platforms: :ruby @@ -106,11 +105,12 @@ group :development do gem 'letter_opener' # gem 'thin' gem 'faye' - gem 'capistrano', '~> 3.0', require: false + gem 'capistrano', require: false gem 'capistrano-bundler', require: false - gem 'capistrano-rvm', '~> 0.1', require: false - gem 'capistrano-rails', '~> 1.1', require: false + gem 'capistrano-rvm', require: false + gem 'capistrano-rails', require: false gem 'capistrano3-puma', require: false + gem "airbrussh", require: false gem 'spring' gem 'spring-commands-rspec' gem 'web-console', '~> 2.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6479d2ab..b8e2aff5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -482,10 +482,10 @@ DEPENDENCIES airbrussh bourbon cancancan - capistrano (~> 3.0) + capistrano capistrano-bundler - capistrano-rails (~> 1.1) - capistrano-rvm (~> 0.1) + capistrano-rails + capistrano-rvm capistrano3-puma capybara-screenshot cmtool!