Skip to content

Commit

Permalink
Update production env, using puma as server
Browse files Browse the repository at this point in the history
  • Loading branch information
kdstarter committed Mar 31, 2018
1 parent 995c0b7 commit adfcdef
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 220 deletions.
27 changes: 19 additions & 8 deletions Capfile
@@ -1,12 +1,19 @@
require 'highline/import'

# Load DSL and Setup Up Stages
# frozen_string_literal: true
# Load DSL and set up stages
require 'capistrano/setup'

# Includes default deployment tasks
# Include default deployment tasks
require 'capistrano/deploy'

# Includes tasks from other gems included in your Gemfile
require 'capistrano/puma'
require 'capistrano/puma/nginx'
require 'capistrano/puma/jungle'
install_plugin Capistrano::Puma, load_hooks: false

require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
Expand All @@ -15,13 +22,17 @@ require 'capistrano/deploy'
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/passenger'

require 'sshkit/sudo'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
14 changes: 9 additions & 5 deletions Gemfile
Expand Up @@ -53,6 +53,8 @@ gem 'sinatra', '1.4.5', require: false
gem 'redis-rails', '4.0.0'
gem 'redis-namespace', '1.4.1'

gem 'puma', '~> 3.11.0'

group :production do
gem 'oneapm_rpm', '~> 1.3.5'
end
Expand All @@ -77,9 +79,11 @@ group :development, :test do
gem 'simplecov', '0.9.0', require: false
gem 'coveralls', '0.7.1', require: false

