From 0badb02f4dbcef5dbd884fec9b09a69b007825af Mon Sep 17 00:00:00 2001 From: renansoares Date: Wed, 30 Mar 2016 17:20:09 -0300 Subject: [PATCH] adding new method of deploy --- Capfile | 18 +----------------- Gemfile | 10 +++++----- Gemfile.lock | 12 ++++++++---- config/deploy.rb | 2 ++ config/deploy.rb.1 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config/deploy/production.rb | 1 - config/deploy/staging.rb | 8 ++++---- deploy.rb.1 | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 180 insertions(+), 31 deletions(-) create mode 100644 config/deploy.rb.1 create mode 100644 deploy.rb.1 diff --git a/Capfile b/Capfile index b1afcf9..6b297ad 100644 --- a/Capfile +++ b/Capfile @@ -1,26 +1,10 @@ # Load DSL and Setup Up Stages require 'capistrano/setup' - -# Includes default deployment tasks require 'capistrano/deploy' -# Includes tasks from other gems included in your Gemfile -# -# For documentation on these, see for example: -# -# https://github.com/capistrano/rvm -# https://github.com/capistrano/rbenv -# https://github.com/capistrano/chruby -# https://github.com/capistrano/bundler -# https://github.com/capistrano/rails -# -require 'capistrano/rvm' -# require 'capistrano/rbenv' -# require 'capistrano/chruby' require 'capistrano/rails' require 'capistrano/bundler' -require 'capistrano/rails/assets' -require 'capistrano/rails/migrations' +require 'capistrano/rvm' require 'capistrano/puma' # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. diff --git a/Gemfile b/Gemfile index 7024ae2..4737522 100644 --- a/Gemfile +++ b/Gemfile @@ -42,11 +42,11 @@ gem 'dotenv-rails' gem 'annotate' group :development do - gem 'capistrano', '~> 3.0', require: false - gem 'capistrano-rails', '~> 1.1', require: false - gem 'capistrano-bundler', '~> 1.1', require: false - gem 'capistrano-rvm', '~> 0.1', require: false - + gem 'capistrano', require: false + gem 'capistrano-rails', require: false + gem 'capistrano-bundler', require: false + gem 'capistrano-rvm', require: false + gem 'capistrano3-puma', require: false gem 'better_errors' gem 'binding_of_caller', :platforms=>[:mri_21] gem 'guard-bundler' diff --git a/Gemfile.lock b/Gemfile.lock index 213ba3b..8cc09b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,9 @@ GEM capistrano-rvm (0.1.1) capistrano (~> 3.0) sshkit (~> 1.2) + capistrano3-puma (1.2.1) + capistrano (~> 3.0) + puma (>= 2.6) capybara (2.2.1) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -427,10 +430,11 @@ DEPENDENCIES better_errors binding_of_caller cancan - capistrano (~> 3.0) - capistrano-bundler (~> 1.1) - capistrano-rails (~> 1.1) - capistrano-rvm (~> 0.1) + capistrano + capistrano-bundler + capistrano-rails + capistrano-rvm + capistrano3-puma capybara carrierwave coffee-rails (~> 4.0.0) diff --git a/config/deploy.rb b/config/deploy.rb index 40040e5..733be8c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -4,6 +4,8 @@ lock '3.2.1' set :application, 'vlibras-web2' set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' +set :application, 'vlibras-web2' +set :user, 'deployer' # Default branch is :master ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call diff --git a/config/deploy.rb.1 b/config/deploy.rb.1 new file mode 100644 index 0000000..422e82e --- /dev/null +++ b/config/deploy.rb.1 @@ -0,0 +1,58 @@ +# config valid only for Capistrano 3.1 +lock '3.2.1' + +set :application, 'my_app_name' +set :repo_url, 'git@example.com:me/my_repo.git' + +# Default branch is :master +# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call + +# Default deploy_to directory is /var/www/my_app +# set :deploy_to, '/var/www/my_app' + +# Default value for :scm is :git +# set :scm, :git + +# Default value for :format is :pretty +# set :format, :pretty + +# Default value for :log_level is :debug +# set :log_level, :debug + +# Default value for :pty is false +# set :pty, true + +# Default value for :linked_files is [] +# set :linked_files, %w{config/database.yml} + +# Default value for linked_dirs is [] +# set :linked_dirs, %w{bin 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 + +namespace :deploy do + + desc 'Restart application' + task :restart do + on roles(:app), in: :sequence, wait: 5 do + # Your restart mechanism here, for example: + # execute :touch, release_path.join('tmp/restart.txt') + end + end + + after :publishing, :restart + + 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 + +end diff --git a/config/deploy/production.rb b/config/deploy/production.rb index d0096be..e664a6c 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,4 +1,3 @@ -# -*- encoding : utf-8 -*- # Simple Role Syntax # ================== # Supports bulk-adding hosts to roles, the primary server in each group diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index b15fffb..e664a6c 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,11 +1,12 @@ -# -*- encoding : utf-8 -*- # 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. Don't declare `role :all`, it's a meta role. -# role :web, %w{deploy@example.com} +role :app, %w{deploy@example.com} +role :web, %w{deploy@example.com} +role :db, %w{deploy@example.com} # Extended Server Syntax @@ -14,9 +15,8 @@ # server list. The second argument is a, or duck-types, Hash and is # used to set extended properties on the server. -server '150.165.204.30', port: 2220, user: 'deploy', roles: %w{web} +server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value -set :rails_env, 'production' # Custom SSH Options # ================== diff --git a/deploy.rb.1 b/deploy.rb.1 new file mode 100644 index 0000000..40040e5 --- /dev/null +++ b/deploy.rb.1 @@ -0,0 +1,102 @@ +# -*- encoding : utf-8 -*- +# config valid only for Capistrano 3.1 +lock '3.2.1' + +set :application, 'vlibras-web2' +set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' + +# Default branch is :master +ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call + +set :puma_threads, [4, 16] +set :puma_workers, 0 + +# Default deploy_to directory is /var/www/my_app +set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" +set :deploy_via, :copy +set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.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 :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) } +set :puma_preload_app, true +set :puma_worker_timeout, nil +set :puma_init_active_record, true # Change to false when not using ActiveRecord + +set :rails_env, 'production' + +set :use_sudo, false + +# Default value for :scm is :git +# set :scm, :git + +# Default value for :format is :pretty +# set :format, :pretty + +# Default value for :log_level is :debug +# set :log_level, :debug + +# Default value for :pty is false +set :pty, true + +# Default value for :linked_files is [] +set :linked_files, %w{config/database.yml .env} + +# Default value for linked_dirs is [] +set :linked_dirs, %w{bin 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, 3 + +namespace :puma do + desc 'Create Directories for Puma Pids and Socket' + task :make_dirs do + on roles(:app) do + execute "mkdir #{shared_path}/tmp/sockets -p" + execute "mkdir #{shared_path}/tmp/pids -p" + end + end + + before :start, :make_dirs +end + +namespace :deploy do + desc "Make sure local git is in sync with remote." + task :check_revision do + on roles(:app) do + unless `git rev-parse HEAD` == `git rev-parse origin/master` + puts "WARNING: HEAD is not the same as origin/master" + puts "Run `git push` to sync changes." + exit + end + end + end + + desc 'Initial Deploy' + task :initial do + on roles(:app) do + before 'deploy:restart', 'puma:start' + invoke 'deploy' + end + end + + desc 'Restart application' + task :restart do + on roles(:app), in: :sequence, wait: 5 do + invoke 'puma:restart' + end + end + + before :starting, :check_revision + after :finishing, :compile_assets + after :finishing, :cleanup + after :finishing, :restart +end + +# ps aux | grep puma # Get puma pid +# kill -s SIGUSR2 pid # Restart puma +# kill -s SIGTERM pid # Stop puma -- libgit2 0.21.2