Commit f8dc1043 authored by Francisco de Juan's avatar Francisco de Juan

initial commit of ohwr deploy script

parents
ruby-1.9.3-p545
source 'https://rubygems.org'
gem "vlad"
gem "vlad-git"
gem "renfield"
gem "lockfile"
gem "net-ssh"
GEM
remote: https://rubygems.org/
specs:
lockfile (2.1.0)
net-ssh (2.3.0)
open4 (1.3.0)
rake (0.9.2.2)
rake-remote_task (2.0.6)
open4 (~> 1.0)
rake (~> 0.8)
renfield (0.0.2)
vlad (>= 2.0.0)
vlad (2.2.5)
rake (~> 0.8)
rake-remote_task (~> 2.0)
vlad-git (2.2.0)
vlad (>= 2.1.0)
PLATFORMS
ruby
DEPENDENCIES
lockfile
net-ssh
renfield
vlad
vlad-git
require 'vlad'
require 'renfield'
require 'bundler/vlad'
Vlad.load :app => :passenger,
:scm => :git
Dir.glob(File.dirname(__FILE__) + '/lib/*') {|file| require file}
def prepare(stage)
info "Pointing to #{stage[:name]}"
set :domain, stage[:domain]
set :application, stage[:application]
set :deploy_to, stage[:deploy_to]
set :rails_env, stage[:rails_env]
set :repository, stage[:repository]
set :revision, stage[:revision]
set :ssh_flags, stage[:ssh_flags] || '-p 30262'
set :shared_paths, stage[:shared_paths] if stage[:shared_paths]
set :mkdirs, stage[:mkdirs] if stage[:mkdirs]
set :app, stage[:app] if stage[:app]
set :web_command, stage[:web_command] if stage[:web_command]
end
@dump_releases=nil
def dump_releases
if @dump_releases.nil?
@dump_releases=run("ls -x #{dumps_path}").split.sort
end
return @dump_releases
end
def dumps_path
return File.join(shared_path, 'dumps')
end
@dump_path=nil
def dump_path
if @dump_path.nil?
@dump_path = File.join(dumps_path, now)
run "mkdir -p #{@dump_path}"
end
return @dump_path
end
namespace :vlad do
desc "Notify deploy"
remote_task :notify_deploy do
info "Notifying to errbit"
run "cd #{current_path} && bundle exec rake airbrake:deploy RAILS_ENV=#{rails_env} TO=#{rails_env} REVISION='#{revision.split('/').last}' USER=`whoami` REPO=#{repository}"
end
desc "Notify deploy without bundler"
remote_task :notify_deploy_without_bundler do
info "Notifying to errbit"
run "cd #{current_path} && rake airbrake:deploy RAILS_ENV=#{rails_env} TO=#{rails_env} REVISION='#{revision.split('/').last}' USER=`whoami` REPO=#{repository}"
end
end
This is the Splendeo vlad deployer for all proyects
# Configuration of each service is done in the lib folder
\ No newline at end of file
@production_ohwr = {
:name => 'ohwr production',
:application => 'ohwr',
:deploy_to => '/var/rails/ohwr',
:domain => 'rails_ohwr',
:rails_env => 'production',
:repository => 'git://ohwr.org/ohr-support.git',
:revision => "remotes/origin/master",
:ssh_flags => '-p 22',
:shared_paths => {
'log' => 'log',
'system' => 'public/system',
'pids' => 'tmp/pids',
'config/database.yml' => 'config/database.yml',
'config/email.yml' => 'config/email.yml',
'config/newrelic.yml' => 'config/newrelic.yml',
'config/scm.yml' => 'config/scm.yml',
'config/initializers/errbit.rb' => 'config/initializers/erribt.rb',
'config/initializers/session_store.rb' => 'config/initializers/session_store.rb',
'files' => 'files',
'.bundle' => '.bundle'
}
}
@staging_ohwr = {
:name => 'ohr staging',
:application => 'ohwr.staging.es',
:deploy_to => '/var/rails/ohwr',
:domain => 'rails_alphastaging',
:rails_env => 'staging',
:repository => 'git://ohwr.org/ohr-support.git',
:revision => "remotes/origin/master",
:shared_paths => {
'log' => 'log',
'system' => 'public/system',
'pids' => 'tmp/pids',
'config/database.yml' => 'config/database.yml',
'config/email.yml' => 'config/email.yml',
'config/newrelic.yml' => 'config/newrelic.yml',
'config/scm.yml' => 'config/scm.yml',
'config/initializers/errbit.rb' => 'config/initializers/erribt.rb',
'config/initializers/session_store.rb' => 'config/initializers/session_store.rb',
'files' => 'files',
'.bundle' => '.bundle'
}
}
namespace :ohwr do
desc "Points vlad to the production server"
task :production do
prepare(@production_ohwr)
Rake::Task['vlad:confirm'].invoke
end
desc "Points vlad to the staging server"
task :staging do
@staging_ohwr[:revision] = "remotes/origin/#{ENV['BRANCH']}" unless ENV['BRANCH'].nil?
prepare(@staging_ohwr)
end
namespace :production do
desc "Updates production with the latest version"
remote_task :deploy => %w[
ohwr:production
ohwr:private:deploy
]
desc "Updates production without maintenance or migrations"
remote_task :hot_deploy => %w[
ohwr:production
ohwr:private:hot_deploy
]
end
namespace :staging do
desc "Updates staging with the latest version"
remote_task :deploy => %w[
ohwr:staging
ohwr:private:deploy
]
desc "Updates staging without maintenance or migrations"
remote_task :hot_deploy => %w[
ohwr:staging
ohwr:private:hot_deploy
]
desc "Clone production server on staging"
remote_task :clone_production => %w[
ohwr:staging
vlad:maintenance:set
ohwr:private:dump
ohwr:private:clone_db
ohwr:private:adapt_settings_for_staging
ohwr:private:clone_files
vlad:restart
vlad:maintenance:remove
]
end
namespace :private do
desc 'Clone DB from production to user staging'
remote_task :clone_db => %w[ ohwr:staging ] do
info "Clonning DB from production to staging"
run "pg_dump -c -h #{@production_ohwr[:domain]} -U ohwr ohwr | psql -h localhost -U ohwr ohwr"
remote_rake 'postgresql:remove_anonymous_role'
end
desc "Makes a clone of the production files directory on staging"
remote_task :clone_files => %w[ ohwr:staging ] do
info "Cloning production files into staging"
files_path = "#{shared_path}/files"
run "rm -rf #{files_path}"
run "mkdir -p #{files_path}"
run "rsync -r #{@production_ohwr[:domain]}:/#{files_path} #{files_path}"
end
desc "deploy to server" # code, files, config_files, db_migrate, clean_up
task :deploy => %w[
vlad:maintenance:set
ohwr:private:dump
vlad:update
vlad:bundle:install
ohwr:private:migrate
ohwr:private:cleanup
vlad:restart
vlad:maintenance:remove
vlad:notify_deploy
vlad:cleanup
]
desc "deploy to server without maintenance, bundle, or migrations"
task :hot_deploy => %w[
ohwr:private:dump
vlad:update
ohwr:private:cleanup
vlad:restart
vlad:cleanup
]
desc "makes a security copy of the db and files folder on the dump folder"
remote_task :dump => %w[
ohwr:private:dump:db
ohwr:private:dump:files
ohwr:private:dump:cleanup
]
desc "Executing migrations of database and plugins"
remote_task :migrate do
info "Executing rake db:migrate db:migrate:plugins"
#remote_rake 'db:migrate:upgrade_plugin_migrations db:migrate_plugins db:migrate'
remote_rake 'db:migrate db:migrate:plugins'
end
desc "Clears OHWR sessions and cache"
remote_task :cleanup do
info "OHWR clean up"
remote_rake 'tmp:cache:clear tmp:sessions:clear'
end
desc "Set the values for checkout in staging"
remote_task :adapt_settings_for_staging => %w[ ohwr:staging ] do
info 'Executing OHWR Checkout & Gitolite'
remote_rake 'staging:update_settings'
end
#namespace ohwr:private:dump
namespace :dump do
desc "dump ohwr database"
remote_task :db do
info "Dumping the database"
run "pg_dump -c -U ohwr ohwr | gzip > #{File.join(dump_path, 'ohwr.sql.gz')}"
end
desc "compressed copy of files folder into the dump folder"
remote_task :files do
info "Dumping the files folder"
run "tar -czf #{dump_path}/files.tgz #{shared_path}/files/"
end
desc "removes older releases from the dump folder"
remote_task :cleanup do
info "Cleaning up dump folder"
max = keep_releases
if dump_releases.length <= max then
puts "no old dump releases to clean up #{dump_releases.length} <= #{max}"
else
puts "keeping #{max} of #{dump_releases.length} dump releases"
directories = (dump_releases - dump_releases.last(max)).map { |release|
File.join(dumps_path, release)
}.join(" ")
run "rm -rf #{directories}"
end #if
end # :cleanup
end # namespace :dump
end #namespace :private
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment