From 808f0fcfbba89928ca4446061d87dde5c8bc1718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 7 Aug 2015 12:17:18 +0200 Subject: [PATCH 1/4] adds capistrano's deploy configuration and scripts --- Capfile | 12 +++++++++++ Gemfile | 9 +++------ Gemfile.lock | 21 +++++++++++++++++++ config/deploy.rb | 37 ++++++++++++++++++++++++++++++++++ config/deploy/preproduction.rb | 5 +++++ config/deploy/production.rb | 5 +++++ config/deploy/staging.rb | 5 +++++ 7 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 Capfile create mode 100644 config/deploy.rb create mode 100644 config/deploy/preproduction.rb create mode 100644 config/deploy/production.rb create mode 100644 config/deploy/staging.rb diff --git a/Capfile b/Capfile new file mode 100644 index 000000000..7cbfc3dd8 --- /dev/null +++ b/Capfile @@ -0,0 +1,12 @@ +# Load DSL and set up stages +require 'capistrano/setup' + +# Include default deployment tasks +require 'capistrano/deploy' + +require 'capistrano/bundler' +require 'capistrano/rails/assets' +require 'capistrano/rails/migrations' + +# Load 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 d96ea4e03..3b9106df6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.3' # Use PostgreSQL @@ -26,11 +25,6 @@ gem 'devise' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' gem 'acts_as_commentable_with_threading' -# Use Unicorn as the app server -# gem 'unicorn' - -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development gem 'acts-as-taggable-on' gem "responders" gem 'foundation-rails' @@ -52,6 +46,9 @@ group :development, :test do gem 'quiet_assets' gem 'letter_opener_web', '~> 1.2.0' gem 'i18n-tasks' + gem 'capistrano', '3.4.0', require: false + gem "capistrano-bundler", '1.1.4', require: false + gem "capistrano-rails", '1.1.3', require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index bc4dd1e27..ae4ba36e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,6 +53,16 @@ GEM builder (3.2.2) byebug (5.0.0) columnize (= 0.9.0) + capistrano (3.4.0) + i18n + rake (>= 10.0.0) + sshkit (~> 1.3) + capistrano-bundler (1.1.4) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-rails (1.1.3) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -74,6 +84,7 @@ GEM coffee-script-source execjs coffee-script-source (1.9.1.1) + colorize (0.7.7) columnize (0.9.0) coveralls (0.8.2) json (~> 1.8) @@ -145,6 +156,9 @@ GEM mini_portile (0.6.2) minitest (5.7.0) multi_json (1.11.2) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.2) netrc (0.10.3) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) @@ -232,6 +246,10 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) + sshkit (1.7.1) + colorize (>= 0.7.0) + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) term-ansicolor (1.3.2) tins (~> 1.0) terminal-table (1.5.2) @@ -271,6 +289,9 @@ DEPENDENCIES acts_as_commentable_with_threading acts_as_votable byebug + capistrano (= 3.4.0) + capistrano-bundler (= 1.1.4) + capistrano-rails (= 1.1.3) capybara ckeditor coffee-rails (~> 4.1.0) diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 000000000..6ff4b36ac --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,37 @@ +# config valid only for current version of Capistrano +lock '3.4.0' + +def deploysecret(key) + @deploy_secrets_yml ||= YAML.load_file('config/deploy-secrets.yml')[fetch(:stage).to_s] + @deploy_secrets_yml[key.to_s] +end + +set :rails_env, fetch(:stage) + +set :application, 'participacion' +set :repo_url, 'git@github.com:AyuntamientoMadrid/participacion.git' + +set :scm, :git +set :revision, `git rev-parse --short #{fetch(:branch)}`.strip + +set :log_level, :info + +set :linked_files, %w{config/database.yml config/secrets.yml} +set :linked_dirs, %w{log tmp public/system public/assets} + +set :keep_releases, 5 + +set :local_user, ENV['USER'] + +namespace :deploy do + + 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/preproduction.rb b/config/deploy/preproduction.rb new file mode 100644 index 000000000..fb9033c03 --- /dev/null +++ b/config/deploy/preproduction.rb @@ -0,0 +1,5 @@ +set :deploy_to, deploysecret(:deploy_to) +set :branch, :production +set :ssh_options, port: deploysecret(:ssh_port) + +server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) \ No newline at end of file diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 000000000..fb9033c03 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,5 @@ +set :deploy_to, deploysecret(:deploy_to) +set :branch, :production +set :ssh_options, port: deploysecret(:ssh_port) + +server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) \ No newline at end of file diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb new file mode 100644 index 000000000..9a2008ddc --- /dev/null +++ b/config/deploy/staging.rb @@ -0,0 +1,5 @@ +set :deploy_to, deploysecret(:deploy_to) +set :branch, :master +set :ssh_options, port: deploysecret(:ssh_port) + +server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) From 949f8a68df7fd5cc50bb47da0c5a5feb8e4c3178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 7 Aug 2015 12:19:01 +0200 Subject: [PATCH 2/4] adds sample deploy-secrets.yml file --- .gitignore | 1 + config/deploy-secrets.yml.example | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 config/deploy-secrets.yml.example diff --git a/.gitignore b/.gitignore index eb917c637..5cc519787 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,6 @@ /spec/examples.txt /config/database.yml /config/secrets.yml +/config/deploy-secrets.yml /coverage diff --git a/config/deploy-secrets.yml.example b/config/deploy-secrets.yml.example new file mode 100644 index 000000000..b69fea225 --- /dev/null +++ b/config/deploy-secrets.yml.example @@ -0,0 +1,18 @@ +staging: + deploy_to: "/var/www/participacion" + ssh_port: 21 + server: staging.participacion.madrid.es + user: xxxxx + +preproduction: + deploy_to: "/var/www/participacion" + ssh_port: 2222 + server: xxx.xxx.xxx.xxx + user: xxxxx + +production: + deploy_to: "/var/www/participacion" + ssh_port: 2222 + server: xxx.xxx.xxx.xxx + user: xxxxx + From 8a8ca834baf21221ca5591e979beced8e5a10b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 7 Aug 2015 12:21:03 +0200 Subject: [PATCH 3/4] adds capistrano-rvm sets ruby version for deploy to 2.2.2 --- Capfile | 1 + Gemfile | 1 + Gemfile.lock | 4 ++++ config/deploy.rb | 1 + 4 files changed, 7 insertions(+) diff --git a/Capfile b/Capfile index 7cbfc3dd8..bccdc3ab9 100644 --- a/Capfile +++ b/Capfile @@ -4,6 +4,7 @@ require 'capistrano/setup' # Include default deployment tasks require 'capistrano/deploy' +require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' diff --git a/Gemfile b/Gemfile index 3b9106df6..68069b954 100644 --- a/Gemfile +++ b/Gemfile @@ -49,6 +49,7 @@ group :development, :test do gem 'capistrano', '3.4.0', require: false gem "capistrano-bundler", '1.1.4', require: false gem "capistrano-rails", '1.1.3', require: false + gem "capistrano-rvm", require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index ae4ba36e3..bda9c97b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,6 +63,9 @@ GEM capistrano-rails (1.1.3) capistrano (~> 3.1) capistrano-bundler (~> 1.1) + capistrano-rvm (0.1.2) + capistrano (~> 3.0) + sshkit (~> 1.2) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -292,6 +295,7 @@ DEPENDENCIES capistrano (= 3.4.0) capistrano-bundler (= 1.1.4) capistrano-rails (= 1.1.3) + capistrano-rvm capybara ckeditor coffee-rails (~> 4.1.0) diff --git a/config/deploy.rb b/config/deploy.rb index 6ff4b36ac..8104d742f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -7,6 +7,7 @@ def deploysecret(key) end set :rails_env, fetch(:stage) +set :rvm_ruby_version, '2.2.2' set :application, 'participacion' set :repo_url, 'git@github.com:AyuntamientoMadrid/participacion.git' From 60a9fad9c1ff80409ed4976603bf72bd8274f3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 7 Aug 2015 12:23:33 +0200 Subject: [PATCH 4/4] adds passenger to deploy config --- Capfile | 1 + Gemfile | 1 + Gemfile.lock | 3 +++ config/deploy/staging.rb | 2 ++ 4 files changed, 7 insertions(+) diff --git a/Capfile b/Capfile index bccdc3ab9..b565fae23 100644 --- a/Capfile +++ b/Capfile @@ -8,6 +8,7 @@ require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' +require 'capistrano/passenger' # Load 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 68069b954..3ede96cce 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ group :development, :test do gem "capistrano-bundler", '1.1.4', require: false gem "capistrano-rails", '1.1.3', require: false gem "capistrano-rvm", require: false + gem "capistrano-passenger", require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index bda9c97b3..bdeda8b6e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,8 @@ GEM capistrano-bundler (1.1.4) capistrano (~> 3.1) sshkit (~> 1.2) + capistrano-passenger (0.1.1) + capistrano (~> 3.0) capistrano-rails (1.1.3) capistrano (~> 3.1) capistrano-bundler (~> 1.1) @@ -294,6 +296,7 @@ DEPENDENCIES byebug capistrano (= 3.4.0) capistrano-bundler (= 1.1.4) + capistrano-passenger capistrano-rails (= 1.1.3) capistrano-rvm capybara diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 9a2008ddc..5ca436c42 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -2,4 +2,6 @@ set :deploy_to, deploysecret(:deploy_to) set :branch, :master set :ssh_options, port: deploysecret(:ssh_port) +set :passenger_restart_with_sudo, false + server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer)