capistrano-shortcuts 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/lib/capistrano/shortcuts.rb +1 -1
- data/lib/capistrano/shortcuts/tasks/deploy_database.rake +111 -0
- data/lib/capistrano/shortcuts/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d6a4fd1a79734018fac7c509788b79de96b122
|
4
|
+
data.tar.gz: e99f5f9d66e655427e38e5068fc2851f935b728d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e37d55cd40c998122e5fbccd61c1d2f79e98b88065cab93d4c4770b52300d339cecd44a57ce91af93aaed466a333f242e24b00b4b9dbb1ffc4b6f5b74ea6b661
|
7
|
+
data.tar.gz: c5279826670b579516e87e2115cc88d19396c845a343b3af1bb9a5255f21207ebdc4d44c0ed67ed1871081674888dabad824ef2026c69e2603f861efefd30fbd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,18 @@ And include the tasks via your Capfile:
|
|
25
25
|
|
26
26
|
require 'capistrano/shortcuts'
|
27
27
|
|
28
|
+
|
29
|
+
## MySQL Database Tasks
|
30
|
+
|
31
|
+
Push or pull a copy of the database to or from the environment:
|
32
|
+
|
33
|
+
cap <environment> db:pull
|
34
|
+
cap <environment> db:push
|
35
|
+
|
36
|
+
Pull a copy of the production database to local machine, run migrations to update to development mode, then push the fresh and updated version to staging:
|
37
|
+
|
38
|
+
cap <environment> db:sync
|
39
|
+
|
28
40
|
## Config Files
|
29
41
|
|
30
42
|
Push all config files listed in the :linked_files variable to the specified environment:
|
data/lib/capistrano/shortcuts.rb
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
production_protected = true
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
|
5
|
+
db_config = YAML::load_file('config/database.yml')
|
6
|
+
local_rails_env = 'development'
|
7
|
+
dump_file = "capistrano-dump.sql"
|
8
|
+
|
9
|
+
task pull: [:dump_remote_db, :pull_db, :load_local_db]
|
10
|
+
task push: [:dump_local_db, :push_db, :load_remote_db]
|
11
|
+
|
12
|
+
task :dump_remote_db do
|
13
|
+
on roles(:db) do
|
14
|
+
dump_db(db_config[fetch(:rails_env)], dump_file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :pull_db do
|
19
|
+
on roles(:db) do
|
20
|
+
run_locally do
|
21
|
+
if db_config[fetch(:rails_env)]['host'].nil?
|
22
|
+
domain = fetch(:domain)
|
23
|
+
else
|
24
|
+
domain = db_config[fetch(:rails_env)]['host']
|
25
|
+
end
|
26
|
+
execute("scp -i #{fetch(:aws_key_pair)} #{fetch(:user)}@#{domain}:~/#{dump_file}.gz .")
|
27
|
+
end
|
28
|
+
execute("rm #{dump_file}.gz")
|
29
|
+
run_locally do
|
30
|
+
execute("gunzip -f #{dump_file}.gz")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
task :load_local_db do
|
36
|
+
run_locally do
|
37
|
+
load_db(db_config[local_rails_env], dump_file)
|
38
|
+
execute("rm #{dump_file}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :dump_local_db do
|
43
|
+
run_locally do
|
44
|
+
dump_db(db_config[local_rails_env], dump_file)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :push_db do
|
49
|
+
if production_protected and fetch(:rails_env) == 'production'
|
50
|
+
raise "Sorry, I refuse to push the local database to production."
|
51
|
+
end
|
52
|
+
run_locally do
|
53
|
+
if db_config[fetch(:rails_env)]['host'].nil?
|
54
|
+
domain = fetch(:domain)
|
55
|
+
else
|
56
|
+
domain = db_config[fetch(:rails_env)]['host']
|
57
|
+
end
|
58
|
+
|
59
|
+
execute("scp -i #{fetch(:aws_key_pair)} #{dump_file}.gz #{fetch(:user)}@#{domain}:~")
|
60
|
+
execute("rm #{dump_file}.gz")
|
61
|
+
end
|
62
|
+
on roles(:db) do
|
63
|
+
execute("gunzip -f #{dump_file}.gz")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
task :load_remote_db do
|
68
|
+
if production_protected and fetch(:rails_env) == 'production'
|
69
|
+
raise "Sorry, I won't load the remote database on production."
|
70
|
+
end
|
71
|
+
on roles(:db) do
|
72
|
+
load_db(db_config[fetch(:rails_env)], "~/#{dump_file}")
|
73
|
+
execute("rm #{dump_file}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def dump_db(config, output_file)
|
78
|
+
execute("MYSQL_PWD=#{config['password']} " +
|
79
|
+
"mysqldump -f " +
|
80
|
+
"-u #{config['username']} " +
|
81
|
+
"#{config['database']} " +
|
82
|
+
"-r #{output_file}")
|
83
|
+
execute("gzip -f #{output_file}")
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_db(config, input_file)
|
87
|
+
execute("MYSQL_PWD=#{config['password']} " +
|
88
|
+
"mysql " +
|
89
|
+
"-u #{config['username']} " +
|
90
|
+
"#{config['database']} " +
|
91
|
+
"< #{input_file}")
|
92
|
+
end
|
93
|
+
|
94
|
+
# task :backup do
|
95
|
+
# on roles(:db) do
|
96
|
+
# dump_file = "cap-backup-#{Time.now.to_i}.sql"
|
97
|
+
# execute("mysqldump " +
|
98
|
+
# "-u #{db_config[fetch(:rails_env)]['username']} " +
|
99
|
+
# "-h #{db_config[fetch(:rails_env)]['host']} " +
|
100
|
+
# "-p " +
|
101
|
+
# "#{db_config[fetch(:rails_env)]['database']} " +
|
102
|
+
# "> #{dump_file}") do |ch, _, out|
|
103
|
+
# if out =~ /^Enter password: /
|
104
|
+
# ch.send_data "#{db_config[fetch(:rails_env)]['password']}\n"
|
105
|
+
# else
|
106
|
+
# puts out
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-shortcuts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Gehman
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/capistrano/shortcuts.rb
|
58
58
|
- lib/capistrano/shortcuts/tasks/deploy_apache.rake
|
59
59
|
- lib/capistrano/shortcuts/tasks/deploy_config.rake
|
60
|
+
- lib/capistrano/shortcuts/tasks/deploy_database.rake
|
60
61
|
- lib/capistrano/shortcuts/tasks/deploy_memcache.rake
|
61
62
|
- lib/capistrano/shortcuts/tasks/deploy_web.rake
|
62
63
|
- lib/capistrano/shortcuts/version.rb
|