gorilla-capistrano-recipes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Benny Degezelle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,49 @@
1
+ = gorilla-capistrano-recipes
2
+
3
+ This gem holds some capistrano presets that we use for all of our projects.
4
+ Preset configs for git, lighttpd & passenger, radiant stuff, ...
5
+
6
+ The radiant-related recipes are mostly copied from http://github.com/ehaselwanter/radiant-capistrano-extension
7
+
8
+ == How-To
9
+
10
+ Keep your Capfile clean like this:
11
+
12
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
13
+
14
+ set :user, 'user'
15
+ set :password, "password"
16
+ set :application, "www"
17
+
18
+ set :repository, "user@your_git_host:git/project.git"
19
+ set :scm_password, "password"
20
+
21
+ server "your_app_host", :app, :web, :db, :primary => true
22
+
23
+ DatabaseYml = %Q{# By capistrano
24
+ production:
25
+ adapter: mysql
26
+ database: gorilla
27
+ username: gorilla
28
+ password: password
29
+ host: your_db_host
30
+ }
31
+
32
+ load 'lib/gorilla-capistrano-recipes/deploy'
33
+ load 'lib/gorilla-capistrano-recipes/mysql'
34
+ load 'lib/gorilla-capistrano-recipes/passenger'
35
+ load 'lib/gorilla-capistrano-recipes/radiant'
36
+
37
+ == Note on Patches/Pull Requests
38
+
39
+ * Fork the project.
40
+ * Make your feature addition or bug fix.
41
+ * Add tests for it. This is important so I don't break it in a
42
+ future version unintentionally.
43
+ * Commit, do not mess with rakefile, version, or history.
44
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
45
+ * Send me a pull request. Bonus points for topic branches.
46
+
47
+ == Copyright
48
+
49
+ Copyright (c) 2009 Benny Degezelle. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gorilla-capistrano-recipes"
8
+ gem.summary = %Q{Common capistrano recipes for Gorilla sites}
9
+ gem.description = %Q{This gem allows for a clean Capfile by setting up common capistrano stuff such as Git preferences, Radiant specifics, db dump helpers, passenger or lighty restart, ...}
10
+ gem.email = "benny@gorilla-webdesign.be"
11
+ gem.homepage = "http://github.com/jomz/gorilla-capistrano-recipes"
12
+ gem.authors = ["Benny Degezelle"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "gorilla-capistrano-recipes #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,48 @@
1
+ configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
2
+
3
+ configuration.load do
4
+ require "capistrano/deepmodules"
5
+
6
+ default_run_options[:pty] = true
7
+ set :ssh_options, { :forward_agent => true}
8
+ set :deploy_to, "/home/#{user}/apps/#{application}"
9
+ set :use_sudo, false
10
+ set :group_writable, false
11
+ set :keep_releases, 3
12
+ set :migrate_env, "password"
13
+
14
+ set :scm, "git"
15
+ set :deploy_via, :remote_cache
16
+ set :git_shallow_clone, 1
17
+ set :git_enable_submodules, 1
18
+
19
+ namespace :deploy do
20
+ desc "Keep only 3 releases"
21
+ task :after_default do
22
+ cleanup
23
+ end
24
+
25
+ desc "clear cached copy, e.g. when changing submodule urls"
26
+ task :clear_cached_copy do
27
+ run <<-CMD
28
+ rm -rf #{shared_path}/cached-copy
29
+ CMD
30
+ end
31
+
32
+ end
33
+
34
+ namespace :configs do
35
+ desc "Create all config files in shared/config"
36
+ task :copy_database_config do
37
+ run "mkdir -p #{shared_path}/config"
38
+ put DatabaseYml, "#{shared_path}/config/database.yml"
39
+ end
40
+
41
+ desc "Link in the shared config files"
42
+ task :link do
43
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
44
+ end
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,20 @@
1
+ configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
2
+
3
+ configuration.load do
4
+ namespace :deploy do
5
+ desc "Restart the web server"
6
+ task :restart, :roles => :app do
7
+ run "lighty restart >/dev/null 2>&1"
8
+ end
9
+
10
+ desc "Stop the web server"
11
+ task :stop, :roles => :app do
12
+ run "lighty stop >/dev/null 2>&1"
13
+ end
14
+
15
+ desc "Start the web server"
16
+ task :start, :roles => :app do
17
+ run "lighty start >/dev/null 2>&1"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ desc 'Dumps the production database to db/production_data.sql on the remote server'
2
+ task :remote_db_dump, :roles => :db, :only => { :primary => true } do
3
+ rake = fetch(:rake, "rake")
4
+ rails_env = fetch(:rails_env, "production")
5
+
6
+ run "cd #{deploy_to}/#{current_dir} && " +
7
+ "#{rake} RAILS_ENV=#{rails_env} db:database_dump --trace"
8
+ end
9
+
10
+ desc 'Loads the production database to db/production_data.sql on the remote server'
11
+ task :remote_db_load, :roles => :db, :only => { :primary => true } do
12
+ rake = fetch(:rake, "rake")
13
+ rails_env = fetch(:rails_env, "production")
14
+
15
+ run "cd #{deploy_to}/#{current_dir} && " +
16
+ "#{rake} RAILS_ENV=#{rails_env} db:production_data_load --trace"
17
+ end
18
+
19
+ desc 'Downloads db/production_data.sql from the remote production environment to your local machine'
20
+ task :remote_db_download, :roles => :db, :only => { :primary => true } do
21
+ download("#{deploy_to}/#{current_dir}/db/production_data.sql", "db/production_data.sql", :via => :scp)
22
+ end
23
+
24
+ desc 'Uploads db/production_data.sql to the remote production environment from your local machine'
25
+ task :remote_db_upload, :roles => :db, :only => { :primary => true } do
26
+ upload("db/development_data.sql", "#{deploy_to}/#{current_dir}/db/production_data.sql", :via => :scp)
27
+ end
28
+
29
+ desc 'Cleans up data dump file'
30
+ task :remote_db_cleanup, :roles => :db, :only => { :primary => true } do
31
+ run "rm #{deploy_to}/#{current_dir}/db/production_data.sql"
32
+ end
33
+
34
+ desc 'Cleans up data dump file'
35
+ task :remote_cache_cleanup, :roles => :app do
36
+ run "rm -rf #{deploy_to}/#{current_dir}/cache/* ;true"
37
+ end
38
+
39
+ desc 'Dumps, downloads and then cleans up the production data dump'
40
+ task :remote_db_runner do
41
+ remote_db_dump
42
+ remote_db_download
43
+ remote_db_cleanup
44
+ end
45
+
46
+ desc 'Dumps, uploads and then cleans up the production data dump'
47
+ task :local_db_runner do
48
+ remote_db_upload
49
+ remote_db_load
50
+ remote_cache_cleanup
51
+ remote_db_cleanup
52
+ end
@@ -0,0 +1,32 @@
1
+ configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
2
+
3
+ configuration.load do
4
+ namespace :passenger do
5
+ desc "Restart the web server"
6
+ task :restart, :roles => :app do
7
+ run "touch #{current_release}/tmp/restart.txt"
8
+ end
9
+
10
+ [:start, :stop].each do |t|
11
+ desc "#{t} task is a no-op with passenger"
12
+ task t, :roles => :app do ; end
13
+ end
14
+ end
15
+
16
+ namespace :deploy do
17
+ desc "Restart the web server"
18
+ task :restart do
19
+ passenger::restart
20
+ end
21
+
22
+ desc "Start the web server"
23
+ task :start do
24
+ passenger::start
25
+ end
26
+
27
+ desc "Stop the web server"
28
+ task :stop do
29
+ passenger::stop
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,108 @@
1
+ configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
2
+
3
+ configuration.load do
4
+ namespace :deploy do
5
+ after "deploy:setup" do
6
+ configs::copy_database_config
7
+ public_files::create_shared_assets
8
+ public_files::create_shared_galleries
9
+ public_files::create_shared_page_attachments
10
+ end
11
+ after "deploy:update_code" do
12
+ configs::link
13
+ public_files::link_assets
14
+ public_files::link_galleries
15
+ public_files::link_page_attachments
16
+ end
17
+ after "deploy:cold", "deploy:radiant:bootstrap"
18
+ after "deploy:migrate", "deploy:radiant:migrate:extensions"
19
+ after "deploy:symlink" do
20
+ run "mkdir -p #{latest_release}/cache"
21
+ end
22
+
23
+ desc "Overridden deploy:cold for Radiant."
24
+ task :cold do
25
+ update
26
+ radiant::bootstrap
27
+ #start
28
+ end
29
+ end
30
+
31
+ namespace :radiant do
32
+ desc "Radiant Bootstrap with empty template and default values."
33
+ task :bootstrap do
34
+ rake = fetch(:rake, "rake")
35
+ rails_env = fetch(:rails_env, "production")
36
+
37
+ run "cd #{current_release}; #{rake} RAILS_ENV=#{rails_env} ADMIN_NAME=Administrator ADMIN_USERNAME=admin ADMIN_PASSWORD=radiant DATABASE_TEMPLATE=empty.yml OVERWRITE=true db:bootstrap"
38
+ end
39
+
40
+ namespace :migrate do
41
+ desc "Runs migrations on extensions."
42
+ task :extensions do
43
+ rake = fetch(:rake, "rake")
44
+ rails_env = fetch(:rails_env, "production")
45
+ run "cd #{current_release}; #{rake} RAILS_ENV=#{rails_env} db:migrate:extensions"
46
+ end
47
+ end
48
+
49
+ namespace :content do
50
+ desc "rsync the local public content to the current radiant deployment"
51
+ task :push_local_public_to_current_public do
52
+ set :deploy_to_path, File.join(deploy_to,"current","public")
53
+ system "rsync -avz -e ssh public/ #{user}@#{ehost}:#{deploy_to_path}"
54
+ end
55
+
56
+ desc "fetch server production_db to local production_db"
57
+ task :fetch_server_prod_to_local_prod do
58
+ set :current_radiant, File.join(deploy_to,"current")
59
+ run "cd #{current_radiant}; rake "
60
+ end
61
+
62
+ desc "fetch assets"
63
+ task :fetch_assets do
64
+ set :deploy_to_path, File.join(deploy_to,"current","public","assets")
65
+ system "rsync -Lavz -e ssh #{user}@#{ehost}:#{deploy_to_path}/ public/assets "
66
+ end
67
+
68
+ desc "fetch gallery"
69
+ task :fetch_galleries do
70
+ set :deploy_to_path, File.join(deploy_to,"current","public","galleries")
71
+ system "rsync -Lavz -e ssh #{user}@#{ehost}:#{deploy_to_path}/ public/galleries "
72
+ end
73
+ end # eo content namespace
74
+
75
+ end # eo radiant namespace
76
+
77
+ namespace :public_files do
78
+ desc "Create shared assets dir"
79
+ task :create_shared_assets do
80
+ run "mkdir -p #{shared_path}/public/assets"
81
+ end
82
+
83
+ desc "Create shared page_attachments dir"
84
+ task :create_shared_page_attachments do
85
+ run "mkdir -p #{shared_path}/public/page_attachments"
86
+ end
87
+
88
+ desc "Create shared galleries dir"
89
+ task :create_shared_galleries do
90
+ run "mkdir -p #{shared_path}/public/galleries"
91
+ end
92
+
93
+ desc "Link public/assets to shared/public/assets"
94
+ task :link_assets do
95
+ run "ln -nfs #{shared_path}/public/assets #{release_path}/public/assets"
96
+ end
97
+
98
+ desc "Link public/page_attachments to shared/public/page_attachments"
99
+ task :link_page_attachments do
100
+ run "ln -nfs #{shared_path}/public/page_attachments #{release_path}/public/page_attachments"
101
+ end
102
+
103
+ desc "Link public/galleries to shared/public/galleries"
104
+ task :link_galleries do
105
+ run "ln -nfs #{shared_path}/public/galleries #{release_path}/public/galleries"
106
+ end
107
+ end # eo public_files namespace
108
+ end
@@ -0,0 +1 @@
1
+ gem 'capistrano', '>= 2.4.3' # load v2.4.3 or higher
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,50 @@
1
+ namespace :db do
2
+ desc "Dump the current database to a MySQL file"
3
+ task :database_dump do
4
+ load 'config/environment.rb'
5
+ abcs = ActiveRecord::Base.configurations
6
+ case abcs[RAILS_ENV]["adapter"]
7
+ when 'mysql'
8
+ ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
9
+ File.open("db/#{RAILS_ENV}_data.sql", "w+") do |f|
10
+ if abcs[RAILS_ENV]["password"].blank?
11
+ f << `mysqldump --skip-lock-tables -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} #{abcs[RAILS_ENV]["database"]}`
12
+ else
13
+ f << `mysqldump --skip-lock-tables -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} -p#{abcs[RAILS_ENV]["password"]} #{abcs[RAILS_ENV]["database"]}`
14
+ end
15
+ end
16
+ else
17
+ raise "Task not supported by '#{abcs[RAILS_ENV]['adapter']}'"
18
+ end
19
+ end
20
+
21
+ desc "Refreshes your local development environment to the current production database"
22
+ task :get_production_data_from_server do
23
+ `cap remote_db_runner`
24
+ `rake db:production_data_load --trace`
25
+ end
26
+
27
+ desc "Refreshes your remote production environment to the current development database"
28
+ task :put_development_data_to_server do
29
+ `rake RAILS_ENV=development db:database_dump --trace`
30
+ `cap local_db_runner`
31
+ end
32
+
33
+ desc "Loads the production data downloaded into db/production_data.sql into your local development database"
34
+ task :production_data_load do
35
+ load 'config/environment.rb'
36
+ abcs = ActiveRecord::Base.configurations
37
+ case abcs[RAILS_ENV]["adapter"]
38
+ when 'mysql'
39
+ ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
40
+ if abcs[RAILS_ENV]["password"].blank?
41
+ `mysql -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} #{abcs[RAILS_ENV]["database"]} < db/production_data.sql`
42
+ else
43
+ `mysql -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} -p#{abcs[RAILS_ENV]["password"]} #{abcs[RAILS_ENV]["database"]} < db/production_data.sql`
44
+ end
45
+ else
46
+ raise "Task not supported by '#{abcs[RAILS_ENV]['adapter']}'"
47
+ end
48
+ end
49
+
50
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'gorilla-capistrano-recipes'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGorillaCapistranoRecipes < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gorilla-capistrano-recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benny Degezelle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: This gem allows for a clean Capfile by setting up common capistrano stuff such as Git preferences, Radiant specifics, db dump helpers, passenger or lighty restart, ...
26
+ email: benny@gorilla-webdesign.be
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/gorilla-capistrano-recipes.rb
42
+ - lib/gorilla-capistrano-recipes/deploy.rb
43
+ - lib/gorilla-capistrano-recipes/lighttpd.rb
44
+ - lib/gorilla-capistrano-recipes/mysql.rb
45
+ - lib/gorilla-capistrano-recipes/passenger.rb
46
+ - lib/gorilla-capistrano-recipes/radiant.rb
47
+ - lib/tasks/db.rake
48
+ - test/helper.rb
49
+ - test/test_gorilla-capistrano-recipes.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/jomz/gorilla-capistrano-recipes
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Common capistrano recipes for Gorilla sites
78
+ test_files:
79
+ - test/helper.rb
80
+ - test/test_gorilla-capistrano-recipes.rb