capistrano-magento2 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39f8768fb9d567d6d6472c88c5678de0ab0301239c448ec8c553c2289b3bb7e2
4
- data.tar.gz: b316370020b96dc2b90737ddfb56019e6f9f2097c93d05a208fdb622a0cd2b1d
3
+ metadata.gz: 647236f26af13c3c337e3c4c2c105f959c4a5af20b2d5cae9d064c7f1523d168
4
+ data.tar.gz: f8534cef247514959253f7e47caf8563966a92c4b9f712a987b9f68299b7b8d0
5
5
  SHA512:
6
- metadata.gz: b63c59ddd943416c55cd7216cccf5797dd361f8c091b4b067b394c96f4d199d07760b608b7e2deae4d455bc0af3ce4910ead1f1ffa14ab4ed04df47ed548a8f7
7
- data.tar.gz: a67d479d4a50a102c13fe0de1e7749170b26efdb2c330f1e40da0ee4641a0c5be1bc9384cee67a3e7811c1928ed8ae9010e7f42c3108138481d684c6a410310e
6
+ metadata.gz: 3e65ecf251ecb4b7d93d4ab838036b64859962decd16ec18f8848d4828cf86b85fb3c2c86225b0ec04febd7f65c6d4b550d49c0c2954217cb75f0d039bc87756
7
+ data.tar.gz: 6663d81e73de427ea960a3dbdb742de46e8bc58d8d7f115616b8c18511bb659a186a389eaf8bdee74bb530156c8005d5558417559a049803ba71bc5ba2bef0b5
@@ -1,5 +1,12 @@
1
1
  # Capistrano::Magento2 Change Log
2
2
 