gem 'highline', '1.6.21'
gem 'capistrano', '3.1.0'
gem 'capistrano-rvm', '0.1.1'
gem 'capistrano-rails', '1.1.0'
gem 'capistrano-bundler', '1.1.3'
gem 'capistrano', '3.7.0'
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rvm'
gem 'capistrano-sidekiq'
gem 'capistrano3-puma'
gem 'sshkit-sudo'
end
45 changes: 31 additions & 14 deletions Gemfile.lock
Expand Up @@ -50,6 +50,8 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
airbrussh (1.3.0)
sshkit (>= 1.6.1, != 1.7.0)
arbre (1.0.2)
activesupport (>= 3.0.0)
arel (5.0.1.20140414130214)
Expand All @@ -73,19 +75,29 @@ GEM
byebug (3.2.0)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
capistrano (3.1.0)
capistrano (3.7.0)
airbrussh (>= 1.0.0)
capistrano-harrow
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
sshkit (>= 1.9.0)
capistrano-bundler (1.1.3)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-harrow (0.5.3)
capistrano-rails (1.1.0)
capistrano (>= 3.0.0)
capistrano-bundler (>= 1.0.0)
capistrano-rvm (0.1.1)
capistrano (~> 3.0)
sshkit (~> 1.2)
capistrano-sidekiq (0.5.3)
capistrano
sidekiq
capistrano3-puma (3.1.1)
capistrano (~> 3.7)
capistrano-bundler
puma (~> 3.4)
capybara (2.4.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -119,8 +131,8 @@ GEM
execjs
coffee-script-source (1.8.0)
colored (1.2)
colorize (0.7.3)
columnize (0.8.9)
concurrent-ruby (1.0.5)
connection_pool (2.0.0)
coveralls (0.7.1)
multi_json (~> 1.3)
Expand Down Expand Up @@ -160,13 +172,13 @@ GEM
has_scope (0.6.0.rc)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
highline (1.6.21)
hike (1.2.3)
hirb (0.7.2)
httparty (0.13.1)
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.6.11)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
inherited_resources (1.4.1)
has_scope (~> 0.6.0.rc)
responders (~> 1.0.0.rc)
Expand Down Expand Up @@ -195,7 +207,7 @@ GEM
mysql2 (0.3.21)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
net-ssh (4.2.0)
netrc (0.7.7)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
Expand All @@ -208,6 +220,7 @@ GEM
polyamorous (1.1.0)
activerecord (>= 3.0)
polyglot (0.3.5)
puma (3.11.3)
qiniu (6.2.4)
json (~> 1.7)
mime-types (~> 1.19)
Expand Down Expand Up @@ -253,7 +266,7 @@ GEM
activesupport (= 4.1.5)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rake (12.3.1)
ransack (1.4.1)
actionpack (>= 3.0)
activerecord (>= 3.0)
Expand Down Expand Up @@ -345,10 +358,11 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sshkit (1.5.1)
colorize
sshkit (1.16.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
sshkit-sudo (0.1.0)
sshkit (~> 1.8)
subexec (0.2.3)
term-ansicolor (1.3.0)
tins (~> 1.0)
Expand Down Expand Up @@ -391,10 +405,12 @@ DEPENDENCIES
browser (~> 0.6.0)
bugsnag (= 2.4.1)
byebug (= 3.2.0)
capistrano (= 3.1.0)
capistrano-bundler (= 1.1.3)
capistrano-rails (= 1.1.0)
capistrano-rvm (= 0.1.1)
capistrano (= 3.7.0)
capistrano-bundler
capistrano-rails
capistrano-rvm
capistrano-sidekiq
capistrano3-puma
capybara (= 2.4.3)
carrierwave (= 0.10.0)
carrierwave-qiniu (= 0.1.3)
Expand All @@ -409,7 +425,6 @@ DEPENDENCIES
factory_girl_rails (= 4.4.1)
font-awesome-rails (= 4.1.0)
friendly_id (= 5.0.4)
highline (= 1.6.21)
hirb (= 0.7.2)
jquery-rails (= 3.1.1)
jquery-turbolinks (= 2.1.0)
Expand All @@ -421,6 +436,7 @@ DEPENDENCIES
nprogress-rails (~> 0.1.6.7)
oneapm_rpm (~> 1.3.5)
paranoia (= 2.0.2)
puma (~> 3.11.0)
qiniu-rs (= 3.4.10)
rails (~> 4.1.5)
rails-i18n (= 4.0.2)
Expand All @@ -437,6 +453,7 @@ DEPENDENCIES
simple_form (= 3.1.0.rc2)
simplecov (= 0.9.0)
sinatra (= 1.4.5)
sshkit-sudo
turbolinks (= 2.5.3)
uglifier (= 2.5.1)
watir-webdriver (= 0.6.11)
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Expand Up @@ -3,4 +3,11 @@

require File.expand_path('../config/application', __FILE__)

module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment

Rails.application.load_tasks
66 changes: 33 additions & 33 deletions config/deploy.rb
@@ -1,27 +1,19 @@
# config valid only for Capistrano 3.1
lock '3.1.0'

def ask_secretly(key, default=nil)
set key, proc {
hint = default ? " [#{default}]" : ""
answer = HighLine.new.ask("Enter server #{key}#{hint}: ") { |q| q.echo = false }.to_s
}
end
# frozen_string_literal: true
# config valid only for current version of Capistrano
lock '3.7.0'

set :application, 'blog-eye'
set :repo_url, "git@github.com:agilejzl/blog-eye.git"

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
ask :branch, 'master'

# Default deploy_to directory is /var/www/my_app
set :deploy_to, "/var/www/#{fetch(:application)}"
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'

# Default value for :scm is :git
set :scm, :git
set :use_sudo, false
# set :run_options, { pty: true }
set :ssh_options, { forward_agent: true }
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty
Expand All @@ -30,27 +22,34 @@ def ask_secretly(key, default=nil)
# set :log_level, :debug

# Default value for :pty is false
set :pty, true
set :pty, false

# Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/settings.yml config/sensitive.yml config/oneapm.yml}
set :linked_files, fetch(:linked_files, []).push('config/settings.yml', 'config/database.yml', 'config/sensitive.yml', 'config/puma.rb')

# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, %w{public/assets}
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
set :keep_releases, 5
# set :keep_releases, 5

set :puma_init_active_record, true
# Puma config file
set :puma_conf, "#{shared_path}/config/puma.rb"

set :rvm_binary, '~/.rvm/bin/rvm'
set :rvm_ruby_version, 'default'

namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 3 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end

Expand All @@ -63,14 +62,15 @@ def ask_secretly(key, default=nil)
end
end

before :publishing, :rake_commands

after :publishing, :restart

after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 3 do
# Here we can do anything such as:
desc 'Restart the application'
task :restart do
on roles(:app) do
execute "cd #{deploy_to}/current && #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/tmp/pids/puma.state restart"
end
end

before :publishing, :rake_commands
end

after :deploy, 'deploy:restart'

0 comments on commit adfcdef

Please sign in to comment.