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] 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)