Skip to content

Commit 06fb10c

Browse files
committed
Merge branch 'develop' for release 0.8.0
* Added support for zero-down deployment (PR #104, issue #34) * Added call to "composer dump-autoload --no-dev --optimize" following DI compliation (issue #102)
2 parents fd4511e + d6d0627 commit 06fb10c

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Capistrano::Magento2 Change Log
22

3+
0.8.0
4+
==========
5+
6+
* Added support for zero-down deployment (PR #104, issue #34)
7+
* Added call to "composer dump-autoload --no-dev --optimize" following DI compliation (issue #102)
8+
39
0.7.3
410
==========
511

lib/capistrano/magento2/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
module Capistrano
1111
module Magento2
12-
VERSION = '0.7.3'
12+
VERSION = '0.8.0'
1313
end
1414
end

lib/capistrano/tasks/deploy.rake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ namespace :deploy do
3030
invoke 'magento:deploy:mode:production'
3131
invoke 'magento:setup:static-content:deploy'
3232
invoke 'magento:setup:di:compile'
33+
invoke 'magento:composer:dump-autoload'
3334
end
3435
invoke 'magento:setup:permissions'
36+
invoke 'magento:maintenance:check'
3537
invoke 'magento:maintenance:enable' if fetch(:magento_deploy_maintenance)
3638

3739
on release_roles :all do
@@ -49,7 +51,9 @@ namespace :deploy do
4951
on primary fetch(:magento_deploy_setup_role) do
5052
within release_path do
5153
if test :magento, 'app:config:import --help >/dev/null 2>&1'
52-
invoke 'magento:app:config:import'
54+
if fetch(:magento_deploy_maintenance)
55+
invoke 'magento:app:config:import'
56+
end
5357
end
5458
end
5559
end

lib/capistrano/tasks/magento.rake

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ namespace :magento do
124124
end
125125
end
126126

127+
desc 'Run composer dump-autoload'
128+
task 'dump-autoload' do
129+
130+
on release_roles :all do
131+
within release_path do
132+
composer_flags = '--no-dev --no-interaction'
133+
134+
if fetch(:magento_deploy_production)
135+
composer_flags += ' --optimize'
136+
end
137+
138+
execute :composer, "dump-autoload #{composer_flags} 2>&1"
139+
end
140+
end
141+
end
142+
127143
task :auth_config do
128144
on release_roles :all do
129145
within release_path do
@@ -382,7 +398,60 @@ namespace :magento do
382398
end
383399
end
384400
end
385-
401+
402+
# Internal command used to check if maintenance mode is neeeded and disable when zero-down deploy is possible
403+
task :check do
404+
on primary fetch(:magento_deploy_setup_role) do
405+
within release_path do
406+
# Do not disable maintenance mode by default; require a postive id on database status output
407+
disable_maintenance = false
408+
409+
# The setup:db:status command is only available in Magento 2.2.2 and later
410+
if not test :magento, 'setup:db:status --help >/dev/null 2>&1'
411+
info "Magento CLI command setup:db:status is not available. Maintenance mode will be used by default."
412+
else
413+
info "Checking database status..."
414+
# Check setup:db:status output and disable maintenance mode if all modules are up-to-date
415+
database_status = capture :magento, 'setup:db:status' , raise_on_non_zero_exit: false
416+
417+
if database_status.to_s.include? 'All modules are up to date'
418+
info "All modules are up to date. No database updates should occur during this release."
419+
puts ""
420+
disable_maintenance = true
421+
else
422+
puts " #{database_status.gsub("\n", "\n ").sub("Run 'setup:upgrade' to update your DB schema and data.", "")}"
423+
end
424+
425+
# Gather md5sums of app/etc/config.php on current and new release
426+
config_hash_release = capture :md5sum, "#{release_path}/app/etc/config.php"
427+
if test "[ -f #{current_path}/app/etc/config.php ]"
428+
config_hash_current = capture :md5sum, "#{current_path}/app/etc/config.php"
429+
else
430+
config_hash_current = ("%-34s" % "n/a") + "#{current_path}/app/etc/config.php"
431+
end
432+
433+
# Output some informational messages showing the config.php hash values
434+
info "<release_path>/app/etc/config.php hash: #{config_hash_release.split(" ")[0]}"
435+
info "<current_path>/app/etc/config.php hash: #{config_hash_current.split(" ")[0]}"
436+
info ""
437+
438+
# If hashes differ, maintenance mode should not be disabled even if there are no database changes.
439+
if config_hash_release.split(" ")[0] != config_hash_current.split(" ")[0]
440+
info "Configuration hashes do not match. Maintenance mode will be used by default."
441+
disable_maintenance = false
442+
end
443+
444+
if disable_maintenance
445+
info "Disabling use of maintenance mode for a zero-down deployment."
446+
set :magento_deploy_maintenance, false
447+
else
448+
info "Maintenance mode usage will be enforced per :magento_deploy_maintenance (enabled by default)"
449+
end
450+
end
451+
end
452+
end
453+
end
454+
386455
desc 'Disable maintenance mode'
387456
task :disable do
388457
on release_roles :all do

0 commit comments

Comments
 (0)