capones_recipes 0.10.1 → 0.10.2

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
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'shoulda', '>= 0'
5
+ gem 'bundler', '~> 1.0'
6
+ gem 'jeweler', '~> 1.6.1'
7
+ gem 'rcov', '>= 0'
8
+ end
9
+
10
+ gem 'capistrano'
11
+ gem 'capistrano_colors'
12
+ gem 'cap-recipes'
13
+ gem 'capistrano-ext'
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ cap-recipes (0.3.36)
5
+ capistrano (2.8.0)
6
+ highline
7
+ net-scp (>= 1.0.0)
8
+ net-sftp (>= 2.0.0)
9
+ net-ssh (>= 2.0.14)
10
+ net-ssh-gateway (>= 1.1.0)
11
+ capistrano-ext (1.2.1)
12
+ capistrano (>= 1.0.0)
13
+ capistrano_colors (0.5.4)
14
+ git (1.2.5)
15
+ highline (1.6.2)
16
+ jeweler (1.6.4)
17
+ bundler (~> 1.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ net-scp (1.0.4)
21
+ net-ssh (>= 1.99.1)
22
+ net-sftp (2.0.5)
23
+ net-ssh (>= 2.0.9)
24
+ net-ssh (2.1.4)
25
+ net-ssh-gateway (1.1.0)
26
+ net-ssh (>= 1.99.1)
27
+ rake (0.9.2)
28
+ rcov (0.9.9)
29
+ shoulda (2.11.3)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.0)
36
+ cap-recipes
37
+ capistrano
38
+ capistrano-ext
39
+ capistrano_colors
40
+ jeweler (~> 1.6.1)
41
+ rcov
42
+ shoulda
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "capones_recipes"
18
+ gem.homepage = "http://github.com/raskhadafi/capones-recipes"
19
+ gem.license = "MIT"
20
+ gem.summary = "Some capistrano recipes for use."
21
+ gem.description = "A collection of useful capistrano recipes used by CyT GmbH and others."
22
+ gem.email = "roman.simecek@cyt.ch"
23
+ gem.authors = ["Roman Simecek", "Simon Hürlimann"]
24
+ # gem.files = ['lib/recipes/*', 'lib/*', 'Capfile', 'lib/cookbook/*']
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.10.2
@@ -0,0 +1,97 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capones_recipes}
8
+ s.version = "0.10.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roman Simecek", "Simon Hürlimann"]
12
+ s.date = %q{2011-08-17}
13
+ s.description = %q{A collection of useful capistrano recipes used by CyT GmbH and others.}
14
+ s.email = %q{roman.simecek@cyt.ch}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Capfile",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "capones_recipes.gemspec",
29
+ "config/deploy.rb",
30
+ "config/deploy/production.rb",
31
+ "config/deploy/staging.rb",
32
+ "lib/capones_recipes.rb",
33
+ "lib/cookbook/rails.rb",
34
+ "lib/cookbook/rails31.rb",
35
+ "lib/cookbook/wikisigns.rb",
36
+ "lib/recipes/database.rb",
37
+ "lib/recipes/database/mysql.rb",
38
+ "lib/recipes/database/sqlite.rb",
39
+ "lib/recipes/database/sync.rb",
40
+ "lib/recipes/katalog.rb",
41
+ "lib/recipes/katalog/import.rb",
42
+ "lib/recipes/katalog/katalog.rb",
43
+ "lib/recipes/kuhsaft.rb",
44
+ "lib/recipes/kuhsaft/setup.rb",
45
+ "lib/recipes/new_relic.rb",
46
+ "lib/recipes/new_relic/new_relic.rb",
47
+ "lib/recipes/rails.rb",
48
+ "lib/recipes/rails/bundler.rb",
49
+ "lib/recipes/rails/database_yml.rb",
50
+ "lib/recipes/rails/mod_rails.rb",
51
+ "lib/recipes/rails31.rb",
52
+ "lib/recipes/rails31/rails31.rb",
53
+ "lib/recipes/settings_logic.rb",
54
+ "lib/recipes/settings_logic/settings_logic.rb",
55
+ "lib/recipes/thinking_sphinx.rb",
56
+ "lib/recipes/thinking_sphinx/thinking_sphinx.rb"
57
+ ]
58
+ s.homepage = %q{http://github.com/raskhadafi/capones-recipes}
59
+ s.licenses = ["MIT"]
60
+ s.require_paths = ["lib"]
61
+ s.rubygems_version = %q{1.6.2}
62
+ s.summary = %q{Some capistrano recipes for use.}
63
+
64
+ if s.respond_to? :specification_version then
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
69
+ s.add_runtime_dependency(%q<capistrano_colors>, [">= 0"])
70
+ s.add_runtime_dependency(%q<cap-recipes>, [">= 0"])
71
+ s.add_runtime_dependency(%q<capistrano-ext>, [">= 0"])
72
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
74
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
75
+ s.add_development_dependency(%q<rcov>, [">= 0"])
76
+ else
77
+ s.add_dependency(%q<capistrano>, [">= 0"])
78
+ s.add_dependency(%q<capistrano_colors>, [">= 0"])
79
+ s.add_dependency(%q<cap-recipes>, [">= 0"])
80
+ s.add_dependency(%q<capistrano-ext>, [">= 0"])
81
+ s.add_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
84
+ s.add_dependency(%q<rcov>, [">= 0"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<capistrano>, [">= 0"])
88
+ s.add_dependency(%q<capistrano_colors>, [">= 0"])
89
+ s.add_dependency(%q<cap-recipes>, [">= 0"])
90
+ s.add_dependency(%q<capistrano-ext>, [">= 0"])
91
+ s.add_dependency(%q<shoulda>, [">= 0"])
92
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
93
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
94
+ s.add_dependency(%q<rcov>, [">= 0"])
95
+ end
96
+ end
97
+
data/config/deploy.rb ADDED
@@ -0,0 +1,16 @@
1
+ set :application, "set your application name here"
2
+ set :repository, "set your repository location here"
3
+ set :web_root, "/srv/cyt.ch/"
4
+
5
+ role :web, "your web-server here" # Your HTTP server, Apache/etc
6
+ role :app, "your app-server here" # This may be the same as your `Web` server
7
+ role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
8
+ role :db, "your slave db-server here"
9
+
10
+ # Configuration
11
+ set :scm, :git
12
+ ssh_options[:forward_agent] = true
13
+ set :use_sudo, false
14
+ set :deploy_via, :remote_cache
15
+ set :git_enable_submodules, 1
16
+ set :copy_exclude, [".git", "spec"]
@@ -0,0 +1,7 @@
1
+ set :rails_env, 'production'
2
+ set :branch, "stable"
3
+
4
+ set :deploy_to, "#{web_root}#{application}"
5
+ role :web, "web01.#{application}" # Your HTTP server, Apache/etc
6
+ role :app, "web01.#{application}" # This may be the same as your `Web` server
7
+ role :db, "web01.#{application}", :primary => true # This is where Rails migrations will run
@@ -0,0 +1,7 @@
1
+ set :rails_env, 'staging'
2
+ set :branch, "master"
3
+
4
+ set :deploy_to, "#{web_root}#{application}"
5
+ role :web, "test.#{application}" # Your HTTP server, Apache/etc
6
+ role :app, "test.#{application}" # This may be the same as your `Web` server
7
+ role :db, "test.#{application}", :primary => true # This is where Rails migrations will run
@@ -0,0 +1,93 @@
1
+ require 'capistrano/configuration'
2
+ # MySQL Backup/Restore tasks
3
+ #
4
+ # Based on code from:
5
+ # * http://snippets.aktagon.com/snippets/20-Capistrano-2-task-for-backing-up-your-MySQL-production-database-before-each-deployment
6
+ # * http://www.martin-probst.com/blog/2007/11/20/mysql-backup-restore-task-for-capistrano/
7
+ Capistrano::Configuration.instance.load do
8
+ namespace :mysql do
9
+ task :backup, :roles => :import do
10
+ backup_dir ||= "#{deploy_to}/backups"
11
+ run "mkdir -p #{backup_dir}"
12
+
13
+ filename = "#{backup_dir}/#{application}.dump.#{Time.now.strftime('%Y-%m-%d_%H-%M')}.sql.bz2"
14
+ text = capture "cat #{deploy_to}/current/config/database.yml"
15
+ yaml = YAML::load(text)
16
+
17
+ on_rollback { run "rm #{filename}" }
18
+
19
+ logger.info "Backing up to #{filename}..."
20
+ run "mysqldump -u #{yaml[rails_env]['username']} -p #{yaml[rails_env]['database']} -h #{yaml[rails_env]['host']}| bzip2 -c > #{filename}" do |ch, stream, out|
21
+ if out =~ /^Enter password:/
22
+ ch.send_data "#{yaml[rails_env]['password']}\n"
23
+ else
24
+ puts out
25
+ end
26
+ end
27
+
28
+ run "ln -nfs #{filename} #{backup_dir}/#{application}.latest"
29
+
30
+ logger.info "Backup successfull."
31
+ end
32
+
33
+ task :restore, :roles => :import do
34
+ backup_dir ||= "#{deploy_to}/backups"
35
+
36
+ filename = "#{backup_dir}/#{application}.latest"
37
+ text = capture "cat #{deploy_to}/current/config/database.yml"
38
+ yaml = YAML::load(text)
39
+
40
+ logger.info "Restoring from #{filename}..."
41
+ run "bzip2 -d < #{filename} |mysql -u #{yaml[rails_env]['username']} -p#{yaml[rails_env]['password']} -h #{yaml[rails_env]['host']} #{yaml[rails_env]['database']}" do |ch, stream, out|
42
+ puts out
43
+ end
44
+
45
+ logger.info "Restore successfull."
46
+ end
47
+
48
+ namespace :sync do
49
+ desc "Sync down the mysql db to local"
50
+ task :down, :roles => :app do
51
+ sync_dir ||= "#{deploy_to}/sync"
52
+ run "mkdir -p #{sync_dir}"
53
+
54
+ filename = "#{application}.dump.#{Time.now.strftime('%Y-%m-%d_%H-%M')}.sql.bz2"
55
+ text = capture "cat #{deploy_to}/current/config/database.yml"
56
+ yaml = YAML::load(text)
57
+ on_rollback { delete filename }
58
+
59
+ # Remote DB dump
60
+ run "mysqldump -u #{yaml[rails_env]['username']} -p #{yaml[rails_env]['database']} -h #{yaml[rails_env]['host']} | bzip2 -9 > #{sync_dir}/#{filename}" do |channel, stream, data|
61
+ if data =~ /^Enter password:/
62
+ channel.send_data "#{yaml[rails_env]['password']}\n"
63
+ else
64
+ puts data
65
+ end
66
+ end
67
+
68
+ # Download dump
69
+ download "#{sync_dir}/#{filename}", filename
70
+
71
+ run "rm #{sync_dir}/#{filename}"
72
+
73
+ # Local DB import
74
+ username, password, database = database_config('development')
75
+ system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
76
+ system "rake db:migrate"
77
+
78
+ logger.important "sync database from the stage '#{stage}' to local finished"
79
+ end
80
+
81
+ #
82
+ # Reads the database credentials from the local config/database.yml file
83
+ # +db+ the name of the environment to get the credentials for
84
+ # Returns username, password, database
85
+ #
86
+ def database_config(db)
87
+ database = YAML::load_file('config/database.yml')
88
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database']
89
+ end
90
+ end
91
+ end
92
+ end
93
+
@@ -0,0 +1,29 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", "sqlite:setup"
3
+ after "db:symlink", "sqlite:symlink"
4
+
5
+ namespace :sqlite do
6
+ desc "Setup Sqlite3 db"
7
+ task :setup do
8
+ run "mkdir -p #{shared_path}/db"
9
+ end
10
+
11
+ namespace :sync do
12
+ desc "Sync down the production sqlite database to local development sqlite"
13
+ task :down do
14
+ download "#{shared_path}/db/#{rails_env}.sqlite3", "db/development.sqlite3", :via => :scp
15
+ end
16
+
17
+ desc "Sync up the development sqlite database to production sqlite"
18
+ task :up do
19
+ run "mkdir -p #{shared_path}/db"
20
+ upload "db/development.sqlite3", "#{shared_path}/db/#{rails_env}.sqlite3", :via => :scp
21
+ end
22
+ end
23
+
24
+ desc "Make symlink for shared database"
25
+ task :symlink do
26
+ run "ln -nfs #{shared_path}/db/#{rails_env}.sqlite3 #{release_path}/db/#{rails_env}.sqlite3"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,320 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+
4
+ Capistrano::Configuration.instance.load do
5
+ #
6
+ # Capistrano sync.rb task for syncing databases and directories between the
7
+ # local development environment and different multi_stage environments. You
8
+ # cannot sync directly between two multi_stage environments, always use your
9
+ # local machine as loop way.
10
+ #
11
+ # Author: Michael Kessler aka netzpirat
12
+ # Gist: 111597
13
+ #
14
+ # Released under the MIT license.
15
+ # Kindly sponsored by Screen Concept, www.screenconcept.ch
16
+ #
17
+ namespace :sync do
18
+
19
+ after "deploy:setup", "sync:setup"
20
+
21
+ desc <<-DESC
22
+ Creates the sync dir in shared path. The sync directory is used to keep
23
+ backups of database dumps and archives from synced directories. This task will
24
+ be called on 'deploy:setup'
25
+ DESC
26
+ task :setup do
27
+ run "cd #{shared_path}; mkdir sync"
28
+ end
29
+
30
+ namespace :down do
31
+
32
+ desc <<-DESC
33
+ Syncs the database and declared directories from the selected multi_stage environment
34
+ to the local development environment. This task simply calls both the 'sync:down:db' and
35
+ 'sync:down:fs' tasks.
36
+ DESC
37
+ task :default do
38
+ db and fs
39
+ end
40
+
41
+ desc <<-DESC
42
+ Syncs database from the selected mutli_stage environement to the local develoment environment.
43
+ The database credentials will be read from your local config/database.yml file and a copy of the
44
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
45
+ declared in the sync_backups variable and defaults to 5.
46
+ DESC
47
+ task :db, :roles => :db, :only => { :primary => true } do
48
+ # Use production on non-multistage
49
+ set :stage, 'production' unless exists?(:stage)
50
+
51
+ filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
52
+ on_rollback { delete "#{shared_path}/sync/#{filename}" }
53
+
54
+ # Remote DB dump
55
+ username, password, database, host = remote_database_config(stage)
56
+ host_option = host ? "--host='#{host}'" : ""
57
+ run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
58
+ puts data
59
+ end
60
+ purge_old_backups "database"
61
+
62
+ # Download dump
63
+ download "#{shared_path}/sync/#{filename}", filename
64
+
65
+ # Local DB import
66
+ username, password, database, host = database_config('development')
67
+ system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
68
+
69
+ logger.important "sync database from the stage '#{stage}' to local finished"
70
+ end
71
+
72
+ desc <<-DESC
73
+ Sync declared directories from the selected multi_stage environment to the local development
74
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
75
+ variable. The path is relative to the rails root.
76
+ DESC
77
+ task :fs, :roles => :web, :once => true do
78
+ # Use production on non-multistage
79
+ set :stage, 'production' unless exists?(:stage)
80
+
81
+ server, port = host_and_port
82
+
83
+ Array(fetch(:sync_directories, [])).each do |syncdir|
84
+ unless File.directory? "#{syncdir}"
85
+ logger.info "create local '#{syncdir}' folder"
86
+ Dir.mkdir "#{syncdir}"
87
+ end
88
+ logger.info "sync #{syncdir} from #{server}:#{port} to local"
89
+ destination, base = Pathname.new(syncdir).split
90
+ system "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{current_path}/#{syncdir} #{destination.to_s}"
91
+ end
92
+
93
+ logger.important "sync filesystem from the stage '#{stage}' to local finished"
94
+ end
95
+
96
+ namespace :kuhsaft do
97
+
98
+ desc <<-DESC
99
+ Syncs the database and declared directories from the selected multi_stage environment
100
+ to the local development environment. This task simply calls both the 'sync:down:kuhsaft:db' and
101
+ 'sync:down:kuhsaft:fs' tasks.
102
+ DESC
103
+ task :default do
104
+ db
105
+ end
106
+
107
+ desc <<-DESC
108
+ Syncs database from the selected mutli_stage environement to the local develoment environment.
109
+ The database credentials will be read from your local config/database.yml file and a copy of the
110
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
111
+ declared in the sync_backups variable and defaults to 5.
112
+ DESC
113
+ task :db, :roles => :db, :only => { :primary => true } do
114
+ # Use production on non-multistage
115
+ set :stage, 'production' unless exists?(:stage)
116
+
117
+ filename = "database.kuhsaft.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
118
+ on_rollback { delete "#{shared_path}/sync/#{filename}" }
119
+
120
+ # Remote DB dump
121
+ username, password, database, host = remote_database_config(stage)
122
+ host_option = host ? "--host='#{host}'" : ""
123
+ run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} pages localized_pages contents assets tags taggings | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
124
+ puts data
125
+ end
126
+ purge_old_backups "database"
127
+
128
+ # Download dump
129
+ download "#{shared_path}/sync/#{filename}", filename
130
+
131
+ # Local DB import
132
+ username, password, database, host = database_config('development')
133
+ system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
134
+
135
+ logger.important "sync database from the stage '#{stage}' to local finished"
136
+ end
137
+ end
138
+ end
139
+
140
+ namespace :up do
141
+
142
+ desc <<-DESC
143
+ Syncs the database and declared directories from the local development environment
144
+ to the selected multi_stage environment. This task simply calls both the 'sync:up:db' and
145
+ 'sync:up:fs' tasks.
146
+ DESC
147
+ task :default do
148
+ db and fs
149
+ end
150
+
151
+ desc <<-DESC
152
+ Syncs database from the local develoment environment to the selected mutli_stage environement.
153
+ The database credentials will be read from your local config/database.yml file and a copy of the
154
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
155
+ declared in the sync_backups variable and defaults to 5.
156
+ DESC
157
+ task :db, :roles => :db, :only => { :primary => true } do
158
+ # Use production on non-multistage
159
+ set :stage, 'production' unless exists?(:stage)
160
+
161
+ filename = "database.all.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
162
+
163
+ on_rollback do
164
+ delete "#{shared_path}/sync/#{filename}"
165
+ system "rm -f #{filename}"
166
+ end
167
+
168
+ # Make a backup before importing
169
+ username, password, database, host = remote_database_config(stage)
170
+ host_option = host ? "--host='#{host}'" : ""
171
+ run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
172
+ puts data
173
+ end
174
+
175
+ # Local DB export
176
+ filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
177
+ username, password, database, host = database_config('development')
178
+ host_option = host ? "--host='#{host}'" : ""
179
+ system "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}"
180
+ upload filename, "#{shared_path}/sync/#{filename}"
181
+ system "rm -f #{filename}"
182
+
183
+ # Remote DB import
184
+ username, password, database, host = remote_database_config(stage)
185
+ host_option = host ? "--host='#{host}'" : ""
186
+ run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}; rm -f #{shared_path}/sync/#{filename}"
187
+ purge_old_backups "database.all"
188
+
189
+ logger.important "sync database from local to the stage '#{stage}' finished"
190
+ end
191
+
192
+ desc <<-DESC
193
+ Sync declared directories from the local development environement to the selected multi_stage
194
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
195
+ variable. The path is relative to the rails root.
196
+ DESC
197
+ task :fs, :roles => :web, :once => true do
198
+ # Use production on non-multistage
199
+ set :stage, 'production' unless exists?(:stage)
200
+
201
+ server, port = host_and_port
202
+ Array(fetch(:sync_directories, [])).each do |syncdir|
203
+ destination, base = Pathname.new(syncdir).split
204
+ if File.directory? "#{syncdir}"
205
+ # Make a backup
206
+ logger.info "backup #{syncdir}"
207
+ run "tar cjf #{shared_path}/sync/#{base}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.tar.bz2 #{current_path}/#{syncdir}"
208
+ purge_old_backups "#{base}"
209
+ else
210
+ logger.info "Create '#{syncdir}' directory"
211
+ run "mkdir #{current_path}/#{syncdir}"
212
+ end
213
+
214
+ # Sync directory up
215
+ logger.info "sync #{syncdir} to #{server}:#{port} from local"
216
+ system "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{current_path}/#{destination.to_s}"
217
+ end
218
+ logger.important "sync filesystem from local to the stage '#{stage}' finished"
219
+ end
220
+
221
+ namespace :kuhsaft do
222
+
223
+ desc <<-DESC
224
+ Syncs the database and declared directories from the local development environment
225
+ to the selected multi_stage environment. This task simply calls both the 'sync:up:kuhsaft:db' task.
226
+ DESC
227
+ task :default do
228
+ db
229
+ end
230
+
231
+ desc <<-DESC
232
+ Syncs database from the local develoment environment to the selected mutli_stage environement.
233
+ The database credentials will be read from your local config/database.yml file and a copy of the
234
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
235
+ declared in the sync_backups variable and defaults to 5.
236
+ DESC
237
+ task :db, :roles => :db, :only => { :primary => true } do
238
+ # Use production on non-multistage
239
+ set :stage, 'production' unless exists?(:stage)
240
+
241
+ filename = "database.kuhsaft.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
242
+
243
+ on_rollback do
244
+ delete "#{shared_path}/sync/#{filename}"
245
+ system "rm -f #{filename}"
246
+ end
247
+
248
+ # Make a backup before importing
249
+ username, password, database, host = remote_database_config(stage)
250
+ host_option = host ? "--host='#{host}'" : ""
251
+ run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} pages localized_pages contents assets tags taggings | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
252
+ puts data
253
+ end
254
+
255
+ # Local DB export
256
+ filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
257
+ username, password, database, host = database_config('development')
258
+ host_option = host ? "--host='#{host}'" : ""
259
+ system "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}"
260
+ upload filename, "#{shared_path}/sync/#{filename}"
261
+ system "rm -f #{filename}"
262
+
263
+ # Remote DB import
264
+ username, password, database, host = remote_database_config(stage)
265
+ host_option = host ? "--host='#{host}'" : ""
266
+ run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}; rm -f #{shared_path}/sync/#{filename}"
267
+ purge_old_backups "database.kuhsaft"
268
+
269
+ logger.important "sync database from local to the stage '#{stage}' finished"
270
+ end
271
+ end
272
+
273
+ end
274
+
275
+ #
276
+ # Reads the database credentials from the local config/database.yml file
277
+ # +db+ the name of the environment to get the credentials for
278
+ # Returns username, password, database
279
+ #
280
+ def database_config(db)
281
+ database = YAML::load_file('config/database.yml')
282
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'], database["#{db}"]['host']
283
+ end
284
+
285
+ #
286
+ # Reads the database credentials from the remote config/database.yml file
287
+ # +db+ the name of the environment to get the credentials for
288
+ # Returns username, password, database
289
+ #
290
+ def remote_database_config(db)
291
+ env = rails_env || db
292
+ config = capture "cat #{deploy_to}/current/config/database.yml"
293
+ database = YAML::load(config)
294
+ return database["#{env}"]['username'], database["#{env}"]['password'], database["#{env}"]['database'], database["#{env}"]['host']
295
+ end
296
+
297
+ #
298
+ # Returns the actual host name to sync and port
299
+ #
300
+ def host_and_port
301
+ return roles[:web].servers.first.host, ssh_options[:port] || roles[:web].servers.first.port || 22
302
+ end
303
+
304
+ #
305
+ # Purge old backups within the shared sync directory
306
+ #
307
+ def purge_old_backups(base)
308
+ count = fetch(:sync_backups, 5).to_i
309
+ backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse
310
+ if count >= backup_files.length
311
+ logger.important "no old backups to clean up"
312
+ else
313
+ logger.info "keeping #{count} of #{backup_files.length} sync backups"
314
+ delete_backups = (backup_files - backup_files.last(count)).join(" ")
315
+ try_sudo "rm -rf #{delete_backups}"
316
+ end
317
+ end
318
+
319
+ end
320
+ end
@@ -0,0 +1,62 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", "import:setup"
3
+ after "deploy:update_code", "import:symlink"
4
+
5
+ namespace :import do
6
+ desc "Create data directory"
7
+ task :setup, :roles => :import do
8
+ run "mkdir -p #{shared_path}/data"
9
+ end
10
+
11
+ desc "Make symlink for data"
12
+ task :symlink, :roles => :import do
13
+ run "ln -nfs #{shared_path}/data #{release_path}/data"
14
+ end
15
+
16
+ desc "Upload XLS file"
17
+ task :push, :roles => :import do
18
+ upload "data/Dossier-Katalog.xls", "#{shared_path}/data/dossiers.xls"
19
+
20
+ run "xls2csv -d utf-8 -c';' #{shared_path}/data/dossiers.xls > #{shared_path}/data/dossiers.csv"
21
+ end
22
+
23
+ desc "Clone current environment database as import database."
24
+ task :seed_import_db, :roles => :import do
25
+ old_rails_env = rails_env
26
+ mysql.backup
27
+
28
+ set :rails_env, 'import'
29
+ mysql.restore
30
+
31
+ set :rails_env, old_rails_env
32
+ end
33
+
34
+ desc "Clone import database to current environment."
35
+ task :push_import_db, :roles => :import do
36
+ old_rails_env = rails_env
37
+ set :rails_env, 'import'
38
+ mysql.backup
39
+
40
+ set :rails_env, old_rails_env
41
+ mysql.restore
42
+ end
43
+
44
+ desc "Import CSV file."
45
+ task :import_csv, :roles => :import do
46
+ old_rails_env = rails_env
47
+ set :rails_env, 'import'
48
+
49
+ stream "cd #{deploy_to}/current && RAILS_ENV=#{rails_env} /usr/bin/env bundle exec rails runner 'Dossier.import_from_csv(\"data/dossiers.csv\")'"
50
+ set :rails_env, old_rails_env
51
+ end
52
+
53
+ desc "Do a full import."
54
+ task :default do
55
+ push
56
+ seed_import_db
57
+ import_csv
58
+ push_import_db
59
+ thinking_sphinx.rebuild
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :katalog do
3
+ desc "Create sphinx wordform and exception lists."
4
+ task :export_sphinx_lists, :roles => :app do
5
+ logger.info "Create sphinx wordform and exception lists."
6
+ run "cd #{deploy_to}/current && RAILS_ENV=#{rails_env} /usr/bin/env bundle exec rails runner 'SphinxAdminWordForm.send(:export_file); SphinxAdminException.send(:export_file)'"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", "kuhsaft:setup"
3
+ after "deploy:update_code", "kuhsaft:symlink"
4
+
5
+ namespace :kuhsaft do
6
+ desc "Create uploads directory in capistrano shared path"
7
+ task :setup do
8
+ run "mkdir -p #{shared_path}/uploads"
9
+ end
10
+
11
+ desc "Make symlink for shared uploads"
12
+ task :symlink do
13
+ run "ln -nfs #{shared_path}/uploads #{release_path}/uploads"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", :new_relic
3
+ after "deploy:update_code", "new_relic:symlink"
4
+
5
+ namespace :new_relic do
6
+ desc "Create application yaml in capistrano shared path"
7
+ task :default do
8
+ run "mkdir -p #{shared_path}/config"
9
+ upload "config/newrelic.yml.example", "#{shared_path}/config/newrelic.yml", :via => :scp
10
+ end
11
+
12
+ desc "Make symlink for shared application yaml"
13
+ task :symlink do
14
+ run "ln -nfs #{shared_path}/config/newrelic.yml #{release_path}/config/newrelic.yml"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # Bundle install
3
+ require "bundler/capistrano"
4
+ after "bundle:install", "deploy:migrate"
5
+ end
@@ -0,0 +1,27 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", :db
3
+ before "deploy:migrate", "db:symlink"
4
+
5
+ namespace :db do
6
+ desc "Create database yaml in capistrano shared path"
7
+ task :default do
8
+ run "mkdir -p #{shared_path}/config"
9
+ upload "config/database.yml.example", "#{shared_path}/config/database.yml", :via => :scp
10
+ end
11
+
12
+ desc "Make symlink for shared database yaml"
13
+ task :symlink do
14
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
15
+ end
16
+
17
+ task :rake, :roles => :app do
18
+ run("cd #{deploy_to}/current && /usr/bin/env bundle exec rake #{rake_task} RAILS_ENV=#{rails_env}")
19
+ end
20
+
21
+ desc "Setup database"
22
+ task :setup, :roles => :app do
23
+ set :rake_task, 'db:setup'
24
+ rake
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :webistrano do
3
+ namespace :mod_rails do
4
+ desc "start mod_rails & Apache"
5
+ task :start, :roles => :app, :except => { :no_release => true } do
6
+ as = fetch(:runner, "app")
7
+ invoke_command "#{apache_init_script} start", :via => run_method, :as => as
8
+ end
9
+
10
+ desc "stop mod_rails & Apache"
11
+ task :stop, :roles => :app, :except => { :no_release => true } do
12
+ as = fetch(:runner, "app")
13
+ invoke_command "#{apache_init_script} stop", :via => run_method, :as => as
14
+ end
15
+
16
+ desc "restart mod_rails"
17
+ task :restart, :roles => :app, :except => { :no_release => true } do
18
+ as = fetch(:runner, "app")
19
+ restart_file = fetch(:mod_rails_restart_file, "#{deploy_to}/current/tmp/restart.txt")
20
+ invoke_command "touch #{restart_file}", :via => run_method, :as => as
21
+ end
22
+ end
23
+ end
24
+
25
+ namespace :deploy do
26
+ task :restart, :roles => :app, :except => { :no_release => true } do
27
+ webistrano.mod_rails.restart
28
+ end
29
+
30
+ task :start, :roles => :app, :except => { :no_release => true } do
31
+ webistrano.mod_rails.start
32
+ end
33
+
34
+ task :stop, :roles => :app, :except => { :no_release => true } do
35
+ webistrano.mod_rails.stop
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # Compile the assets in Rails 3.1
3
+ after 'deploy:migrate' do
4
+ run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ Capistrano::Configuration.instance.load do
2
+ before "deploy:setup", :settings_logic
3
+ before "db:symlink", "settings_logic:symlink"
4
+
5
+ namespace :settings_logic do
6
+ desc "Create application yaml in capistrano shared path"
7
+ task :default do
8
+ run "mkdir -p #{shared_path}/config"
9
+ upload "config/application.yml.example", "#{shared_path}/config/application.yml", :via => :scp
10
+ end
11
+
12
+ desc "Make symlink for shared application yaml"
13
+ task :symlink do
14
+ run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # Thinking Sphinx for Capistrano
2
+ require 'thinking_sphinx/deploy/capistrano'
3
+
4
+ Capistrano::Configuration.instance.load do
5
+ after "deploy:setup", "thinking_sphinx:setup"
6
+
7
+ after "deploy:migrate" do
8
+ thinking_sphinx.symlink
9
+ thinking_sphinx.rebuild
10
+ end
11
+
12
+ namespace :thinking_sphinx do
13
+ desc "Prepare for sphinx config"
14
+ task :setup, :roles => :app do
15
+ run "mkdir -p #{shared_path}/config/sphinx"
16
+ run "mkdir -p #{shared_path}/db/sphinx"
17
+ end
18
+
19
+ desc "Make symlink for sphinx configs and data"
20
+ task :symlink, :roles => :app do
21
+ run "ln -nfs #{shared_path}/config/sphinx #{release_path}/config/sphinx"
22
+ run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: capones_recipes
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.10.1
5
+ version: 0.10.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Roman Simecek
@@ -112,21 +112,43 @@ extra_rdoc_files:
112
112
  - LICENSE.txt
