nomagic_capistrano_recipes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ *.swo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nomagic_capistrano_recipes.gemspec
4
+ gemspec
@@ -0,0 +1,4 @@
1
+ nomagic_capistrano_recipes
2
+ ==========================
3
+
4
+ My recipes for capistrano
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,149 @@
1
+ require "nomagic_capistrano_recipes/version"
2
+
3
+ module NomagicCapistranoRecipes
4
+ Capistrano::Configuration.instance.load do
5
+ set :enable_local_db_export, false
6
+ set :enable_local_asset_export, false
7
+
8
+ namespace :import do
9
+ desc "Dump remote database and import to local"
10
+ task :remote_database do
11
+ puts "-----------------------------------------------------------------------------------------"
12
+ puts "Importing database from #{domain} to local machine"
13
+ puts "-----------------------------------------------------------------------------------------"
14
+
15
+ get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
16
+
17
+ remote_settings = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
18
+ local_settings = YAML::load_file("config/database.yml")["development"]
19
+
20
+ # Dump on remote
21
+ puts "-----------------------------------------------------------------------------------------"
22
+ puts "Dumping database on #{domain}"
23
+ puts "-----------------------------------------------------------------------------------------"
24
+ run "mysqldump -u#{remote_settings["username"]} #{"-p#{remote_settings["password"]}" if remote_settings["password"]} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} > #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
25
+
26
+ # Rsync to local
27
+ puts "-----------------------------------------------------------------------------------------"
28
+ puts "Rsyncing database from #{domain} to local"
29
+ puts "-----------------------------------------------------------------------------------------"
30
+ run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
31
+
32
+ # Update database on local
33
+ puts "-----------------------------------------------------------------------------------------"
34
+ puts "Updating database on local"
35
+ puts "-----------------------------------------------------------------------------------------"
36
+ run_locally("mysql -u#{local_settings["username"]} #{"-p#{local_settings["password"]}" if local_settings["password"]} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings["database"]} < tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
37
+
38
+ # Remove temporary files
39
+ puts "-----------------------------------------------------------------------------------------"
40
+ puts "Removing temporary files"
41
+ puts "-----------------------------------------------------------------------------------------"
42
+ run "rm #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
43
+ run_locally("rm tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
44
+ run_locally("rm tmp/#{stage}-database.yml")
45
+ end
46
+
47
+ desc "Download remote (system) assets to local machine"
48
+ task :remote_assets do
49
+ puts "-----------------------------------------------------------------------------------------"
50
+ puts "Importing assets from #{domain} to local machine"
51
+ puts "-----------------------------------------------------------------------------------------"
52
+ system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/system/ public/system/"
53
+ end
54
+ end
55
+
56
+ namespace :export do
57
+ desc "Dump local database and export to remote"
58
+ task :local_database do
59
+ if enable_local_db_export
60
+
61
+ # Confirm that we really want to override the database
62
+ puts "-----------------------------------------------------------------------------------------"
63
+ puts "Do you really want to override #{stage} database with your local version?"
64
+ puts "-----------------------------------------------------------------------------------------"
65
+ set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
66
+ abort "Export to #{stage} was stopped" unless continue == 'y'
67
+
68
+ # If stage is production - double check that we want to do this
69
+ if "#{stage}" == 'production'
70
+ puts "-----------------------------------------------------------------------------------------"
71
+ puts "WARNING: You are overriding the PRODUCTION database, are you COMPLETELY sure?"
72
+ puts "-----------------------------------------------------------------------------------------"
73
+ set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
74
+ abort "Export to production was stopped" unless continue == 'y'
75
+ end
76
+
77
+ puts "-----------------------------------------------------------------------------------------"
78
+ puts "Exporting database from local machine to #{domain}"
79
+ puts "-----------------------------------------------------------------------------------------"
80
+
81
+ get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
82
+
83
+ remote_settings = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
84
+ local_settings = YAML::load_file("config/database.yml")["development"]
85
+
86
+ # Dump local database
87
+ puts "-----------------------------------------------------------------------------------------"
88
+ puts "Dumping local database"
89
+ puts "-----------------------------------------------------------------------------------------"
90
+ run_locally("mysqldump -u#{local_settings['username']} #{"-p#{local_settings['password']}" if local_settings['password']} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings['database']} > tmp/local-#{local_settings['database']}-dump.sql")
91
+
92
+ # Rsync to remote
93
+ puts "-----------------------------------------------------------------------------------------"
94
+ puts "Rsyncing database from local to #{domain}"
95
+ puts "-----------------------------------------------------------------------------------------"
96
+ run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress tmp/local-#{local_settings["database"]}-dump.sql #{user}@#{domain}:#{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql")
97
+
98
+ # Update database on remote
99
+ puts "-----------------------------------------------------------------------------------------"
100
+ puts "Updating database on #{domain}"
101
+ puts "-----------------------------------------------------------------------------------------"
102
+ run "mysql -u#{remote_settings['username']} #{"-p#{remote_settings['password']}" if remote_settings['password']} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} < #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
103
+
104
+ # Remove temporary files
105
+ puts "-----------------------------------------------------------------------------------------"
106
+ puts "Removing temporary files"
107
+ puts "-----------------------------------------------------------------------------------------"
108
+ run_locally("rm tmp/local-#{local_settings["database"]}-dump.sql")
109
+ run_locally("rm tmp/#{stage}-database.yml")
110
+ run "rm #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
111
+ else
112
+ puts "-----------------------------------------------------------------------------------------"
113
+ puts "NOTE: exporting your local database to #{stage} is disabled"
114
+ puts "-----------------------------------------------------------------------------------------"
115
+ end
116
+ end
117
+
118
+ desc "Downloads remote (system) assets to the local development machine"
119
+ task :local_assets do
120
+ if enable_local_asset_export
121
+ # Confirm that we really want to upload local assets
122
+ puts "-----------------------------------------------------------------------------------------"
123
+ puts "Do you really want to upload local assets to #{stage} at #{domain}?"
124
+ puts "-----------------------------------------------------------------------------------------"
125
+ set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
126
+ abort "Export to #{stage} was stopped" unless continue == 'y'
127
+
128
+ # If stage is production - double check that we want to do this
129
+ if "#{stage}" == 'production'
130
+ puts "-----------------------------------------------------------------------------------------"
131
+ puts "WARNING: You are overriding the PRODUCTION assets, are you COMPLETELY sure?"
132
+ puts "-----------------------------------------------------------------------------------------"
133
+ set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
134
+ abort "Export to production was stopped" unless continue == 'y'
135
+ end
136
+
137
+ puts "-----------------------------------------------------------------------------------------"
138
+ puts "Exporting assets from local machine to #{domain}"
139
+ puts "-----------------------------------------------------------------------------------------"
140
+ system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress public/system/ #{user}@#{domain}:#{shared_path}/system/"
141
+ else
142
+ puts "-----------------------------------------------------------------------------------------"
143
+ puts "NOTE: exporting your local assets to #{stage} is disabled"
144
+ puts "-----------------------------------------------------------------------------------------"
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,3 @@
1
+ module NomagicCapistranoRecipes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nomagic_capistrano_recipes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nomagic_capistrano_recipes"
7
+ s.version = NomagicCapistranoRecipes::VERSION
8
+ s.authors = ["Alexander Belozerov"]
9
+ s.email = ["belozerov.sasha@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "Useful capistrano recipes"
12
+ s.description = "Useful capistrano recipes"
13
+
14
+ s.rubyforge_project = "nomagic_capistrano_recipes"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nomagic_capistrano_recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Belozerov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Useful capistrano recipes
15
+ email:
16
+ - belozerov.sasha@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - lib/nomagic_capistrano_recipes.rb
26
+ - lib/nomagic_capistrano_recipes/version.rb
27
+ - nomagic_capistrano_recipes.gemspec
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: nomagic_capistrano_recipes
48
+ rubygems_version: 1.8.24
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Useful capistrano recipes
52
+ test_files: []