Commit dbc71b08dac24b4bd923cc3e60c3b7174de3e300
1 parent
909de786
Exists in
master
and in
1 other branch
change deploy method
Showing
5 changed files
with
90 additions
and
13 deletions
Show diff stats
Capfile
@@ -17,9 +17,11 @@ require 'capistrano/deploy' | @@ -17,9 +17,11 @@ require 'capistrano/deploy' | ||
17 | require 'capistrano/rvm' | 17 | require 'capistrano/rvm' |
18 | # require 'capistrano/rbenv' | 18 | # require 'capistrano/rbenv' |
19 | # require 'capistrano/chruby' | 19 | # require 'capistrano/chruby' |
20 | +require 'capistrano/rails' | ||
20 | require 'capistrano/bundler' | 21 | require 'capistrano/bundler' |
21 | require 'capistrano/rails/assets' | 22 | require 'capistrano/rails/assets' |
22 | require 'capistrano/rails/migrations' | 23 | require 'capistrano/rails/migrations' |
24 | +require 'capistrano/puma' | ||
23 | 25 | ||
24 | # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | 26 | # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. |
25 | Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } | 27 | Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } |
Gemfile
Gemfile.lock
@@ -270,6 +270,7 @@ GEM | @@ -270,6 +270,7 @@ GEM | ||
270 | pry-rescue (1.4.1) | 270 | pry-rescue (1.4.1) |
271 | interception (>= 0.5) | 271 | interception (>= 0.5) |
272 | pry | 272 | pry |
273 | + puma (3.2.0) | ||
273 | quiet_assets (1.0.2) | 274 | quiet_assets (1.0.2) |
274 | railties (>= 3.1, < 5.0) | 275 | railties (>= 3.1, < 5.0) |
275 | rack (1.5.2) | 276 | rack (1.5.2) |
@@ -459,6 +460,7 @@ DEPENDENCIES | @@ -459,6 +460,7 @@ DEPENDENCIES | ||
459 | pry-debugger | 460 | pry-debugger |
460 | pry-rails | 461 | pry-rails |
461 | pry-rescue | 462 | pry-rescue |
463 | + puma | ||
462 | quiet_assets | 464 | quiet_assets |
463 | rack-livereload | 465 | rack-livereload |
464 | rails (= 4.1.1) | 466 | rails (= 4.1.1) |
config/deploy.rb
@@ -8,9 +8,21 @@ set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' | @@ -8,9 +8,21 @@ set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' | ||
8 | # Default branch is :master | 8 | # Default branch is :master |
9 | ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call | 9 | ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call |
10 | 10 | ||
11 | +set :puma_threads, [4, 16] | ||
12 | +set :puma_workers, 0 | ||
13 | + | ||
11 | # Default deploy_to directory is /var/www/my_app | 14 | # Default deploy_to directory is /var/www/my_app |
12 | -set :deploy_to, '/srv/vlibras-web2/' | 15 | +set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" |
13 | set :deploy_via, :copy | 16 | set :deploy_via, :copy |
17 | +set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock" | ||
18 | +set :puma_state, "#{shared_path}/tmp/pids/puma.state" | ||
19 | +set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" | ||
20 | +set :puma_access_log, "#{release_path}/log/puma.error.log" | ||
21 | +set :puma_error_log, "#{release_path}/log/puma.access.log" | ||
22 | +set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) } | ||
23 | +set :puma_preload_app, true | ||
24 | +set :puma_worker_timeout, nil | ||
25 | +set :puma_init_active_record, true # Change to false when not using ActiveRecord | ||
14 | 26 | ||
15 | set :rails_env, 'production' | 27 | set :rails_env, 'production' |
16 | 28 | ||
@@ -40,24 +52,51 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public | @@ -40,24 +52,51 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public | ||
40 | # Default value for keep_releases is 5 | 52 | # Default value for keep_releases is 5 |
41 | set :keep_releases, 3 | 53 | set :keep_releases, 3 |
42 | 54 | ||
55 | +namespace :puma do | ||
56 | + desc 'Create Directories for Puma Pids and Socket' | ||
57 | + task :make_dirs do | ||
58 | + on roles(:app) do | ||
59 | + execute "mkdir #{shared_path}/tmp/sockets -p" | ||
60 | + execute "mkdir #{shared_path}/tmp/pids -p" | ||
61 | + end | ||
62 | + end | ||
63 | + | ||
64 | + before :start, :make_dirs | ||
65 | +end | ||
66 | + | ||
43 | namespace :deploy do | 67 | namespace :deploy do |
44 | - desc 'Restart application' | ||
45 | - task :restart do | ||
46 | - on roles(:web), in: :sequence, wait: 5 do | 68 | + desc "Make sure local git is in sync with remote." |
69 | + task :check_revision do | ||
70 | + on roles(:app) do | ||
71 | + unless `git rev-parse HEAD` == `git rev-parse origin/master` | ||
72 | + puts "WARNING: HEAD is not the same as origin/master" | ||
73 | + puts "Run `git push` to sync changes." | ||
74 | + exit | ||
75 | + end | ||
47 | end | 76 | end |
48 | end | 77 | end |
49 | 78 | ||
50 | - after :publishing, :restart | 79 | + desc 'Initial Deploy' |
80 | + task :initial do | ||
81 | + on roles(:app) do | ||
82 | + before 'deploy:restart', 'puma:start' | ||
83 | + invoke 'deploy' | ||
84 | + end | ||
85 | + end | ||
51 | 86 | ||
52 | - after :restart, :clear_cache do | ||
53 | - on roles(:web), in: :groups, limit: 3, wait: 10 do | ||
54 | - # Here we can do anything such as: | ||
55 | - #within release_path do | ||
56 | - #execute :rake, 'assets:clobber' | ||
57 | - #execute :rake, 'assets:precompile' | ||
58 | - # execute :rake, 'tmp:clear -e production' | ||
59 | - #end | 87 | + desc 'Restart application' |
88 | + task :restart do | ||
89 | + on roles(:app), in: :sequence, wait: 5 do | ||
90 | + invoke 'puma:restart' | ||
60 | end | 91 | end |
61 | end | 92 | end |
62 | 93 | ||
94 | + before :starting, :check_revision | ||
95 | + after :finishing, :compile_assets | ||
96 | + after :finishing, :cleanup | ||
97 | + after :finishing, :restart | ||
63 | end | 98 | end |
99 | + | ||
100 | +# ps aux | grep puma # Get puma pid | ||
101 | +# kill -s SIGUSR2 pid # Restart puma | ||
102 | +# kill -s SIGTERM pid # Stop puma |
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | + | ||
2 | +upstream puma { | ||
3 | + server unix:///home/deployer/apps/vlibras-web2/shared/tmp/sockets/appname-puma.sock; | ||
4 | +} | ||
5 | + | ||
6 | +server { | ||
7 | + listen 80 default_server deferred; | ||
8 | + # server_name example.com; | ||
9 | + | ||
10 | + root /home/deployer/apps/vlibras-web2/current/public; | ||
11 | + access_log /home/deployer/apps/vlibras-web2/current/log/nginx.access.log; | ||
12 | + error_log /home/deployer/apps/vlibras-web2/current/log/nginx.error.log info; | ||
13 | + | ||
14 | + location ^~ /assets/ { | ||
15 | + gzip_static on; | ||
16 | + expires max; | ||
17 | + add_header Cache-Control public; | ||
18 | + } | ||
19 | + | ||
20 | + try_files $uri/index.html $uri @puma; | ||
21 | + location @puma { | ||
22 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
23 | + proxy_set_header Host $http_host; | ||
24 | + proxy_redirect off; | ||
25 | + | ||
26 | + proxy_pass http://puma; | ||
27 | + } | ||
28 | + | ||
29 | + error_page 500 502 503 504 /500.html; | ||
30 | + client_max_body_size 10M; | ||
31 | + keepalive_timeout 10; | ||
32 | +} |