kcapifony 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kcapifony might be problematic. Click here for more details.
- data/CHANGELOG +118 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/bin/kcapifony +122 -0
- data/lib/kcapifony.rb +26 -0
- data/lib/ksymfony1.rb +639 -0
- data/lib/ksymfony2.rb +377 -0
- metadata +75 -0
data/lib/ksymfony1.rb
ADDED
@@ -0,0 +1,639 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
load Gem.find_files('kcapifony.rb').last.to_s
|
3
|
+
|
4
|
+
# Dirs that need to remain the same between deploys (shared dirs)
|
5
|
+
set :shared_children, %w(log web/uploads)
|
6
|
+
|
7
|
+
# Files that need to remain the same between deploys
|
8
|
+
set :shared_files, %w(config/databases.yml)
|
9
|
+
|
10
|
+
# Asset folders (that need to be timestamped)
|
11
|
+
set :asset_children, %w(web/css web/images web/js)
|
12
|
+
|
13
|
+
# Use ORM
|
14
|
+
set :use_orm, true
|
15
|
+
|
16
|
+
# Symfony default ORM
|
17
|
+
set(:symfony_orm) { guess_symfony_orm }
|
18
|
+
|
19
|
+
# Symfony lib path
|
20
|
+
set(:symfony_lib) { guess_symfony_lib }
|
21
|
+
|
22
|
+
# Shared symfony lib
|
23
|
+
set :use_shared_symfony, false
|
24
|
+
set :symfony_version, "1.4.11"
|
25
|
+
|
26
|
+
def guess_symfony_orm
|
27
|
+
databases = YAML::load(IO.read('config/databases.yml'))
|
28
|
+
|
29
|
+
if databases[symfony_env_local]
|
30
|
+
databases[symfony_env_local].keys[0].to_s
|
31
|
+
else
|
32
|
+
databases['all'].keys[0].to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def guess_symfony_lib
|
37
|
+
symfony_version = capture("cd #{latest_release} && #{php_bin} ./symfony -V")
|
38
|
+
|
39
|
+
/\((.*)\)/.match(symfony_version)[1]
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_database_config(data, env)
|
43
|
+
databases = YAML::load(data)
|
44
|
+
|
45
|
+
if databases[env]
|
46
|
+
db_param = databases[env][symfony_orm]['param']
|
47
|
+
else
|
48
|
+
db_param = databases['all'][symfony_orm]['param']
|
49
|
+
end
|
50
|
+
|
51
|
+
{
|
52
|
+
'type' => /(\w+)\:/.match(db_param['dsn'])[1],
|
53
|
+
'user' => db_param['username'],
|
54
|
+
'pass' => db_param['password'],
|
55
|
+
'db' => /dbname=([^;$]+)/.match(db_param['dsn'])[1]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace :deploy do
|
60
|
+
desc "Customize migrate task because symfony doesn't need it."
|
61
|
+
task :migrate do
|
62
|
+
symfony.orm.migrate
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Symlink static directories and static files that need to remain between deployments."
|
66
|
+
task :share_childs do
|
67
|
+
if shared_children
|
68
|
+
shared_children.each do |link|
|
69
|
+
run "mkdir -p #{shared_path}/#{link}"
|
70
|
+
run "if [ -d #{release_path}/#{link} ] ; then rm -rf #{release_path}/#{link}; fi"
|
71
|
+
run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
if shared_files
|
75
|
+
shared_files.each do |link|
|
76
|
+
link_dir = File.dirname("#{shared_path}/#{link}")
|
77
|
+
run "mkdir -p #{link_dir}"
|
78
|
+
run "touch #{shared_path}/#{link}"
|
79
|
+
run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "Customize the finalize_update task to work with symfony."
|
85
|
+
task :finalize_update, :except => { :no_release => true } do
|
86
|
+
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
|
87
|
+
run "mkdir -p #{latest_release}/cache"
|
88
|
+
run "chmod -R g+w #{latest_release}/cache"
|
89
|
+
|
90
|
+
# Share common files & folders
|
91
|
+
share_childs
|
92
|
+
|
93
|
+
if fetch(:normalize_asset_timestamps, true)
|
94
|
+
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
95
|
+
asset_paths = asset_children.map { |p| "#{latest_release}/#{p}" }.join(" ")
|
96
|
+
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
desc "Need to overwrite the deploy:cold task so it doesn't try to run the migrations."
|
101
|
+
task :cold do
|
102
|
+
update
|
103
|
+
symfony.orm.build_db_and_load
|
104
|
+
start
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "Deploy the application and run the test suite."
|
108
|
+
task :testall do
|
109
|
+
update_code
|
110
|
+
symlink
|
111
|
+
symfony.orm.build_db_and_load
|
112
|
+
symfony.tests.all
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
namespace :symfony do
|
117
|
+
desc "Runs custom symfony task"
|
118
|
+
task :default do
|
119
|
+
prompt_with_default(:task_arguments, "cache:clear")
|
120
|
+
|
121
|
+
stream "cd #{latest_release} && #{php_bin} ./symfony #{task_arguments}"
|
122
|
+
end
|
123
|
+
|
124
|
+
desc "Downloads & runs check_configuration.php on remote"
|
125
|
+
task :check_configuration do
|
126
|
+
prompt_with_default(:version, "1.4")
|
127
|
+
|
128
|
+
run "wget http://sf-to.org/#{version}/check.php -O /tmp/check_configuration.php"
|
129
|
+
stream "#{php_bin} /tmp/check_configuration.php"
|
130
|
+
run "rm /tmp/check_configuration.php"
|
131
|
+
end
|
132
|
+
|
133
|
+
desc "Clears the cache"
|
134
|
+
task :cc do
|
135
|
+
run "cd #{latest_release} && #{php_bin} ./symfony cache:clear"
|
136
|
+
run "chmod -R g+w #{latest_release}/cache"
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Creates symbolic link to symfony lib in shared"
|
140
|
+
task :create_lib_symlink do
|
141
|
+
prompt_with_default(:version, symfony_version)
|
142
|
+
symlink_path = "#{latest_release}/lib/vendor/symfony"
|
143
|
+
|
144
|
+
run "if [ ! -d #{shared_path}/symfony-#{version} ]; then exit 1; fi;"
|
145
|
+
run "ln -nfs #{shared_path}/symfony-#{version} #{symlink_path};"
|
146
|
+
end
|
147
|
+
|
148
|
+
namespace :configure do
|
149
|
+
desc "Configure database DSN"
|
150
|
+
task :database do
|
151
|
+
prompt_with_default(:dsn, "mysql:host=localhost;dbname=#{application}")
|
152
|
+
prompt_with_default(:db_username, "root")
|
153
|
+
db_password = Capistrano::CLI.password_prompt("db_password : ")
|
154
|
+
|
155
|
+
# surpress debug log output to hide the password
|
156
|
+
current_logger_level = self.logger.level
|
157
|
+
if current_logger_level >= Capistrano::Logger::DEBUG
|
158
|
+
logger.debug %(executing "cd #{latest_release} && #{php_bin} ./symfony configure:database '#{dsn}' '#{db_username}' ***")
|
159
|
+
self.logger.level = Capistrano::Logger::INFO
|
160
|
+
end
|
161
|
+
|
162
|
+
stream "cd #{latest_release} && #{php_bin} ./symfony configure:database '#{dsn}' '#{db_username}' '#{db_password}'"
|
163
|
+
|
164
|
+
# restore logger level
|
165
|
+
self.logger.level = current_logger_level
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
namespace :project do
|
170
|
+
desc "Disables an application in a given environment"
|
171
|
+
task :disable do
|
172
|
+
run "cd #{latest_release} && #{php_bin} ./symfony project:disable #{symfony_env_prod}"
|
173
|
+
end
|
174
|
+
|
175
|
+
desc "Enables an application in a given environment"
|
176
|
+
task :enable do
|
177
|
+
run "cd #{latest_release} && #{php_bin} ./symfony project:enable #{symfony_env_prod}"
|
178
|
+
end
|
179
|
+
|
180
|
+
desc "Fixes symfony directory permissions"
|
181
|
+
task :permissions do
|
182
|
+
run "cd #{latest_release} && #{php_bin} ./symfony project:permissions"
|
183
|
+
end
|
184
|
+
|
185
|
+
desc "Optimizes a project for better performance"
|
186
|
+
task :optimize do
|
187
|
+
prompt_with_default(:application, "frontend")
|
188
|
+
|
189
|
+
run "cd #{latest_release} && #{php_bin} ./symfony project:optimize #{application}"
|
190
|
+
end
|
191
|
+
|
192
|
+
desc "Clears all non production environment controllers"
|
193
|
+
task :clear_controllers do
|
194
|
+
run "cd #{latest_release} && #{php_bin} ./symfony project:clear-controllers"
|
195
|
+
end
|
196
|
+
|
197
|
+
desc "Sends emails stored in a queue"
|
198
|
+
task :send_emails do
|
199
|
+
prompt_with_default(:message_limit, 10)
|
200
|
+
prompt_with_default(:time_limit, 10)
|
201
|
+
|
202
|
+
stream "cd #{latest_release} && #{php_bin} ./symfony project:send-emails --message-limit=#{message_limit} --time-limit=#{time_limit} --env=#{symfony_env_prod}"
|
203
|
+
end
|
204
|
+
|
205
|
+
desc 'Task to set all front controllers to a specific environment'
|
206
|
+
task :set_environment do
|
207
|
+
if (env = fetch(:symfony_env_prod, nil)) && env != 'prod'
|
208
|
+
cmd = []
|
209
|
+
apps = fetch(:symfony_apps, ['frontend'])
|
210
|
+
|
211
|
+
# First application listed becomes index.php
|
212
|
+
if app = apps.shift
|
213
|
+
cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/index.php"
|
214
|
+
end
|
215
|
+
|
216
|
+
# All other apps are copied to their default controllers
|
217
|
+
for app in apps
|
218
|
+
cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/#{app}.php"
|
219
|
+
end
|
220
|
+
|
221
|
+
run cmd.join(';') if cmd.join(';')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
namespace :plugin do
|
227
|
+
desc "Publishes web assets for all plugins"
|
228
|
+
task :publish_assets do
|
229
|
+
run "cd #{latest_release} && #{php_bin} ./symfony plugin:publish-assets"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
namespace :log do
|
234
|
+
desc "Clears log files"
|
235
|
+
task :clear do
|
236
|
+
run "cd #{latest_release} && #{php_bin} ./symfony log:clear"
|
237
|
+
end
|
238
|
+
|
239
|
+
desc "Rotates an application's log files"
|
240
|
+
task :rotate do
|
241
|
+
prompt_with_default(:application, "frontend")
|
242
|
+
|
243
|
+
run "cd #{latest_release} && #{php_bin} ./symfony log:rotate #{application} #{symfony_env_prod}"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
namespace :tests do
|
248
|
+
desc "Launches all tests"
|
249
|
+
task :all do
|
250
|
+
run "cd #{latest_release} && #{php_bin} ./symfony test:all"
|
251
|
+
end
|
252
|
+
|
253
|
+
desc "Launches functional tests"
|
254
|
+
task :functional do
|
255
|
+
prompt_with_default(:application, "frontend")
|
256
|
+
|
257
|
+
run "cd #{latest_release} && #{php_bin} ./symfony test:functional #{application}"
|
258
|
+
end
|
259
|
+
|
260
|
+
desc "Launches unit tests"
|
261
|
+
task :unit do
|
262
|
+
run "cd #{latest_release} && #{php_bin} ./symfony test:unit"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
namespace :orm do
|
267
|
+
desc "Ensure symfony ORM is properly configured"
|
268
|
+
task :setup do
|
269
|
+
find_and_execute_task("symfony:#{symfony_orm}:setup")
|
270
|
+
end
|
271
|
+
|
272
|
+
desc "Migrates database to current version"
|
273
|
+
task :migrate do
|
274
|
+
find_and_execute_task("symfony:#{symfony_orm}:migrate")
|
275
|
+
end
|
276
|
+
|
277
|
+
desc "Generate model lib form and filters classes based on your schema"
|
278
|
+
task :build_classes do
|
279
|
+
find_and_execute_task("symfony:#{symfony_orm}:build_classes")
|
280
|
+
end
|
281
|
+
|
282
|
+
desc "Generate code & database based on your schema"
|
283
|
+
task :build_all do
|
284
|
+
find_and_execute_task("symfony:#{symfony_orm}:build_all")
|
285
|
+
end
|
286
|
+
|
287
|
+
desc "Generate code & database based on your schema & load fixtures"
|
288
|
+
task :build_all_and_load do
|
289
|
+
find_and_execute_task("symfony:#{symfony_orm}:build_all_and_load")
|
290
|
+
end
|
291
|
+
|
292
|
+
desc "Generate sql & database based on your schema"
|
293
|
+
task :build_db do
|
294
|
+
find_and_execute_task("symfony:#{symfony_orm}:build_db")
|
295
|
+
end
|
296
|
+
|
297
|
+
desc "Generate sql & database based on your schema & load fixtures"
|
298
|
+
task :build_db_and_load do
|
299
|
+
find_and_execute_task("symfony:#{symfony_orm}:build_db_and_load")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
namespace :doctrine do
|
304
|
+
desc "Compile doctrine"
|
305
|
+
task :compile do
|
306
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:compile"
|
307
|
+
end
|
308
|
+
|
309
|
+
desc "Ensure Doctrine is correctly configured"
|
310
|
+
task :setup do
|
311
|
+
conf_files_exists = capture("if test -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
|
312
|
+
if (!conf_files_exists.eql?("exists"))
|
313
|
+
symfony.configure.database
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
desc "Execute a DQL query and view the results"
|
318
|
+
task :dql do
|
319
|
+
prompt_with_default(:query, "")
|
320
|
+
|
321
|
+
stream "cd #{latest_release} && #{php_bin} ./symfony doctrine:dql #{query} --env=#{symfony_env_prod}"
|
322
|
+
end
|
323
|
+
|
324
|
+
desc "Dumps data to the fixtures directory"
|
325
|
+
task :data_dump do
|
326
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:data-dump --env=#{symfony_env_prod}"
|
327
|
+
end
|
328
|
+
|
329
|
+
desc "Loads YAML fixture data"
|
330
|
+
task :data_load do
|
331
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:data-load --env=#{symfony_env_prod}"
|
332
|
+
end
|
333
|
+
|
334
|
+
desc "Loads YAML fixture data without remove"
|
335
|
+
task :data_load_append do
|
336
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:data-load --append --env=#{symfony_env_prod}"
|
337
|
+
end
|
338
|
+
|
339
|
+
desc "Migrates database to current version"
|
340
|
+
task :migrate do
|
341
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:migrate --env=#{symfony_env_prod}"
|
342
|
+
end
|
343
|
+
|
344
|
+
desc "Generate model lib form and filters classes based on your schema"
|
345
|
+
task :build_classes do
|
346
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:build --all-classes --env=#{symfony_env_prod}"
|
347
|
+
end
|
348
|
+
|
349
|
+
desc "Generate code & database based on your schema"
|
350
|
+
task :build_all do
|
351
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database? (y/N)")
|
352
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:build --all --no-confirmation --env=#{symfony_env_prod}"
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
desc "Generate code & database based on your schema & load fixtures"
|
357
|
+
task :build_all_and_load do
|
358
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database and load #{symfony_env_prod}'s fixtures? (y/N)")
|
359
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:build --all --and-load --no-confirmation --env=#{symfony_env_prod}"
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
desc "Generate sql & database based on your schema"
|
364
|
+
task :build_db do
|
365
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database? (y/N)")
|
366
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:build --sql --db --no-confirmation --env=#{symfony_env_prod}"
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
desc "Generate sql & database based on your schema & load fixtures"
|
371
|
+
task :build_db_and_load do
|
372
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database and load #{symfony_env_prod}'s fixtures? (y/N)")
|
373
|
+
run "cd #{latest_release} && #{php_bin} ./symfony doctrine:build --sql --db --and-load --no-confirmation --env=#{symfony_env_prod}"
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
namespace :propel do
|
379
|
+
desc "Ensure Propel is correctly configured"
|
380
|
+
task :setup do
|
381
|
+
conf_files_exists = capture("if test -s #{shared_path}/config/propel.ini -a -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
|
382
|
+
|
383
|
+
# share childs again (for propel.ini file)
|
384
|
+
shared_files << "config/propel.ini"
|
385
|
+
deploy.share_childs
|
386
|
+
|
387
|
+
if (!conf_files_exists.eql?("exists"))
|
388
|
+
run "cp #{symfony_lib}/plugins/sfPropelPlugin/config/skeleton/config/propel.ini #{shared_path}/config/propel.ini"
|
389
|
+
symfony.configure.database
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
desc "Migrates database to current version"
|
394
|
+
task :migrate do
|
395
|
+
puts "propel doesn't have built-in migration for now"
|
396
|
+
end
|
397
|
+
|
398
|
+
desc "Generate model lib form and filters classes based on your schema"
|
399
|
+
task :build_classes do
|
400
|
+
run "php #{latest_release}/symfony propel:build --model --env=#{symfony_env_prod}"
|
401
|
+
run "php #{latest_release}/symfony propel:build --forms --env=#{symfony_env_prod}"
|
402
|
+
run "php #{latest_release}/symfony propel:build --filters --env=#{symfony_env_prod}"
|
403
|
+
end
|
404
|
+
|
405
|
+
desc "Generate code & database based on your schema"
|
406
|
+
task :build_all do
|
407
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database? (y/N)")
|
408
|
+
run "cd #{latest_release} && #{php_bin} ./symfony propel:build --sql --db --no-confirmation --env=#{symfony_env_prod}"
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
desc "Generate code & database based on your schema & load fixtures"
|
413
|
+
task :build_all_and_load do
|
414
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database and load #{symfony_env_prod}'s fixtures? (y/N)")
|
415
|
+
run "cd #{latest_release} && #{php_bin} ./symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env_prod}"
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
desc "Generate sql & database based on your schema"
|
420
|
+
task :build_db do
|
421
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database? (y/N)")
|
422
|
+
run "cd #{latest_release} && #{php_bin} ./symfony propel:build --sql --db --no-confirmation --env=#{symfony_env_prod}"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
desc "Generate sql & database based on your schema & load fixtures"
|
427
|
+
task :build_db_and_load do
|
428
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env_prod}'s database and load #{symfony_env_prod}'s fixtures? (y/N)")
|
429
|
+
run "cd #{latest_release} && #{php_bin} ./symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env_prod}"
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
namespace :database do
|
436
|
+
namespace :dump do
|
437
|
+
desc "Dump remote database"
|
438
|
+
task :remote do
|
439
|
+
filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.gz"
|
440
|
+
file = "/tmp/#{filename}"
|
441
|
+
sqlfile = "#{application}_dump.sql"
|
442
|
+
config = ""
|
443
|
+
|
444
|
+
run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
|
445
|
+
config = load_database_config data, symfony_env_prod
|
446
|
+
end
|
447
|
+
|
448
|
+
case config['type']
|
449
|
+
when 'mysql'
|
450
|
+
run "mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
|
451
|
+
puts data
|
452
|
+
end
|
453
|
+
when 'pgsql'
|
454
|
+
run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
|
455
|
+
puts data
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
require "FileUtils"
|
460
|
+
FileUtils.mkdir_p("backups")
|
461
|
+
get file, "backups/#{filename}"
|
462
|
+
begin
|
463
|
+
FileUtils.ln_sf(filename, "backups/#{application}.remote_dump.latest.sql.gz")
|
464
|
+
rescue NotImplementedError # hack for windows which doesnt support symlinks
|
465
|
+
FileUtils.cp_r("backups/#{filename}", "backups/#{application}.remote_dump.latest.sql.gz")
|
466
|
+
end
|
467
|
+
run "rm #{file}"
|
468
|
+
end
|
469
|
+
|
470
|
+
desc "Dump local database"
|
471
|
+
task :local do
|
472
|
+
filename = "#{application}.local_dump.#{Time.now.to_i}.sql.gz"
|
473
|
+
tmpfile = "backups/#{application}_dump_tmp.sql"
|
474
|
+
file = "backups/#{filename}"
|
475
|
+
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
|
476
|
+
sqlfile = "#{application}_dump.sql"
|
477
|
+
|
478
|
+
require "FileUtils"
|
479
|
+
FileUtils::mkdir_p("backups")
|
480
|
+
case config['type']
|
481
|
+
when 'mysql'
|
482
|
+
`mysqldump -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
|
483
|
+
when 'pgsql'
|
484
|
+
`pg_dump -U #{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
|
485
|
+
end
|
486
|
+
File.open(tmpfile, "r+") do |f|
|
487
|
+
gz = Zlib::GzipWriter.open(file)
|
488
|
+
while (line = f.gets)
|
489
|
+
gz << line
|
490
|
+
end
|
491
|
+
gz.flush
|
492
|
+
gz.close
|
493
|
+
end
|
494
|
+
|
495
|
+
begin
|
496
|
+
FileUtils.ln_sf(filename, "backups/#{application}.local_dump.latest.sql.gz")
|
497
|
+
rescue NotImplementedError # hack for windows which doesnt support symlinks
|
498
|
+
FileUtils.cp_r("backups/#{filename}", "backups/#{application}.local_dump.latest.sql.gz")
|
499
|
+
end
|
500
|
+
FileUtils.rm(tmpfile)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
namespace :move do
|
505
|
+
desc "Dump remote database, download it to local & populate here"
|
506
|
+
task :to_local do
|
507
|
+
filename = "#{application}.remote_dump.latest.sql.gz"
|
508
|
+
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
|
509
|
+
sqlfile = "#{application}_dump.sql"
|
510
|
+
|
511
|
+
database.dump.remote
|
512
|
+
|
513
|
+
require "FileUtils"
|
514
|
+
f = File.new("backups/#{sqlfile}", "a+")
|
515
|
+
require "zlib"
|
516
|
+
gz = Zlib::GzipReader.new(File.open("backups/#{filename}", "r"))
|
517
|
+
f << gz.read
|
518
|
+
f.close
|
519
|
+
|
520
|
+
case config['type']
|
521
|
+
when 'mysql'
|
522
|
+
`mysql -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} < backups/#{sqlfile}`
|
523
|
+
when 'pgsql'
|
524
|
+
`psql -U #{config['user']} --password=\"#{config['pass']}\" #{config['db']} < backups/#{sqlfile}`
|
525
|
+
end
|
526
|
+
FileUtils.rm("backups/#{sqlfile}")
|
527
|
+
end
|
528
|
+
|
529
|
+
desc "Dump local database, load it to remote & populate there"
|
530
|
+
task :to_remote do
|
531
|
+
filename = "#{application}.local_dump.latest.sql.gz"
|
532
|
+
file = "backups/#{filename}"
|
533
|
+
sqlfile = "#{application}_dump.sql"
|
534
|
+
config = ""
|
535
|
+
|
536
|
+
database.dump.local
|
537
|
+
|
538
|
+
upload(file, "/tmp/#{filename}", :via => :scp)
|
539
|
+
run "gunzip -c /tmp/#{filename} > /tmp/#{sqlfile}"
|
540
|
+
|
541
|
+
run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
|
542
|
+
config = load_database_config data, symfony_env_prod
|
543
|
+
end
|
544
|
+
|
545
|
+
case config['type']
|
546
|
+
when 'mysql'
|
547
|
+
run "mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
|
548
|
+
puts data
|
549
|
+
end
|
550
|
+
when 'pgsql'
|
551
|
+
run "psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
|
552
|
+
puts data
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
run "rm /tmp/#{filename}"
|
557
|
+
run "rm /tmp/#{sqlfile}"
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
namespace :shared do
|
563
|
+
namespace :databases do
|
564
|
+
desc "Download config/databases.yml from remote server"
|
565
|
+
task :to_local do
|
566
|
+
download("#{shared_path}/config/databases.yml", "config/databases.yml", :via => :scp)
|
567
|
+
end
|
568
|
+
|
569
|
+
desc "Upload config/databases.yml to remote server"
|
570
|
+
task :to_remote do
|
571
|
+
upload("config/databases.yml", "#{shared_path}/config/databases.yml", :via => :scp)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
namespace :log do
|
576
|
+
desc "Download all logs from remote folder to local one"
|
577
|
+
task :to_local do
|
578
|
+
download("#{shared_path}/log", "./", :via => :scp, :recursive => true)
|
579
|
+
end
|
580
|
+
|
581
|
+
desc "Upload all logs from local folder to remote one"
|
582
|
+
task :to_remote do
|
583
|
+
upload("log", "#{shared_path}/", :via => :scp, :recursive => true)
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
namespace :uploads do
|
588
|
+
desc "Download all files from remote web/uploads folder to local one"
|
589
|
+
task :to_local do
|
590
|
+
download("#{shared_path}/web/uploads", "web", :via => :scp, :recursive => true)
|
591
|
+
end
|
592
|
+
|
593
|
+
desc "Upload all files from local web/uploads folder to remote one"
|
594
|
+
task :to_remote do
|
595
|
+
upload("web/uploads", "#{shared_path}/web", :via => :scp, :recursive => true)
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
namespace :symfony do
|
600
|
+
desc "Downloads symfony framework to shared directory"
|
601
|
+
task :download do
|
602
|
+
prompt_with_default(:version, symfony_version)
|
603
|
+
|
604
|
+
run <<-CMD
|
605
|
+
if [ ! -d #{shared_path}/symfony-#{version} ]; then
|
606
|
+
wget -q http://www.symfony-project.org/get/symfony-#{version}.tgz -O- | tar -zxf - -C #{shared_path};
|
607
|
+
fi
|
608
|
+
CMD
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
# After setup
|
614
|
+
after "deploy:setup" do
|
615
|
+
if use_shared_symfony
|
616
|
+
shared.symfony.download
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
# Before finalizing update
|
621
|
+
before "deploy:finalize_update" do
|
622
|
+
if use_shared_symfony
|
623
|
+
symfony.create_lib_symlink
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
# After finalizing update:
|
628
|
+
after "deploy:finalize_update" do
|
629
|
+
if use_orm
|
630
|
+
symfony.orm.setup # 1. Ensure that ORM is configured
|
631
|
+
symfony.orm.build_classes # 2. (Re)build the model
|
632
|
+
end
|
633
|
+
symfony.cc # 3. Clear cache
|
634
|
+
symfony.plugin.publish_assets # 4. Publish plugin assets
|
635
|
+
symfony.project.permissions # 5. Fix project permissions
|
636
|
+
if symfony_env_prod.eql?("prod")
|
637
|
+
symfony.project.clear_controllers # 6. Clear controllers in production environment
|
638
|
+
end
|
639
|
+
end
|