-
Notifications
You must be signed in to change notification settings - Fork 217
/
capifony_symfony2.rb
executable file
·365 lines (284 loc) · 11 KB
/
capifony_symfony2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# encoding: utf-8
require 'capistrano'
require 'capistrano/maintenance'
require 'colored'
require 'fileutils'
require 'inifile'
require 'yaml'
require 'zlib'
require 'ruby-progressbar'
module Capifony
module Symfony2
def self.load_into(configuration)
configuration.load do
load_paths.push File.expand_path('../', __FILE__)
load 'capifony'
load 'symfony2/symfony'
load 'symfony2/database'
load 'symfony2/deploy'
load 'symfony2/doctrine'
load 'symfony2/propel'
load 'symfony2/web'
load 'symfony2/shared'
# Symfony application path
set :app_path, "app"
# Symfony web path
set :web_path, "web"
# Symfony console bin
set :symfony_console, app_path + "/console"
# Symfony debug flag for console commands
set :symfony_debug, false
# Symfony log path
set :log_path, app_path + "/logs"
# Symfony cache path
set :cache_path, app_path + "/cache"
# Symfony config file path
set :app_config_path, app_path + "/config"
# Symfony config file (parameters.(ini|yml|etc...)
set :app_config_file, "parameters.yml"
# Symfony bin vendors
set :symfony_vendors, "bin/vendors"
# Symfony build_bootstrap script
set :build_bootstrap, "bin/build_bootstrap"
# Whether to use composer to install vendors.
# If set to false, it will use the bin/vendors script
set :use_composer, false
# Whether to use composer to install vendors to a local temp directory.
set :use_composer_tmp, false
# Path to composer binary
# If set to false, Capifony will download/install composer
set :composer_bin, false
# Release number to composer
# If you would like to instead update to a specific release simply specify it (for example '1.0.0-alpha8')
set :composer_version, ""
# Options to pass to composer when installing/updating
set :composer_options, "--no-dev --verbose --prefer-dist --optimize-autoloader --no-progress"
# Options to pass to composer when dumping the autoloader (dump-autoloader)
set :composer_dump_autoload_options, "--optimize"
# Whether to update vendors using the configured dependency manager (composer or bin/vendors)
set :update_vendors, false
# run bin/vendors script in mode (upgrade, install (faster if shared /vendor folder) or reinstall)
set :vendors_mode, "reinstall"
# Copy vendors from previous release
set :copy_vendors, false
# Whether to run cache warmup
set :cache_warmup, true
# Use AsseticBundle
set :dump_assetic_assets, false
# Assets install
set :assets_install, false
set :assets_symlinks, false
set :assets_relative, false
set :assets_install_path, web_path
# Whether to update `assets_version` in `config.yml`
set :update_assets_version, false
# Need to clear *_dev controllers
set :clear_controllers, true
# Controllers to clear
set :controllers_to_clear, ['app_*.php']
# Files that need to remain the same between deploys
set :shared_files, false
# Dirs that need to remain the same between deploys (shared dirs)
set :shared_children, [log_path, web_path + "/uploads"]
# Asset folders (that need to be timestamped)
set :asset_children, [web_path + "/css", web_path + "/images", web_path + "/js"]
# Dirs that need to be writable by the HTTP Server (i.e. cache, log dirs)
set :writable_dirs, [log_path, cache_path]
# Name used by the Web Server (i.e. www-data for Apache)
set :webserver_user, "www-data"
# Method used to set permissions (:chmod, :acl, or :chown)
set :permission_method, false
# Execute set permissions
set :use_set_permissions, false
# Model manager: (doctrine, propel)
set :model_manager, "doctrine"
# Doctrine custom entity manager
set :doctrine_em, false
# Database backup folder
set :backup_path, "backups"
# Use --flush option in doctrine:clear_* task
set :doctrine_clear_use_flush_option, false
# Symfony2 version
set(:symfony_version) { guess_symfony_version }
# If set to false, it will never ask for confirmations (migrations task for instance)
# Use it carefully, really!
set :interactive_mode, true
def load_database_config(data, env)
read_parameters(data)['parameters']
end
def read_parameters(data)
if '.ini' === File.extname(app_config_file) then
File.readable?(data) ? IniFile::load(data) : IniFile.new(data)
else
YAML::load(data)
end
end
def guess_symfony_version
capture("cd #{latest_release} && #{php_bin} #{symfony_console} --version |cut -d \" \" -f 3")
end
def remote_file_exists?(full_path)
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end
def remote_command_exists?(command)
'true' == capture("if [ -x \"$(which #{command})\" ]; then echo 'true'; fi").strip
end
def console_options
console_options = "--env=#{symfony_env_prod}"
if !symfony_debug
console_options += " --no-debug"
end
return console_options
end
STDOUT.sync
$error = false
$pretty_errors_defined = false
# Be less verbose by default
logger.level = Capistrano::Logger::IMPORTANT
def capifony_pretty_print(msg)
if logger.level == Capistrano::Logger::IMPORTANT
pretty_errors
msg = msg.slice(0, 57)
msg << '.' * (60 - msg.size)
print msg
else
puts msg.green
end
end
def capifony_puts_ok
if logger.level == Capistrano::Logger::IMPORTANT && !$error
puts '✔'.green
end
$error = false
end
def pretty_errors
if !$pretty_errors_defined
$pretty_errors_defined = true
class << $stderr
@@firstLine = true
alias _write write
def write(s)
if @@firstLine
_write('✘'.red << "\n")
@@firstLine = false
end
_write(s.red)
$error = true
end
end
end
end
$progress_bar = nil
$download_msg_padding = nil
def capifony_progress_start(msg = "--> Working")
$download_msg_padding = '.' * (60 - msg.size)
# Format is equivalent to "Title............82% ETA: 00:00:12"
$progress_bar = ProgressBar.create(
:title => msg,
:format => "%t%B %p%% %e",
:length => 60,
:progress_mark => "."
)
end
def capifony_progress_update(current, total)
unless $progress_bar
raise "Please create a progress bar using capifony_progress_start"
end
percent = (current.to_f / total.to_f * 100).floor
if percent > 99
green_tick = '✔'.green
# Format is equivalent to "Title.............✔"
$progress_bar.format("%t#{$download_msg_padding}#{green_tick}")
end
$progress_bar.progress = percent
end
[
"symfony:doctrine:cache:clear_metadata",
"symfony:doctrine:cache:clear_query",
"symfony:doctrine:cache:clear_result",
"symfony:doctrine:schema:create",
"symfony:doctrine:schema:drop",
"symfony:doctrine:schema:update",
"symfony:doctrine:load_fixtures",
"symfony:doctrine:migrations:migrate",
"symfony:doctrine:migrations:status",
].each do |action|
before action do
set :doctrine_em_flag, doctrine_em ? " --em=#{doctrine_em}" : ""
end
end
["symfony:composer:install", "symfony:composer:update", "symfony:vendors:install", "symfony:vendors:upgrade"].each do |action|
before action do
if copy_vendors
symfony.composer.copy_vendors
end
end
end
after "deploy:finalize_update" do
if update_assets_version
symfony.assets.update_version # Update `assets_version`
end
if use_composer && !use_composer_tmp
if update_vendors
symfony.composer.update
else
symfony.composer.install
end
else
if update_vendors
vendors_mode.chomp # To remove trailing whiteline
case vendors_mode
when "upgrade" then symfony.vendors.upgrade
when "install" then symfony.vendors.install
when "reinstall" then symfony.vendors.reinstall
end
end
end
if model_manager == "propel"
symfony.propel.build.model
end
if assets_install
symfony.assets.install # Install assets
end
if dump_assetic_assets
symfony.assetic.dump # Dump assetic assets
end
if cache_warmup
symfony.cache.warmup # Warmup clean cache
end
if clear_controllers
# If clear_controllers is an array set controllers_to_clear,
# else use the default value 'app_*.php'
if clear_controllers.is_a? Array
set(:controllers_to_clear) { clear_controllers }
end
symfony.project.clear_controllers
end
if use_set_permissions
# Set permissions after all cache files have been created
symfony.deploy.set_permissions
end
end
before "deploy:update_code" do
msg = "--> Updating code base with #{deploy_via} strategy"
if logger.level == Capistrano::Logger::IMPORTANT
pretty_errors
puts msg
else
puts msg.green
end
end
after "deploy:create_symlink" do
puts "--> Successfully deployed!".green
end
# Recreate the autoload file after rolling back
# https://github.com/everzet/capifony/issues/422
after "deploy:rollback" do
run "cd #{current_path} && #{composer_bin} dump-autoload #{composer_dump_autoload_options}"
end
end
end
end
end
if Capistrano::Configuration.instance
Capifony::Symfony2.load_into(Capistrano::Configuration.instance)
end