3
+ 0.8.1
4
+ ==========
5
+
6
+ * Added `require 'capistrano/magento2/cachetool'` which may be used to enable flushing the php-opcache when [cachetool](http://gordalina.github.io/cachetool/) is installed on the server
7
+ * Added `cachetool:opcache:status` and `cachetool:opcache:reset` commands (use `require 'capistrano/magento2/cachetool'` to enable them)
8
+ * Fixed issue causing deployment to disable maintenance mode when manually enabled prior to deployment (issue #16)
9
+
3
10
  0.8.0
4
11
  ==========
5
12
 
data/README.md CHANGED
@@ -204,6 +204,21 @@ To see what process the built-in routine runs, take a look at the included rake
204
204
 
205
205
  Before deploying with Capistrano, you must update each of your web servers to point to the `current` directory inside of the configured `:deploy_to` directory. For example: `/var/www/html/current/pub` Refer to the [Capistrano Structure](http://capistranorb.com/documentation/getting-started/structure/) to learn more about Capistrano's folder structure.
206
206
 
207
+ ### PHP Opcache Reset
208
+
209
+ When doing atomic deployments with php-opcache installed on a server, the cache will reach a full state after which application performance will degrade as a result of the opcache not being able to do it's job. To work nicely with this, there is support included for automatically resetting the php-opcache after a release is published.
210
+
211
+ To use this, include `require 'capistrano/magento2/cachetool'` in your `Capfile` and make sure there is an `/etc/cachetool.yml` or `/var/www/html/.cachetool.yml` (assuming `:deploy_to` points at `/var/www/html`) file configured with contents like the following:
212
+
213
+ adapter: fastcgi
214
+ fastcgi: /var/run/php-fpm/www-data.sock
215
+ temp_dir: /dev/shm/cachetool
216
+ extensions: [ opcache ]
217
+
218
+ With this configuration in place, be sure cachetool ([available from here](http://gordalina.github.io/cachetool/)) has already been installed on the server and is available in `$PATH`.
219
+
220
+ Congratulations! You should now begin to see the pre-deployemnt opcache status information when running a deployment followed immediately be the `cachetool opcache:reset` command used to keep things humming nicely along.
221
+
207
222
  ## Magento Specific Tasks
208
223
 
209
224
  All Magento 2 tasks used by the built-in `deploy.rake` file as well as some additional commands are implemented and exposed to the end-user for use directly via the cap tool. You can also see this list by running `cap -T` from your shell.
@@ -0,0 +1,14 @@
1
+ ##
2
+ # Copyright © 2018 by David Alger. All rights reserved
3
+ #
4
+ # Licensed under the Open Software License 3.0 (OSL-3.0)
5
+ # See included LICENSE file for full text of OSL-3.0
6
+ #
7
+ # http://davidalger.com/contact/
8
+ ##
9
+
10
+ require 'capistrano/deploy'
11
+
12
+ SSHKit.config.command_map[:cachetool] = "/usr/bin/env cachetool --"
13
+
14
+ load File.expand_path('../../tasks/cachetool.rake', __FILE__)
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Capistrano
11
11
  module Magento2
12
- VERSION = '0.8.0'
12
+ VERSION = '0.8.1'
13
13
  end
14
14
  end
@@ -0,0 +1,34 @@
1
+ ##
2
+ # Copyright © 2018 by David Alger. All rights reserved
3
+ #
4
+ # Licensed under the Open Software License 3.0 (OSL-3.0)
5
+ # See included LICENSE file for full text of OSL-3.0
6
+ #
7
+ # http://davidalger.com/contact/
8
+ ##
9
+
10
+ after "deploy:published", "cachetool:opcache:status"
11
+ after "deploy:published", "cachetool:opcache:reset"
12
+
13
+ namespace :cachetool do
14
+ namespace :opcache do
15
+ desc "Resets the contents of the php-opcode cache"
16
+ task :reset do
17
+ on release_roles :all do
18
+ within release_path do
19
+ execute :cachetool, 'opcache:reset'
20
+ end
21
+ end
22
+ end
23
+
24
+ desc "Show information about the php-opcode cache"
25
+ task :status do
26
+ # Due to nature of the output, run this in sequence vs in parallel (the default) with shortest possible wait time
27
+ on release_roles(:all), in: :sequence, wait: 1 do
28
+ within release_path do
29
+ execute :cachetool, 'opcache:status'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -399,30 +399,61 @@ namespace :magento do
399
399
  end
400
400
  end
401
401
 
402
- # Internal command used to check if maintenance mode is neeeded and disable when zero-down deploy is possible
402
+ # Internal command used to check if maintenance mode is neeeded and disable when zero-down deploy is
403
+ # possible or when maintenance mode was previously enabled on the deploy target
403
404
  task :check do
404
405
  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
406
+ maintenance_enabled = nil
407
+ disable_maintenance = false # Do not disable maintenance mode in absence of positive release checks
408
+
409
+ if test "[ -d #{current_path} ]"
410
+ within current_path do
411
+ # If maintenance mode is already enabled, enable maintenance mode on new release and disable management to
412
+ # avoid disabling maintenance mode in the event it was manually enabled prior to deployment
413
+ info "Checking maintenance status..."
414
+ maintenance_status = capture :magento, 'maintenance:status', raise_on_non_zero_exit: false
415
+
416
+ if maintenance_status.to_s.include? 'maintenance mode is active'
417
+ info "Maintenance mode is currently active."
418
+ maintenance_enabled = true
419
+ else
420
+ info "Maintenance mode is currently inactive."
421
+ maintenance_enabled = false
422
+ end
423
+ info ""
424
+ end
425
+ end
426
+
427
+ # If maintenance is currently active, enable it on the newly deployed release
428
+ if maintenance_enabled
429
+ info "Enabling maintenance mode on new release to match active status of current release."
430
+ on release_roles :all do
431
+ within release_path do
432
+ execute :magento, 'maintenance:enable'
433
+ end
434
+ end
435
+ info ""
436
+ end
408
437
 
438
+ within release_path do
409
439
  # The setup:db:status command is only available in Magento 2.2.2 and later
410
440
  if not test :magento, 'setup:db:status --help >/dev/null 2>&1'
411
441
  info "Magento CLI command setup:db:status is not available. Maintenance mode will be used by default."
412
442
  else
413
443
  info "Checking database status..."
414
444
  # 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
445
+ database_status = capture :magento, 'setup:db:status', raise_on_non_zero_exit: false
416
446
 
417
447
  if database_status.to_s.include? 'All modules are up to date'
418
448
  info "All modules are up to date. No database updates should occur during this release."
419
- puts ""
449
+ info ""
420
450
  disable_maintenance = true
421
451
  else
422
452
  puts " #{database_status.gsub("\n", "\n ").sub("Run 'setup:upgrade' to update your DB schema and data.", "")}"
423
453
  end
424
454
 
425
455
  # Gather md5sums of app/etc/config.php on current and new release
456
+ info "Checking config status..."
426
457
  config_hash_release = capture :md5sum, "#{release_path}/app/etc/config.php"
427
458
  if test "[ -f #{current_path}/app/etc/config.php ]"
428
459
  config_hash_current = capture :md5sum, "#{current_path}/app/etc/config.php"
@@ -433,20 +464,27 @@ namespace :magento do
433
464
  # Output some informational messages showing the config.php hash values
434
465
  info "<release_path>/app/etc/config.php hash: #{config_hash_release.split(" ")[0]}"
435
466
  info "<current_path>/app/etc/config.php hash: #{config_hash_current.split(" ")[0]}"
436
- info ""
437
467
 
438
468
  # If hashes differ, maintenance mode should not be disabled even if there are no database changes.
439
469
  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."
470
+ info "Maintenance mode will not be disabled (config hashes differ)."
441
471
  disable_maintenance = false
442
472
  end
473
+ info ""
474
+ end
443
475
 
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
476
+ if maintenance_enabled or disable_maintenance
477
+ info "Disabling maintenance mode management..."
478
+ end
479
+
480
+ if maintenance_enabled
481
+ info "Maintenance mode was already active prior to deploy."
482
+ set :magento_deploy_maintenance, false
483
+ elsif disable_maintenance
484
+ info "There are no database updates or config changes. This is a zero-down deployment."
485
+ set :magento_deploy_maintenance, false
486
+ else
487
+ info "Maintenance mode usage will be enforced per :magento_deploy_maintenance (setting is #{fetch(:magento_deploy_maintenance).to_s})"
450
488
  end
451
489
  end
452
490
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-magento2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Alger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-19 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -70,11 +70,13 @@ files:
70
70
  - capistrano-magento2.gemspec
71
71
  - lib/capistrano-magento2.rb
72
72
  - lib/capistrano/magento2.rb
73
+ - lib/capistrano/magento2/cachetool.rb
73
74
  - lib/capistrano/magento2/defaults.rb
74
75
  - lib/capistrano/magento2/deploy.rb
75
76
  - lib/capistrano/magento2/notifier.rb
76
77
  - lib/capistrano/magento2/pending.rb
77
78
  - lib/capistrano/magento2/version.rb
79
+ - lib/capistrano/tasks/cachetool.rake
78
80
  - lib/capistrano/tasks/deploy.rake
79
81
  - lib/capistrano/tasks/magento.rake
80
82
  - lib/capistrano/tasks/notifier.rake