bard 0.7.8 → 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bard.gemspec +1 -1
- data/lib/bard/capistrano.rb +85 -83
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.9
|
data/bard.gemspec
CHANGED
data/lib/bard/capistrano.rb
CHANGED
@@ -1,105 +1,107 @@
|
|
1
|
-
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
role :staging, "staging@staging.botandrose.com"
|
2
3
|
|
3
|
-
namespace "data" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
namespace "data" do
|
5
|
+
namespace "pull" do
|
6
|
+
desc "pull data from production"
|
7
|
+
task :default, :roles => :production do
|
8
|
+
data_pull :production
|
9
|
+
end
|
10
|
+
task :staging, :roles => :staging do
|
11
|
+
data_pull :staging
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
desc "pull data from production"
|
15
|
+
task :yml, :roles => :production do
|
16
|
+
run "cd #{application} && rake db:data:dump && gzip -9f db/data.yml"
|
17
|
+
transfer :down, "#{application}/db/data.yml.gz", "db/data.yml.gz"
|
18
|
+
system "gunzip -f db/data.yml.gz"
|
19
|
+
system "rake db:data:load"
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
def data_pull(env)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
24
|
+
def data_pull(env)
|
25
|
+
config = YAML::load(File.open("config/database.yml"))
|
26
|
+
source = config[env.to_s]
|
27
|
+
target = config["development"]
|
28
|
+
run "cd #{application} && mysqldump -u#{source["username"]} #{"-p#{source["password"]}" if source["password"]} '#{source["database"]}' > db/data.sql && gzip -9f db/data.sql"
|
29
|
+
transfer :down, "#{application}/db/data.sql.gz", "db/data.sql.gz"
|
30
|
+
run "cd #{application} && rm db/data.sql.gz"
|
31
|
+
system "gunzip -f db/data.sql.gz"
|
32
|
+
system "echo 'DROP DATABASE `#{target["database"]}`; CREATE DATABASE `#{target["database"]}`;' | mysql -u#{target["username"]}"
|
33
|
+
system "mysql -u#{target["username"]} '#{target["database"]}' < db/data.sql"
|
34
|
+
# system "rm db/data.sql"
|
35
|
+
end
|
35
36
|
|
36
|
-
namespace "deploy" do
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
namespace "deploy" do
|
38
|
+
desc "push app from staging to production"
|
39
|
+
task :default, :roles => :production do
|
40
|
+
begin
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
if `curl -s -I http://integrity.botandrose.com/#{application}` !~ /\b404\b/
|
43
|
+
puts "Integrity: verifying build..."
|
44
|
+
system "curl -sX POST http://integrity.botandrose.com/#{application}/builds"
|
45
|
+
while true
|
46
|
+
response = `curl -s http://integrity.botandrose.com/#{application}`
|
47
|
+
break unless response =~ /div class='(building|pending)' id='last_build'/
|
48
|
+
sleep(1)
|
49
|
+
end
|
50
|
+
case response
|
51
|
+
when /div class='failed' id='last_build'/ then raise TestsFailedError
|
52
|
+
when /div class='success' id='last_build'/ then success "Integrity: success! deploying to production"
|
53
|
+
else raise "Unknown response from CI server:\n#{response}"
|
54
|
+
end
|
48
55
|
end
|
49
|
-
case response
|
50
|
-
when /div class='failed' id='last_build'/ then raise TestsFailedError
|
51
|
-
when /div class='success' id='last_build'/ then success "Integrity: success! deploying to production"
|
52
|
-
else raise "Unknown response from CI server:\n#{response}"
|
53
|
-
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
system "git push" if `git remote show origin` =~ /github\.com/
|
58
|
+
run "cd #{application} && git pull"
|
59
|
+
run "cd #{application} && rake gems:install" if File.exist?("Rakefile")
|
60
|
+
run "cd #{application} && script/runner 'Sass::Plugin.options[:always_update] = true; Sass::Plugin.update_stylesheets'" if File.exist?("public/stylesheets/sass") or File.exist?("app/sass")
|
61
|
+
run "cd #{application} && rake asset:packager:build_all" if File.exist?("vendor/plugins/asset_packager")
|
62
|
+
run "cd #{application} && git submodule init && git submodule update" if File.exist?(".gitmodules")
|
63
|
+
run "cd #{application} && rake db:migrate && rake restart" if File.exist?("Rakefile")
|
64
|
+
success "Deploy Succeeded"
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
rescue BardError => e
|
67
|
+
handle_error e
|
68
|
+
end
|
67
69
|
end
|
68
|
-
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
def readline(prompt)
|
72
|
+
STDOUT.print(prompt)
|
73
|
+
STDOUT.flush
|
74
|
+
STDIN.gets
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_error(error)
|
78
|
+
name = error.message.split('::').last.gsub(/([A-Z])/, " \\1").gsub(/^ /,'').gsub(/ Error/, '')
|
79
|
+
failure "!!! Deploy Error: #{name}"
|
80
|
+
end
|
74
81
|
end
|
75
|
-
|
82
|
+
|
83
|
+
## ERROR HANDLING
|
84
|
+
|
76
85
|
def handle_error(error)
|
77
86
|
name = error.message.split('::').last.gsub(/([A-Z])/, " \\1").gsub(/^ /,'').gsub(/ Error/, '')
|
78
87
|
failure "!!! Deploy Error: #{name}"
|
79
88
|
end
|
80
|
-
end
|
81
89
|
|
82
|
-
|
90
|
+
class BardError < Capistrano::Error; end
|
91
|
+
class TestsFailedError < BardError; end
|
92
|
+
class WorkingDirectoryDirtyError < BardError; end
|
93
|
+
class StagingWorkingDirectoryDirtyError < BardError; end
|
94
|
+
class NonFastForwardError < BardError; end
|
83
95
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class BardError < Capistrano::Error; end
|
90
|
-
class TestsFailedError < BardError; end
|
91
|
-
class WorkingDirectoryDirtyError < BardError; end
|
92
|
-
class StagingWorkingDirectoryDirtyError < BardError; end
|
93
|
-
class NonFastForwardError < BardError; end
|
96
|
+
def success(msg)
|
97
|
+
puts "#{GREEN}#{msg}#{DEFAULT}"
|
98
|
+
end
|
94
99
|
|
95
|
-
def
|
96
|
-
|
97
|
-
end
|
100
|
+
def failure(msg)
|
101
|
+
abort "#{RED}#{msg}#{DEFAULT}"
|
102
|
+
end
|
98
103
|
|
99
|
-
|
100
|
-
|
104
|
+
GREEN = "\033[1;32m"
|
105
|
+
RED = "\033[1;31m"
|
106
|
+
DEFAULT = "\033[0m"
|
101
107
|
end
|
102
|
-
|
103
|
-
GREEN = "\033[1;32m"
|
104
|
-
RED = "\033[1;31m"
|
105
|
-
DEFAULT = "\033[0m"
|