Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AbleTech/easy-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelramsay committed May 29, 2012
2 parents fc955e5 + 2c6068e commit 1da1e25
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 15 deletions.
4 changes: 2 additions & 2 deletions easy-deployment.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ 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'
gem.add_runtime_dependency 'capistrano-ext'
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
2 changes: 1 addition & 1 deletion lib/easy-deployment/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Easy
module Deployment
VERSION = "0.0.7"
VERSION = "0.0.9"
end
end
20 changes: 20 additions & 0 deletions lib/easy/deployment/apache.rb
Original file line number Diff line number Diff line change
@@ -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
52 changes: 46 additions & 6 deletions lib/easy/deployment/capistrano.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,47 @@
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(: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
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"
Expand All @@ -25,15 +61,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
10 changes: 4 additions & 6 deletions lib/easy/deployment/logrotate.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions lib/easy/deployment/niet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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

# niet hooks
after 'deploy:start', 'niet:start'
after 'deploy:restart', 'niet:restart'
end

0 comments on commit 1da1e25

Please sign in to comment.