113
113
  - README.rdoc
114
114
  files:
115
+ - .document
115
116
  - Capfile
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - LICENSE.txt
120
+ - README.rdoc
121
+ - Rakefile
122
+ - VERSION
123
+ - capones_recipes.gemspec
124
+ - config/deploy.rb
125
+ - config/deploy/production.rb
126
+ - config/deploy/staging.rb
116
127
  - lib/capones_recipes.rb
117
128
  - lib/cookbook/rails.rb
118
129
  - lib/cookbook/rails31.rb
119
130
  - lib/cookbook/wikisigns.rb
120
131
  - lib/recipes/database.rb
132
+ - lib/recipes/database/mysql.rb
133
+ - lib/recipes/database/sqlite.rb
134
+ - lib/recipes/database/sync.rb
121
135
  - lib/recipes/katalog.rb
136
+ - lib/recipes/katalog/import.rb
137
+ - lib/recipes/katalog/katalog.rb
122
138
  - lib/recipes/kuhsaft.rb
139
+ - lib/recipes/kuhsaft/setup.rb
123
140
  - lib/recipes/new_relic.rb
141
+ - lib/recipes/new_relic/new_relic.rb
124
142
  - lib/recipes/rails.rb
143
+ - lib/recipes/rails/bundler.rb
144
+ - lib/recipes/rails/database_yml.rb
145
+ - lib/recipes/rails/mod_rails.rb
125
146
  - lib/recipes/rails31.rb
147
+ - lib/recipes/rails31/rails31.rb
126
148
  - lib/recipes/settings_logic.rb
149
+ - lib/recipes/settings_logic/settings_logic.rb
127
150
  - lib/recipes/thinking_sphinx.rb
128
- - LICENSE.txt
129
- - README.rdoc
151
+ - lib/recipes/thinking_sphinx/thinking_sphinx.rb
130
152
  has_rdoc: true
131
153
  homepage: http://github.com/raskhadafi/capones-recipes
132
154
  licenses:
@@ -141,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
163
  requirements:
142
164
  - - ">="
143
165
  - !ruby/object:Gem::Version
144
- hash: 3260131765584338043
166
+ hash: -2388807948387241719
145
167
  segments:
146
168
  - 0
147
169
  version: "0"