sumodev_deploy 0.2.8.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sumodev_deploy.rb +6 -178
- data/sumodev_deploy.gemspec +1 -1
- metadata +1 -1
data/lib/sumodev_deploy.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
require 'sumodev_deploy/tasks/db'
|
3
|
+
require 'sumodev_deploy/tasks/errbit'
|
4
|
+
require 'sumodev_deploy/tasks/files'
|
5
|
+
require 'sumodev_deploy/tasks/redirect'
|
2
6
|
|
3
|
-
configuration.load do
|
4
7
|
def _cset(name, *args, &block)
|
5
8
|
unless exists?(name)
|
6
9
|
set(name, *args, &block)
|
@@ -25,6 +28,7 @@ configuration.load do
|
|
25
28
|
_cset(:app_servers) { production_server || staging_server }
|
26
29
|
_cset(:web_servers) { production_server || staging_server }
|
27
30
|
_cset(:db_server) { production_server || staging_server }
|
31
|
+
_cset(:db_lockfile) { "#{shared_path}/db.lock" }
|
28
32
|
|
29
33
|
_cset(:user, 'sites')
|
30
34
|
_cset(:homedir) { "/home/#{user}/" }
|
@@ -43,182 +47,6 @@ configuration.load do
|
|
43
47
|
after 'deploy', 'deploy:cleanup', 'sumodev:errbit:after_deploy'
|
44
48
|
|
45
49
|
namespace :sumodev do
|
46
|
-
namespace :db do
|
47
|
-
def remote_db_name
|
48
|
-
production? && !fetch(:production_db, '').empty? ?
|
49
|
-
production_db :
|
50
|
-
db_name
|
51
|
-
end
|
52
|
-
|
53
|
-
def remote_db_options
|
54
|
-
{:db_host => 'host', :db_username => 'user', :db_password => 'password'}.inject('') do |options, (key, param)|
|
55
|
-
value = fetch(key, '')
|
56
|
-
options << "--#{param}=#{value} " unless value.empty?
|
57
|
-
options
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
desc "Create the database. Reads :db_name variable, or it is composed from client / project"
|
62
|
-
task :create, :roles => :db do
|
63
|
-
run "create_db #{db_name}"
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "Dump the remote database, and outputs the content so you can pipe it"
|
67
|
-
task :dump, :roles => :db do
|
68
|
-
run "mysqldump --set-charset #{db_name}" do |ch, stream, out|
|
69
|
-
if stream == :err
|
70
|
-
ch[:options][:logger].send(:important, out, "#{stream} :: #{ch[:server]}" )
|
71
|
-
else
|
72
|
-
print out
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
desc "Imports the database from the server into your local database"
|
78
|
-
task :get, :roles => :db do
|
79
|
-
run_locally %{mysqladmin create #{db_name}} rescue nil
|
80
|
-
|
81
|
-
mysql = IO.popen("mysql #{db_name}", 'r+')
|
82
|
-
run "mysqldump --set-charset #{remote_db_options} #{remote_db_name}" do |ch, stream, out|
|
83
|
-
if stream == :err
|
84
|
-
ch[:options][:logger].send(:important, out, "#{stream} :: #{ch[:server]}" )
|
85
|
-
else
|
86
|
-
mysql.write out
|
87
|
-
end
|
88
|
-
end
|
89
|
-
mysql.close_write
|
90
|
-
puts mysql.read
|
91
|
-
mysql.close
|
92
|
-
end
|
93
|
-
|
94
|
-
desc "Get database info"
|
95
|
-
task :info, :roles => :db do
|
96
|
-
run "info_db #{db_name}"
|
97
|
-
end
|
98
|
-
|
99
|
-
desc "Imports the database from your local server to the remote one"
|
100
|
-
task :put, :roles => :db, :only => {:primary => true} do
|
101
|
-
run "mysqldump --set-charset #{db_name} > #{current_path}/#{release_name}.sql" rescue nil
|
102
|
-
|
103
|
-
dump = StringIO.new(run_locally "mysqldump --set-charset #{db_name}")
|
104
|
-
dump_path = "#{shared_path}/db_upload.tmp.sql"
|
105
|
-
upload dump, dump_path
|
106
|
-
|
107
|
-
run %{
|
108
|
-
mysql #{remote_db_options} #{remote_db_name} < #{dump_path} &&
|
109
|
-
rm #{dump_path}
|
110
|
-
}
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
namespace :errbit do
|
115
|
-
task :after_deploy, :rolse => :app do
|
116
|
-
update_api_key
|
117
|
-
notify
|
118
|
-
end
|
119
|
-
desc "Updates the Errbit API key"
|
120
|
-
task :update_api_key, :roles => :app do
|
121
|
-
next if fetch(:production_errbit_api_key, "").empty?
|
122
|
-
run "if [ -f #{shared_path}/config/library/globals.php ]; then sed -i \"s/define('ERRBIT_API_KEY', '.*');/define('ERRBIT_API_KEY', '#{production_errbit_api_key}');/\" #{shared_path}/config/library/globals.php; fi"
|
123
|
-
end
|
124
|
-
desc "Notify Errbit about a dqeploy"
|
125
|
-
task :notify, :roles => :app do
|
126
|
-
next if fetch(:production_errbit_api_key, "").empty?
|
127
|
-
require 'active_support/core_ext/object'
|
128
|
-
|
129
|
-
parameters = {
|
130
|
-
:api_key => production_errbit_api_key,
|
131
|
-
:deploy => {
|
132
|
-
:rails_env => stage,
|
133
|
-
:local_username => ENV["USER"],
|
134
|
-
:scm_repository => repository,
|
135
|
-
:scm_revision => current_revision
|
136
|
-
}
|
137
|
-
}
|
138
|
-
run_locally "curl -d '#{parameters.to_query}' https://errors.sumocoders.be/deploys.txt"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
namespace :files do
|
143
|
-
def find_folder_in_parents(folder)
|
144
|
-
require 'pathname'
|
145
|
-
|
146
|
-
path = Pathname.pwd
|
147
|
-
begin
|
148
|
-
found = Pathname.glob(path + folder)
|
149
|
-
return found.first if found.any?
|
150
|
-
|
151
|
-
path = path.parent
|
152
|
-
end until path.root?
|
153
|
-
end
|
154
|
-
|
155
|
-
def rsync(direction, from, to, options = {})
|
156
|
-
servers = find_servers_for_task(current_task)
|
157
|
-
servers = [servers.first] if options[:once]
|
158
|
-
|
159
|
-
servers.each do |server|
|
160
|
-
host_definition = "#{server.user || user}@#{server.host}"
|
161
|
-
host_definition << ":#{server.port}" if server.port && server.port != 22
|
162
|
-
|
163
|
-
case direction
|
164
|
-
when :down
|
165
|
-
run_locally "rsync -rtlpv #{host_definition}:#{from} #{to}"
|
166
|
-
when :up
|
167
|
-
run_locally "rsync -rtlp #{from} #{host_definition}:#{to}"
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
desc "Sync all remote files to your local install"
|
173
|
-
task :get, :roles => :app do
|
174
|
-
path = find_folder_in_parents('frontend/files')
|
175
|
-
if !path
|
176
|
-
abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
|
177
|
-
else
|
178
|
-
rsync :down, shared_files_path, path, :once => true
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
desc "Sync your local files to the remote server"
|
183
|
-
task :put, :roles => :app do
|
184
|
-
# create a backup on the remote, store it under the release-folder, so it will be automagically removed
|
185
|
-
run %{cd #{shared_path} && tar -czf #{current_path}/backup_files.tgz files}
|
186
|
-
|
187
|
-
# check if folder exists
|
188
|
-
path = find_folder_in_parents('frontend/files')
|
189
|
-
if !path
|
190
|
-
abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
|
191
|
-
else
|
192
|
-
rsync :up, "#{path}/", shared_files_path
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
namespace :redirect do
|
198
|
-
desc "Installs the redirect page for the site"
|
199
|
-
task :put, :roles => :app do
|
200
|
-
unless exists?(:production_url)
|
201
|
-
fetch(:production_url) do
|
202
|
-
Capistrano::CLI.ui.ask "What is the production url?"
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
run %{
|
207
|
-
mkdir -p #{shared_path}/redirect &&
|
208
|
-
wget --quiet -O #{shared_path}/redirect/index.php http://static.sumocoders.be/redirect/index.phps &&
|
209
|
-
wget --quiet -O #{shared_path}/redirect/.htaccess http://static.sumocoders.be/redirect/htaccess
|
210
|
-
}
|
211
|
-
|
212
|
-
# change the url
|
213
|
-
run "if [ -f #{shared_path}/redirect/index.php ]; then sed -i 's|<real-url>|#{production_url}|' #{shared_path}/redirect/index.php; fi"
|
214
|
-
|
215
|
-
run %{
|
216
|
-
rm -f #{current_path} &&
|
217
|
-
ln -s #{shared_path}/redirect #{current_path}
|
218
|
-
}
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
50
|
namespace :setup do
|
223
51
|
desc "Create the client folder if it doesn't exist yet"
|
224
52
|
task :client_folder do
|
data/sumodev_deploy.gemspec
CHANGED