screcipes 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,32 @@
1
+ coverage
2
+ rdoc
3
+ pkg
4
+ test/tmp
5
+ test/version_tmp
6
+ tmp
7
+ pkg
8
+ *.gem
9
+ *.rbc
10
+ lib/bundler/man
11
+ spec/reports
12
+ .config
13
+ InstalledFiles
14
+ .bundle
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
20
+
21
+ .DS_Store?
22
+ Icon?
23
+
24
+ # Thumbnails
25
+ ._*
26
+
27
+ # Files that might appear on external disk
28
+ .Spotlight-V100
29
+ .Trashes
30
+
31
+ .*.sw[a-z]
32
+ *.un~
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
1
+ namespace :assets do
2
+ desc "Symlink assets"
3
+ task :symlink do
4
+ run "ln -s #{shared_path}/public/assets #{current_path}/public/assets"
5
+ end
6
+ end
7
+
8
+ after "deploy:symlink", "assets:symlink"
@@ -0,0 +1,16 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ _cset :scm, :git
4
+ _cset :spinner, false
5
+ _cset :git_enable_submodules, 1
6
+ _cset :branch, "master"
7
+ _cset :copy_exclude, ["**/.git"]
8
+
9
+ _cset :sync_backups, 1
10
+ _cset :keep_releases, 5
11
+
12
+ _cset :use_sudo, false
13
+ _cset :runner, 'root'
14
+ _cset :apache_init_script, "/etc/init.d/apache2"
15
+
16
+ end
@@ -0,0 +1,79 @@
1
+ Capistrano::Configuration.instance.load do
2
+ set(:latest_release) { fetch(:current_path) }
3
+ set(:release_path) { fetch(:current_path) }
4
+ set(:current_release) { fetch(:current_path) }
5
+
6
+ set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
7
+ set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
8
+ set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
9
+
10
+ namespace :deploy do
11
+ desc "Deploy the MFer"
12
+ task :default do
13
+ update
14
+ restart
15
+ end
16
+
17
+ desc "Setup a GitHub-style deployment."
18
+ task :setup, :except => { :no_release => true } do
19
+ dirs = [deploy_to, shared_path]
20
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
21
+ run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
22
+ run "git clone #{repository} #{current_path}"
23
+ end
24
+
25
+ task :cold do
26
+ update
27
+ migrate
28
+ end
29
+
30
+ task :update do
31
+ transaction do
32
+ update_code
33
+ end
34
+ end
35
+
36
+ desc "Update the deployed code."
37
+ task :update_code, :except => { :no_release => true } do
38
+ run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
39
+ finalize_update
40
+ end
41
+
42
+ desc "Update the database (overwritten to avoid symlink)"
43
+ task :migrations do
44
+ transaction do
45
+ update_code
46
+ end
47
+ migrate
48
+ restart
49
+ end
50
+
51
+ desc "Restart passenger with restart.txt"
52
+ task :restart, :except => { :no_release => true } do
53
+ run "touch #{current_path}/tmp/restart.txt"
54
+ end
55
+
56
+ namespace :rollback do
57
+ desc "Moves the repo back to the previous version of HEAD"
58
+ task :repo, :except => { :no_release => true } do
59
+ set :branch, "HEAD@{1}"
60
+ deploy.default
61
+ end
62
+
63
+ desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
64
+ task :cleanup, :except => { :no_release => true } do
65
+ run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
66
+ end
67
+
68
+ desc "Rolls back to the previously deployed version."
69
+ task :default do
70
+ rollback.repo
71
+ rollback.cleanup
72
+ end
73
+ end
74
+ end
75
+
76
+ def run_rake(cmd)
77
+ run "cd #{current_path}; #{rake} #{cmd}"
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :deploy do
3
+ desc "Send initial HTTP request to start Phusion Passenger application spawner"
4
+ task :kickstart, :roles => :web do
5
+ servers = find_servers_for_task(current_task)
6
+ servers.each do |server|
7
+ run_locally "wget http://#{server.host} -O - > /dev/null"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
2
+ require "rvm/capistrano"
@@ -0,0 +1,33 @@
1
+ Capistrano::Configuration.instance.load do
2
+ _cset :normal_symlinks, %w(
3
+ config/database.yml
4
+ )
5
+
6
+ _cset :weird_symlinks, {
7
+ }
8
+
9
+ namespace :symlinks do
10
+ desc "Make all the damn symlinks"
11
+ task :make, :roles => :app, :except => { :no_release => true } do
12
+ commands = normal_symlinks.map do |path|
13
+ "rm -rf #{release_path}/#{path} && \
14
+ ln -s #{shared_path}/#{path} #{release_path}/#{path}"
15
+ end
16
+
17
+ commands += weird_symlinks.map do |from, to|
18
+ "rm -rf #{release_path}/#{to} && \
19
+ ln -s #{shared_path}/#{from} #{release_path}/#{to}"
20
+ end
21
+
22
+ # needed for some of the symlinks
23
+ run "mkdir -p #{current_path}/tmp"
24
+
25
+ run <<-CMD
26
+ cd #{release_path} &&
27
+ #{commands.join(" && ")}
28
+ CMD
29
+ end
30
+ end
31
+
32
+ after "deploy:update_code", "symlinks:make"
33
+ end
@@ -0,0 +1,200 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+
4
+ #
5
+ # Capistrano sync.rb task for syncing databases and directories between the
6
+ # local development environment and different multi_stage environments. You
7
+ # cannot sync directly between two multi_stage environments, always use your
8
+ # local machine as loop way.
9
+ #
10
+ # Author: Michael Kessler aka netzpirat
11
+ # Gist: 111597
12
+ #
13
+ # Released under the MIT license.
14
+ # Kindly sponsored by Screen Concept, www.screenconcept.ch
15
+ #
16
+ namespace :sync do
17
+
18
+ after "deploy:setup", "sync:setup"
19
+
20
+ desc <<-DESC
21
+ Creates the sync dir in shared path. The sync directory is used to keep
22
+ backups of database dumps and archives from synced directories. This task will
23
+ be called on 'deploy:setup'
24
+ DESC
25
+ task :setup do
26
+ run "cd #{shared_path}; mkdir sync"
27
+ end
28
+
29
+ namespace :down do
30
+
31
+ desc <<-DESC
32
+ Syncs the database and declared directories from the selected multi_stage environment
33
+ to the local development environment. This task simply calls both the 'sync:down:db' and
34
+ 'sync:down:fs' tasks.
35
+ DESC
36
+ task :default do
37
+ db and fs
38
+ end
39
+
40
+ desc <<-DESC
41
+ Syncs database from the selected mutli_stage environement to the local develoment environment.
42
+ The database credentials will be read from your local config/database.yml file and a copy of the
43
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
44
+ declared in the sync_backups variable and defaults to 5.
45
+ DESC
46
+ task :db, :roles => :db, :only => { :primary => true } do
47
+
48
+ filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
49
+ on_rollback { delete "#{shared_path}/sync/#{filename}" }
50
+
51
+ # Remote DB dump
52
+ username, password, database = database_config(stage)
53
+ run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
54
+ puts data
55
+ end
56
+ purge_old_backups "database"
57
+
58
+ # Download dump
59
+ download "#{shared_path}/sync/#{filename}", filename
60
+
61
+ # Local DB import
62
+ username, password, database = database_config('development')
63
+ system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
64
+
65
+ logger.important "sync database from the stage '#{stage}' to local finished"
66
+ end
67
+
68
+ desc <<-DESC
69
+ Sync declared directories from the selected multi_stage environment to the local development
70
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
71
+ variable. The path is relative to the rails root.
72
+ DESC
73
+ task :fs, :roles => :web, :once => true do
74
+
75
+ server, port = host_and_port
76
+
77
+ Array(fetch(:sync_directories, [])).each do |syncdir|
78
+ unless File.directory? "#{syncdir}"
79
+ logger.info "create local '#{syncdir}' folder"
80
+ Dir.mkdir "#{syncdir}"
81
+ end
82
+ logger.info "sync #{syncdir} from #{server}:#{port} to local"
83
+ destination, base = Pathname.new(syncdir).split
84
+ system "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{shared_path}/#{syncdir} #{destination.to_s}"
85
+ end
86
+
87
+ logger.important "sync filesystem from the stage '#{stage}' to local finished"
88
+ end
89
+
90
+ end
91
+
92
+ namespace :up do
93
+
94
+ desc <<-DESC
95
+ Syncs the database and declared directories from the local development environment
96
+ to the selected multi_stage environment. This task simply calls both the 'sync:up:db' and
97
+ 'sync:up:fs' tasks.
98
+ DESC
99
+ task :default do
100
+ db and fs
101
+ end
102
+
103
+ desc <<-DESC
104
+ Syncs database from the local develoment environment to the selected mutli_stage environement.
105
+ The database credentials will be read from your local config/database.yml file and a copy of the
106
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
107
+ declared in the sync_backups variable and defaults to 5.
108
+ DESC
109
+ task :db, :roles => :db, :only => { :primary => true } do
110
+
111
+ filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
112
+
113
+ on_rollback do
114
+ delete "#{shared_path}/sync/#{filename}"
115
+ system "rm -f #{filename}"
116
+ end
117
+
118
+ # Make a backup before importing
119
+ username, password, database = database_config(stage)
120
+ run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
121
+ puts data
122
+ end
123
+
124
+ # Local DB export
125
+ filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
126
+ username, password, database = database_config('development')
127
+ system "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{filename}"
128
+ upload filename, "#{shared_path}/sync/#{filename}"
129
+ system "rm -f #{filename}"
130
+
131
+ # Remote DB import
132
+ username, password, database = database_config(stage)
133
+ run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{shared_path}/sync/#{filename}"
134
+ purge_old_backups "database"
135
+
136
+ logger.important "sync database from local to the stage '#{stage}' finished"
137
+ end
138
+
139
+ desc <<-DESC
140
+ Sync declared directories from the local development environement to the selected multi_stage
141
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
142
+ variable. The path is relative to the rails root.
143
+ DESC
144
+ task :fs, :roles => :web, :once => true do
145
+
146
+ server, port = host_and_port
147
+ Array(fetch(:sync_directories, [])).each do |syncdir|
148
+ destination, base = Pathname.new(syncdir).split
149
+ if File.directory? "#{syncdir}"
150
+ # Make a backup
151
+ logger.info "backup #{syncdir}"
152
+ run "tar cjf #{shared_path}/sync/#{base}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.tar.bz2 #{shared_path}/#{syncdir}"
153
+ purge_old_backups "#{base}"
154
+ else
155
+ logger.info "Create '#{syncdir}' directory"
156
+ run "mkdir #{current_path}/#{syncdir}"
157
+ end
158
+
159
+ # Sync directory up
160
+ logger.info "sync #{syncdir} to #{server}:#{port} from local"
161
+ system "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{shared_path}/#{destination.to_s}"
162
+ end
163
+ logger.important "sync filesystem from local to the stage '#{stage}' finished"
164
+ end
165
+
166
+ end
167
+
168
+ #
169
+ # Reads the database credentials from the local config/database.yml file
170
+ # +db+ the name of the environment to get the credentials for
171
+ # Returns username, password, database
172
+ #
173
+ def database_config(db)
174
+ database = YAML::load_file('config/database.yml')
175
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database']
176
+ end
177
+
178
+ #
179
+ # Returns the actual host name to sync and port
180
+ #
181
+ def host_and_port
182
+ return roles[:web].servers.first.host, ssh_options[:port] || roles[:web].servers.first.port || 22
183
+ end
184
+
185
+ #
186
+ # Purge old backups within the shared sync directory
187
+ #
188
+ def purge_old_backups(base)
189
+ count = fetch(:sync_backups, 5).to_i
190
+ backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse
191
+ if count >= backup_files.length
192
+ logger.important "no old backups to clean up"
193
+ else
194
+ logger.info "keeping #{count} of #{backup_files.length} sync backups"
195
+ delete_backups = (backup_files - backup_files.last(count)).join(" ")
196
+ try_sudo "rm -rf #{delete_backups}"
197
+ end
198
+ end
199
+
200
+ end
@@ -0,0 +1,7 @@
1
+ require 'screcipes/capistrano/deploy'
2
+ require 'screcipes/capistrano/rvm'
3
+ require 'screcipes/capistrano/assets'
4
+ require 'screcipes/capistrano/sync'
5
+ require 'screcipes/capistrano/kickstart'
6
+ require 'screcipes/capistrano/defaults'
7
+ require 'screcipes/capistrano/symlinks'
@@ -0,0 +1,3 @@
1
+ module Screcipes
2
+ VERSION = "0.0.1"
3
+ end
data/lib/screcipes.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Screcipes
2
+ # Your code goes here...
3
+ end
data/screcipes.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'screcipes/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "screcipes"
7
+ s.version = Screcipes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = []
10
+ s.email = []
11
+ s.homepage = "http://rubygems.org/gems/screcipes"
12
+ s.summary = "screcipes wraps common capistrano setup for screenconcept"
13
+ s.description = "screcipes wraps common capistrano setup for screenconcept"
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ s.rubyforge_project = "screcipes"
17
+
18
+ s.add_development_dependency "bundler", ">= 1.0.7"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
22
+ s.require_path = 'lib'
23
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: screcipes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors: []
13
+
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-06 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 7
34
+ version: 1.0.7
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: screcipes wraps common capistrano setup for screenconcept
38
+ email: []
39
+
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Rakefile
50
+ - lib/screcipes.rb
51
+ - lib/screcipes/capistrano.rb
52
+ - lib/screcipes/capistrano/assets.rb
53
+ - lib/screcipes/capistrano/defaults.rb
54
+ - lib/screcipes/capistrano/deploy.rb
55
+ - lib/screcipes/capistrano/kickstart.rb
56
+ - lib/screcipes/capistrano/rvm.rb
57
+ - lib/screcipes/capistrano/symlinks.rb
58
+ - lib/screcipes/capistrano/sync.rb
59
+ - lib/screcipes/version.rb
60
+ - screcipes.gemspec
61
+ has_rdoc: true
62
+ homepage: http://rubygems.org/gems/screcipes
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 23
85
+ segments:
86
+ - 1
87
+ - 3
88
+ - 6
89
+ version: 1.3.6
90
+ requirements: []
91
+
92
+ rubyforge_project: screcipes
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: screcipes wraps common capistrano setup for screenconcept
97
+ test_files: []
98
+