Commit 0badb02f4dbcef5dbd884fec9b09a69b007825af
1 parent
dbc71b08
Exists in
master
and in
1 other branch
adding new method of deploy
Showing
8 changed files
with
180 additions
and
31 deletions
Show diff stats
Capfile
1 | 1 | # Load DSL and Setup Up Stages |
2 | 2 | require 'capistrano/setup' |
3 | - | |
4 | -# Includes default deployment tasks | |
5 | 3 | require 'capistrano/deploy' |
6 | 4 | |
7 | -# Includes tasks from other gems included in your Gemfile | |
8 | -# | |
9 | -# For documentation on these, see for example: | |
10 | -# | |
11 | -# https://github.com/capistrano/rvm | |
12 | -# https://github.com/capistrano/rbenv | |
13 | -# https://github.com/capistrano/chruby | |
14 | -# https://github.com/capistrano/bundler | |
15 | -# https://github.com/capistrano/rails | |
16 | -# | |
17 | -require 'capistrano/rvm' | |
18 | -# require 'capistrano/rbenv' | |
19 | -# require 'capistrano/chruby' | |
20 | 5 | require 'capistrano/rails' |
21 | 6 | require 'capistrano/bundler' |
22 | -require 'capistrano/rails/assets' | |
23 | -require 'capistrano/rails/migrations' | |
7 | +require 'capistrano/rvm' | |
24 | 8 | require 'capistrano/puma' |
25 | 9 | |
26 | 10 | # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | ... | ... |
Gemfile
... | ... | @@ -42,11 +42,11 @@ gem 'dotenv-rails' |
42 | 42 | gem 'annotate' |
43 | 43 | |
44 | 44 | group :development do |
45 | - gem 'capistrano', '~> 3.0', require: false | |
46 | - gem 'capistrano-rails', '~> 1.1', require: false | |
47 | - gem 'capistrano-bundler', '~> 1.1', require: false | |
48 | - gem 'capistrano-rvm', '~> 0.1', require: false | |
49 | - | |
45 | + gem 'capistrano', require: false | |
46 | + gem 'capistrano-rails', require: false | |
47 | + gem 'capistrano-bundler', require: false | |
48 | + gem 'capistrano-rvm', require: false | |
49 | + gem 'capistrano3-puma', require: false | |
50 | 50 | gem 'better_errors' |
51 | 51 | gem 'binding_of_caller', :platforms=>[:mri_21] |
52 | 52 | gem 'guard-bundler' | ... | ... |
Gemfile.lock
... | ... | @@ -76,6 +76,9 @@ GEM |
76 | 76 | capistrano-rvm (0.1.1) |
77 | 77 | capistrano (~> 3.0) |
78 | 78 | sshkit (~> 1.2) |
79 | + capistrano3-puma (1.2.1) | |
80 | + capistrano (~> 3.0) | |
81 | + puma (>= 2.6) | |
79 | 82 | capybara (2.2.1) |
80 | 83 | mime-types (>= 1.16) |
81 | 84 | nokogiri (>= 1.3.3) |
... | ... | @@ -427,10 +430,11 @@ DEPENDENCIES |
427 | 430 | better_errors |
428 | 431 | binding_of_caller |
429 | 432 | cancan |
430 | - capistrano (~> 3.0) | |
431 | - capistrano-bundler (~> 1.1) | |
432 | - capistrano-rails (~> 1.1) | |
433 | - capistrano-rvm (~> 0.1) | |
433 | + capistrano | |
434 | + capistrano-bundler | |
435 | + capistrano-rails | |
436 | + capistrano-rvm | |
437 | + capistrano3-puma | |
434 | 438 | capybara |
435 | 439 | carrierwave |
436 | 440 | coffee-rails (~> 4.0.0) | ... | ... |
config/deploy.rb
... | ... | @@ -4,6 +4,8 @@ lock '3.2.1' |
4 | 4 | |
5 | 5 | set :application, 'vlibras-web2' |
6 | 6 | set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' |
7 | +set :application, 'vlibras-web2' | |
8 | +set :user, 'deployer' | |
7 | 9 | |
8 | 10 | # Default branch is :master |
9 | 11 | ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call | ... | ... |
... | ... | @@ -0,0 +1,58 @@ |
1 | +# config valid only for Capistrano 3.1 | |
2 | +lock '3.2.1' | |
3 | + | |
4 | +set :application, 'my_app_name' | |
5 | +set :repo_url, 'git@example.com:me/my_repo.git' | |
6 | + | |
7 | +# Default branch is :master | |
8 | +# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call | |
9 | + | |
10 | +# Default deploy_to directory is /var/www/my_app | |
11 | +# set :deploy_to, '/var/www/my_app' | |
12 | + | |
13 | +# Default value for :scm is :git | |
14 | +# set :scm, :git | |
15 | + | |
16 | +# Default value for :format is :pretty | |
17 | +# set :format, :pretty | |
18 | + | |
19 | +# Default value for :log_level is :debug | |
20 | +# set :log_level, :debug | |
21 | + | |
22 | +# Default value for :pty is false | |
23 | +# set :pty, true | |
24 | + | |
25 | +# Default value for :linked_files is [] | |
26 | +# set :linked_files, %w{config/database.yml} | |
27 | + | |
28 | +# Default value for linked_dirs is [] | |
29 | +# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} | |
30 | + | |
31 | +# Default value for default_env is {} | |
32 | +# set :default_env, { path: "/opt/ruby/bin:$PATH" } | |
33 | + | |
34 | +# Default value for keep_releases is 5 | |
35 | +# set :keep_releases, 5 | |
36 | + | |
37 | +namespace :deploy do | |
38 | + | |
39 | + desc 'Restart application' | |
40 | + task :restart do | |
41 | + on roles(:app), in: :sequence, wait: 5 do | |
42 | + # Your restart mechanism here, for example: | |
43 | + # execute :touch, release_path.join('tmp/restart.txt') | |
44 | + end | |
45 | + end | |
46 | + | |
47 | + after :publishing, :restart | |
48 | + | |
49 | + after :restart, :clear_cache do | |
50 | + on roles(:web), in: :groups, limit: 3, wait: 10 do | |
51 | + # Here we can do anything such as: | |
52 | + # within release_path do | |
53 | + # execute :rake, 'cache:clear' | |
54 | + # end | |
55 | + end | |
56 | + end | |
57 | + | |
58 | +end | ... | ... |
config/deploy/production.rb
config/deploy/staging.rb
1 | -# -*- encoding : utf-8 -*- | |
2 | 1 | # Simple Role Syntax |
3 | 2 | # ================== |
4 | 3 | # Supports bulk-adding hosts to roles, the primary server in each group |
5 | 4 | # is considered to be the first unless any hosts have the primary |
6 | 5 | # property set. Don't declare `role :all`, it's a meta role. |
7 | 6 | |
8 | -# role :web, %w{deploy@example.com} | |
7 | +role :app, %w{deploy@example.com} | |
8 | +role :web, %w{deploy@example.com} | |
9 | +role :db, %w{deploy@example.com} | |
9 | 10 | |
10 | 11 | |
11 | 12 | # Extended Server Syntax |
... | ... | @@ -14,9 +15,8 @@ |
14 | 15 | # server list. The second argument is a, or duck-types, Hash and is |
15 | 16 | # used to set extended properties on the server. |
16 | 17 | |
17 | -server '150.165.204.30', port: 2220, user: 'deploy', roles: %w{web} | |
18 | +server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value | |
18 | 19 | |
19 | -set :rails_env, 'production' | |
20 | 20 | |
21 | 21 | # Custom SSH Options |
22 | 22 | # ================== | ... | ... |
... | ... | @@ -0,0 +1,102 @@ |
1 | +# -*- encoding : utf-8 -*- | |
2 | +# config valid only for Capistrano 3.1 | |
3 | +lock '3.2.1' | |
4 | + | |
5 | +set :application, 'vlibras-web2' | |
6 | +set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' | |
7 | + | |
8 | +# Default branch is :master | |
9 | +ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call | |
10 | + | |
11 | +set :puma_threads, [4, 16] | |
12 | +set :puma_workers, 0 | |
13 | + | |
14 | +# Default deploy_to directory is /var/www/my_app | |
15 | +set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" | |
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 | |
26 | + | |
27 | +set :rails_env, 'production' | |
28 | + | |
29 | +set :use_sudo, false | |
30 | + | |
31 | +# Default value for :scm is :git | |
32 | +# set :scm, :git | |
33 | + | |
34 | +# Default value for :format is :pretty | |
35 | +# set :format, :pretty | |
36 | + | |
37 | +# Default value for :log_level is :debug | |
38 | +# set :log_level, :debug | |
39 | + | |
40 | +# Default value for :pty is false | |
41 | +set :pty, true | |
42 | + | |
43 | +# Default value for :linked_files is [] | |
44 | +set :linked_files, %w{config/database.yml .env} | |
45 | + | |
46 | +# Default value for linked_dirs is [] | |
47 | +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} | |
48 | + | |
49 | +# Default value for default_env is {} | |
50 | +# set :default_env, { path: "/opt/ruby/bin:$PATH" } | |
51 | + | |
52 | +# Default value for keep_releases is 5 | |
53 | +set :keep_releases, 3 | |
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 | + | |
67 | +namespace :deploy 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 | |
76 | + end | |
77 | + end | |
78 | + | |
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 | |
86 | + | |
87 | + desc 'Restart application' | |
88 | + task :restart do | |
89 | + on roles(:app), in: :sequence, wait: 5 do | |
90 | + invoke 'puma:restart' | |
91 | + end | |
92 | + end | |
93 | + | |
94 | + before :starting, :check_revision | |
95 | + after :finishing, :compile_assets | |
96 | + after :finishing, :cleanup | |
97 | + after :finishing, :restart | |
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 | ... | ... |