From c0a5a77003a47a46b0608321ebe860ff7ecbd5ca Mon Sep 17 00:00:00 2001 From: Shevaun Coker Date: Mon, 30 Apr 2012 10:10:12 +1200 Subject: [PATCH 1/3] update version for new release --- lib/easy-deployment/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/easy-deployment/version.rb b/lib/easy-deployment/version.rb index f42e008..af64c2a 100644 --- a/lib/easy-deployment/version.rb +++ b/lib/easy-deployment/version.rb @@ -1,5 +1,5 @@ module Easy module Deployment - VERSION = "0.0.7" + VERSION = "0.0.8" end end From 29f17af712fe1a9f5e424a6b365d97704f8fb346 Mon Sep 17 00:00:00 2001 From: Shevaun Coker Date: Tue, 29 May 2012 14:47:35 +1200 Subject: [PATCH 2/3] Add more common tasks to capistrano.rb; add tasks for niet & apache --- easy-deployment.gemspec | 4 ++-- lib/easy-deployment/version.rb | 2 +- lib/easy/deployment/apache.rb | 20 ++++++++++++++++++++ lib/easy/deployment/capistrano.rb | 29 +++++++++++++++++++++++------ lib/easy/deployment/niet.rb | 28 ++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 lib/easy/deployment/apache.rb create mode 100644 lib/easy/deployment/niet.rb diff --git a/easy-deployment.gemspec b/easy-deployment.gemspec index 869bcbd..f5f144a 100644 --- a/easy-deployment.gemspec +++ b/easy-deployment.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.name = "easy-deployment" gem.require_paths = ["lib"] gem.version = Easy::Deployment::VERSION - + gem.add_runtime_dependency 'rails', '>= 3.0.0' gem.add_runtime_dependency 'capistrano' @@ -22,5 +22,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'capistrano_colors' gem.add_development_dependency 'bundler' - gem.add_development_dependency 'rspec', '~> 2.8' + gem.add_development_dependency 'rspec', '~> 2.0' end diff --git a/lib/easy-deployment/version.rb b/lib/easy-deployment/version.rb index af64c2a..3371e8c 100644 --- a/lib/easy-deployment/version.rb +++ b/lib/easy-deployment/version.rb @@ -1,5 +1,5 @@ module Easy module Deployment - VERSION = "0.0.8" + VERSION = "0.0.9" end end diff --git a/lib/easy/deployment/apache.rb b/lib/easy/deployment/apache.rb new file mode 100644 index 0000000..d5c5ed7 --- /dev/null +++ b/lib/easy/deployment/apache.rb @@ -0,0 +1,20 @@ +# Define some defaults for capistrano deploys. +# To load this capistrano configuraiton, require 'easy/deployment/apache' from deploy.rb + +Capistrano::Configuration.instance(:must_exist).load do + namespace :apache do + desc "Configure this site & Reload the apache configuration" + task :configure, :roles => :app, :except => { :no_release => true } do + run "cp -f #{current_path}/config/deploy/#{stage}/apache/* /etc/apache2/sites-enabled/" + end + + [:stop, :start, :restart].each do |action| + desc "#{action.to_s.capitalize} Apache" + task action, :roles => :web do + run "sudo apache2ctl #{action.to_s}" + end + end + end + + after 'apache:configure', 'apache:restart' +end diff --git a/lib/easy/deployment/capistrano.rb b/lib/easy/deployment/capistrano.rb index ef81315..013985f 100644 --- a/lib/easy/deployment/capistrano.rb +++ b/lib/easy/deployment/capistrano.rb @@ -9,11 +9,24 @@ default_run_options[:pty] = true namespace :deploy do + desc "Initial deploy including database creation and apache2 config setup" + task :inital do + set :migrate_target, :latest + update # updates_code and creates symlink + create_db + migrate + top.namespace :easy do + namespace(:logrotate){setup} + namespace(:apache) {configure} + end + restart + end + # By default, we deploy using passenger as an app server task :start do ; end task :stop do ; end task :restart, :roles => :app, :except => { :no_release => true } do - run "touch #{File.join(current_path,'tmp','restart.txt')}" + run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" end desc "[internal] Copies the application configuration files for this environment" @@ -25,15 +38,19 @@ end end + desc "Allow deployment of a branch, commit or tag" + task :set_branch do + set :branch, ENV['tag'] || 'master' + end end namespace :web do - desc "Configure this site & Reload the apache configuration" - task :configure do - run "cp -f #{current_path}/config/deploy/#{stage}/apache/* /etc/apache2/sites-enabled/" - run "sudo apache2ctl -k graceful" + desc "Deprecated - use apache:configure instead" + task :configure, :roles => :app, :except => { :no_release => true } do + puts "Deprecated - use apache:configure instead" end end - after "deploy:update_code", "deploy:configure" + + before 'deploy:update_code', 'deploy:set_branch' # allow specification of branch, tag or commit on the command line end diff --git a/lib/easy/deployment/niet.rb b/lib/easy/deployment/niet.rb new file mode 100644 index 0000000..233bd06 --- /dev/null +++ b/lib/easy/deployment/niet.rb @@ -0,0 +1,28 @@ +# Define some defaults for capistrano deploys. +# To load this capistrano configuraiton, require 'easy/deployment/niet' from deploy.rb + +Capistrano::Configuration.instance(:must_exist).load do + namespace :niet do + desc "Starts the niet process monitor" + task :start, roles: :job do + 2.times do + run "niet -c #{current_path} bundle exec rake jobs:work RAILS_ENV=#{stage}" + end + end + + desc "Restarts the niet process monitor" + task :restart, roles: :job do + run "killall -u deploy niet" + end + + desc "Stops the niet process monitor" + task :stop, roles: :job do + run "killall -u deploy -QUIT niet" + end + + desc "Diplays the status of the niet process monitor" + task :status, roles: :job do + run "ps -fu deploy" + end + end +end From 2c6068eadd83de6c9f03c67eea7962dcbd7823b4 Mon Sep 17 00:00:00 2001 From: Shevaun Coker Date: Tue, 29 May 2012 14:58:33 +1200 Subject: [PATCH 3/3] add missing deployment tasks (create db and load reference data); remove extra namespace in logrotate tasks; add hooks to niet tasks --- lib/easy/deployment/capistrano.rb | 31 +++++++++++++++++++++++++++---- lib/easy/deployment/logrotate.rb | 10 ++++------ lib/easy/deployment/niet.rb | 4 ++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/easy/deployment/capistrano.rb b/lib/easy/deployment/capistrano.rb index 013985f..00261ec 100644 --- a/lib/easy/deployment/capistrano.rb +++ b/lib/easy/deployment/capistrano.rb @@ -15,13 +15,36 @@ update # updates_code and creates symlink create_db migrate - top.namespace :easy do - namespace(:logrotate){setup} - namespace(:apache) {configure} - end + top.namespace(:logrotate) {setup} + top.namespace(:apache) {configure} restart end + desc "Create the database" + task :create_db, :roles => :db, :only => {:primary => true} do + migrate_target = fetch(:migrate_target, :latest) + + directory = case migrate_target.to_sym + when :current then current_path + when :latest then latest_release + else raise ArgumentError, "unknown migration target #{migrate_target.inspect}" + end + run "cd #{directory}; RAILS_ENV=#{stage} bundle exec rake db:create" + end + + desc "Load reference data" + task :reference_data, :roles => :db, :only => { :primary => true } do + migrate_target = fetch(:migrate_target, :latest) + + directory = case migrate_target.to_sym + when :current then current_path + when :latest then latest_release + else raise ArgumentError, "unknown migration target #{migrate_target.inspect}" + end + + run "cd #{directory} && RAILS_ENV=#{stage} bundle exec rake reference:load" + end + # By default, we deploy using passenger as an app server task :start do ; end task :stop do ; end diff --git a/lib/easy/deployment/logrotate.rb b/lib/easy/deployment/logrotate.rb index c36ead0..c1b8b2e 100644 --- a/lib/easy/deployment/logrotate.rb +++ b/lib/easy/deployment/logrotate.rb @@ -1,11 +1,9 @@ # To load this capistrano configuration, require 'easy/deployment/logrotate' from deploy.rb Capistrano::Configuration.instance(:must_exist).load do - namespace :easy do - namespace :logrotate do - desc "Copies the application logrotate file into /etc/logrotate.d" - task :setup, :except => { :no_release => true } do - run "cp #{current_path}/config/deploy/#{stage}/logrotate.conf /etc/logrotate.d/#{application}.conf" - end + namespace :logrotate do + desc "Copies the application logrotate file into /etc/logrotate.d" + task :setup, :except => { :no_release => true } do + run "cp #{current_path}/config/deploy/#{stage}/logrotate.conf /etc/logrotate.d/#{application}.conf" end end end diff --git a/lib/easy/deployment/niet.rb b/lib/easy/deployment/niet.rb index 233bd06..8213886 100644 --- a/lib/easy/deployment/niet.rb +++ b/lib/easy/deployment/niet.rb @@ -25,4 +25,8 @@ run "ps -fu deploy" end end + + # niet hooks + after 'deploy:start', 'niet:start' + after 'deploy:restart', 'niet:restart' end