capistrano-sozo_magento2 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c002ac19f8884287b44aadbb34cf283f58b3d601482a636f43ad2de645815608
4
+ data.tar.gz: c0f0053697d68c11921417d67f0a1ed27a193322be4b2d892db8789c41f9084b
5
+ SHA512:
6
+ metadata.gz: 946959dc1c096e3eb3417791c6c9662e450632a16acb08b4119821823692b8531933c0a6c9ad6adaf1131abef3211354a4ebaf06f3610b5a779965d234706259
7
+ data.tar.gz: 9075f0fdd973e7bde74ef954dd40220642016219693b910fade75a513279845c512c8421411d49c454d93926efebc24c473c5000b0749f55ae9f44c9fe5f0207
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ #Capistrano::SozoMagento2
2
+
3
+ ## Installation
4
+ It is advised to use bundler.
5
+
6
+ 1. Add the following to your projects `Gemfile`
7
+ ```
8
+ gem 'capistrano-sozo-magento2'
9
+ ```
10
+ 2. Install
11
+ ```
12
+ bundle install
13
+ ```
14
+
15
+ ## Usage
16
+ Make sure the following lines are added to your project's `Capfile`:
17
+ ```
18
+ # Load SOZO Magento tasks
19
+ require 'capistrano/sozo-magento2'
20
+ ```
21
+ We recommend putting them in the following location:
22
+ ```
23
+ # Load DSL and set up stages
24
+ require 'capistrano/setup'
25
+
26
+ # Load SOZO Magento tasks
27
+ require 'capistrano/sozo-magento2'
28
+
29
+ # Include default deployment tasks
30
+ require 'capistrano/deploy'
31
+
32
+ require "capistrano/scm/git"
33
+ install_plugin Capistrano::SCM::Git
34
+ ```
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "capistrano/sozo_magento2/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-sozo_magento2"
8
+ spec.version = Capistrano::SozoMagento2::VERSION
9
+ spec.authors = ["Clive Walkden"]
10
+ spec.email = ["clive@sozodesign.co.uk"]
11
+ spec.description = %q{Magento 2 support for Capistrano 3.x in SOZO hosted environments}
12
+ spec.summary = %q{Magento 2 support for Capistrano 3.x in SOZO hosted environments}
13
+ spec.homepage = "https://github.com/sozodesign/capistrano-sozo-magento2"
14
+ spec.license = "Proprietary"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(build|test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "capistrano", "~> 3.9"
22
+ spec.add_dependency "dotenv", "~> 2.2"
23
+ end
@@ -0,0 +1,53 @@
1
+ require 'date'
2
+ require 'dotenv'
3
+ Dotenv.load
4
+
5
+ SSHKit.config.command_map[:composer] = 'php -dmemory_limit=-1 -f /usr/local/bin/composer'
6
+ SSHKit.config.command_map[:n98magerun] = '/usr/local/bin/n98-magerun'
7
+ SSHKit.config.command_map[:magento] = "/usr/bin/env php -d memory_limit=1G -f bin/magento --"
8
+
9
+ load File.expand_path('../tasks/sozo_magento2.rake', __FILE__)
10
+ load File.expand_path('../tasks/deploy.rake', __FILE__)
11
+ load File.expand_path('../tasks/composer.rake', __FILE__)
12
+ load File.expand_path('../tasks/sozo.rake', __FILE__)
13
+ load File.expand_path('../tasks/slack.rake', __FILE__)
14
+ load File.expand_path('../tasks/db.rake', __FILE__)
15
+ load File.expand_path('../tasks/fishpig.rake', __FILE__)
16
+ load File.expand_path('../tasks/magento2.rake', __FILE__)
17
+ load File.expand_path('../tasks/provision.rake', __FILE__)
18
+ load File.expand_path('../tasks/server.rake', __FILE__)
19
+ load File.expand_path('../tasks/wordpress.rake', __FILE__)
20
+
21
+ after 'deploy:updating', 'composer:install'
22
+ after 'composer:install', 'magento:setup:permissions'
23
+
24
+ before 'deploy:updated', 'slack:deploying'
25
+ after 'slack:deploying', 'db:backup'
26
+ after 'db:backup', 'sozo:config:setup'
27
+ after 'sozo:config:setup', 'magento:maintenance:enable'
28
+
29
+ after 'deploy:updated', 'provision:setup_dir'
30
+ after 'provision:setup_dir', 'magento:setup:upgrade'
31
+ after 'magento:setup:upgrade', 'magento:setup:di:compile'
32
+ after 'magento:setup:di:compile', 'magento:setup:static-content:deploy'
33
+ after 'magento:setup:static-content:deploy', 'provision:permissions'
34
+
35
+ after 'deploy:finishing', 'sozo:symlink'
36
+ after 'sozo:symlink', 'fishpig:setup:install_theme'
37
+ after 'fishpig:setup:install_theme', 'wordpress:sozo_mu'
38
+ after 'wordpress:sozo_mu', 'wordpress:cleanup'
39
+ after 'wordpress:cleanup', 'sozo:optimise'
40
+ after 'sozo:optimise', 'server:service:restart'
41
+ after 'server:service:restart', 'magento:maintenance:disable'
42
+
43
+ after 'deploy:finished', "slack:deployed"
44
+ after 'slack:deployed', "db:cleanup"
45
+
46
+ after 'deploy:failed', "slack:failed"
47
+ after 'slack:failed', 'magento:maintenance:disable'
48
+
49
+ namespace :load do
50
+ task :defaults do
51
+ load 'capistrano/sozo_magento2/defaults.rb'
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+ set :linked_files, fetch(:linked_files, []).push()
2
+
3
+ set :linked_dirs, fetch(:linked_dirs, []).push(
4
+ 'magento/pub/media',
5
+ 'magento/pub/sitemap',
6
+ 'magento/var/amasty/geoip',
7
+ 'magento/var/backups',
8
+ 'magento/var/composer_home',
9
+ 'magento/var/importexport',
10
+ 'magento/var/import_history',
11
+ 'magento/var/export',
12
+ 'magento/var/log',
13
+ 'magento/var/nginx',
14
+ 'magento/var/report',
15
+ 'magento/var/session',
16
+ 'magento/var/tmp',
17
+ 'magento/wp/wp-content/uploads'
18
+ )
19
+
20
+ # Composer defaults
21
+ set :composer_flags, '--no-dev --optimize-autoloader --prefer-dist --no-interaction --no-suggest'
22
+ set :composer_dev_flags, '--prefer-dist --no-interaction --no-suggest'
23
+ set :composer_require_flags, '--update-no-dev --optimize-autoloader --prefer-dist --no-suggest'
24
+ set :composer_require_dev_flags, '--optimize-autoloader --prefer-dist'
25
+
26
+ # DB defaults
27
+ set :date_path, Time.now.strftime("%Y%m%d%H%M%S")
28
+ set :backupdir, ->{ "#{fetch(:deploy_root)}/backups" }
29
+ set :backupdirdate, ->{ "#{fetch(:backupdir)}/#{fetch(:date_path)}" }
30
+ set :wp_db, ->{ ENV['WPDB_DATABASE'] }
31
+ set :wp_backup, ->{ ENV['WPDB_BACKUP'] }
32
+ set :keep_backups, ->{ ENV['CAP_KEEP_BACKUPS'] }
33
+
34
+ # Slack defaults
35
+ set :slack_channel, ENV['SLACK_CHANNEL']
36
+ set :slack_webhook, 'https://hooks.slack.com/services/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'
37
+
38
+ # Deployment defaults
39
+ set :confirm_deploy, fetch(:magento_deploy_confirm, [])
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module SozoMagento2
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ namespace :composer do
2
+ desc "Install the Composer dependencies"
3
+ task :install do
4
+ on roles :testing, :staging do
5
+ within release_path + 'magento/' do
6
+ execute :composer, "install", fetch(:composer_dev_flags)
7
+ end
8
+ end
9
+
10
+ on roles(:production) do
11
+ within release_path + 'magento/' do
12
+ execute :composer, "install", fetch(:composer_flags)
13
+ end
14
+ end
15
+ end
16
+
17
+ desc "Update the Composer dependencies"
18
+ task :update do
19
+ on roles :testing, :staging do
20
+ within release_path + 'magento/' do
21
+ execute :composer, "update", fetch(:composer_dev_flags)
22
+ end
23
+ end
24
+
25
+ on roles(:production) do
26
+ within release_path + 'magento/' do
27
+ execute :composer, "update", fetch(:composer_flags)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,50 @@
1
+ namespace :db do
2
+ desc "Backup Magento 2 database"
3
+ task :backup do
4
+ # Backup the database with a timestamp
5
+ on roles :all do
6
+ # Check if the backup directory exists and if not create it
7
+ if test("[ ! -d #{fetch(:backupdir)} ]")
8
+ execute :mkdir, "-p", fetch(:backupdir)
9
+ end
10
+
11
+ # Backup using n98-magerun but don't include the logs or sessions data
12
+ info "Backing up Magento database."
13
+ execute :n98magerun, 'db:dump', "--root-dir='#{fetch(:mage_root)}'",
14
+ '--compression="gzip"',
15
+ '--strip="@log @sessions"',
16
+ '--force', "#{fetch(:backupdir)}/#{fetch(:date_path)}_m2.sql.gz"
17
+
18
+ if ENV['WPDB_BACKUP'] == "true"
19
+ info "Backing up WordPress database."
20
+ execute :n98magerun, 'db:dump', "--root-dir='#{fetch(:mage_root)}'",
21
+ '--compression="gzip"',
22
+ '--connection="wordpress"',
23
+ '--force', "#{fetch(:backupdir)}/#{fetch(:date_path)}_wp.sql.gz"
24
+ end
25
+ end
26
+ end
27
+
28
+ desc "Clean up old backups"
29
+ task :cleanup do
30
+ on roles :all do
31
+ backups = capture(:ls, "-x", "#{fetch(:backupdir)}").split
32
+ valid, invalid = backups.partition { |e| /^\d{14}/ =~ e }
33
+
34
+ info "Found #{valid.count} valid backups."
35
+
36
+ if (valid.count >= fetch(:keep_backups).to_i)
37
+ info "Keeping #{fetch(:keep_backups)} of #{valid.count} backups."
38
+ files = (valid - valid.last(fetch(:keep_backups).to_i)).map do |backup|
39
+ "#{fetch(:backupdir)}" + "/" + (backup).to_s
40
+ end
41
+ end
42
+
43
+ if files.any?
44
+ files.each_slice(100) do |files_batch|
45
+ execute :rm, "-f", *files_batch
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,49 @@
1
+ namespace :deploy do
2
+ before :starting, :confirm_action do
3
+ if fetch(:magento_deploy_confirm).include? fetch(:stage).to_s
4
+ print "\e[0;31m Are you sure you want to deploy to #{fetch(:stage).to_s}? [y/n] \e[0m"
5
+ proceed = STDIN.gets[0..0] rescue nil
6
+ exit unless proceed == 'y' || proceed == 'Y'
7
+ end
8
+ end
9
+
10
+
11
+ Rake::Task["cleanup"].clear_actions
12
+
13
+ desc "Clean up old releases"
14
+ task :cleanup do
15
+ on release_roles :all do |host|
16
+ releases = capture(:ls, "-x", releases_path).split
17
+ valid, invalid = releases.partition { |e| /^\d{14}$/ =~ e }
18
+ keep = fetch(:keep_releases).to_i
19
+
20
+ warn t(:skip_cleanup, host: host.to_s) if invalid.any?
21
+
22
+ if valid.count >= keep
23
+ info t(:keeping_releases, host: host.to_s, keep_releases: keep, releases: valid.count)
24
+ directories = (valid - valid.last(keep))
25
+ if directories.any?
26
+ directories_str = directories.map do |release|
27
+ releases_path.join(release)
28
+ end.join(" ")
29
+ execute :sudo, 'rm', "-rf", directories_str
30
+ # TODO re-symlink the old directory
31
+ else
32
+ info t(:no_old_releases, host: host.to_s, keep_releases: keep)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ Rake::Task["failed"].clear_actions
39
+
40
+ desc "Failed deployment tasks"
41
+ task :failed do
42
+ on release_roles :all do |host|
43
+ on roles :production, :staging, :testing do
44
+ execute :rm, '-rf', release_path
45
+ info "Removed failed deployment"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ namespace :fishpig do
2
+ namespace :setup do
3
+ desc "Install the Wordpress Fishpig theme"
4
+ task :install_theme do
5
+ on roles :all do |host|
6
+ within release_path do
7
+ execute :mkdir, "-p", "#{release_path}/magento/wp/wp-content/themes/fishpig"
8
+ end
9
+ end
10
+
11
+ on roles(:all) do
12
+ execute :sudo, 'cp', '-a', "#{release_path}/environments/global/wp/wp-content/themes/fishpig/.", "#{release_path}/magento/wp/wp-content/themes/fishpig/"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,247 @@
1
+ namespace :magento do
2
+
3
+ namespace :cache do
4
+ desc 'Flush Magento cache storage'
5
+ task :flush do
6
+ on release_roles :all do
7
+ within release_path do
8
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'cache:flush'
9
+ end
10
+ end
11
+ end
12
+
13
+ desc 'Clean Magento cache by types'
14
+ task :clean do
15
+ on release_roles :all do
16
+ within release_path do
17
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'cache:clean'
18
+ end
19
+ end
20
+ end
21
+
22
+ desc 'Enable all Magento cache'
23
+ task :enable do
24
+ on release_roles :all do
25
+ within release_path do
26
+ if File.exist?("magento/bin/magento")
27
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'cache:enable', 'config layout block_html collections reflection db_ddl eav config_integration config_integration_api full_page translate config_webservice'
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ desc 'Disable Magento cache'
34
+ task :disable do
35
+ on release_roles :all do
36
+ within release_path do
37
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'cache:disable'
38
+ end
39
+ end
40
+ end
41
+
42
+ desc 'Check Magento cache enabled status'
43
+ task :status do
44
+ on release_roles :all do
45
+ within release_path do
46
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'cache:status'
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ namespace :composer do
53
+ desc 'Run composer install'
54
+ task :install do
55
+ on release_roles :all do
56
+ within release_path + 'magento/' do
57
+ execute :composer, 'install --prefer-dist --no-interaction --no-dev 2>&1'
58
+ execute :composer, "#{fetch(:composer_requirements)}"
59
+
60
+ # Dir should be here if properly setup, but check for it anyways just in case
61
+ if test "[ -d #{release_path}/update ]"
62
+ execute :composer, 'install --prefer-dist --no-interaction --no-dev -d ./update 2>&1'
63
+ else
64
+ puts "\e[0;31m Warning: ./update dir does not exist in repository!\n\e[0m\n"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ namespace :modules do
72
+ desc 'Make sure modules are enabled'
73
+ task :enable_all do
74
+ on release_roles :staging do
75
+ within release_path + 'magento/' do
76
+ if test("[ -f #{release_path}/magento/app/etc/config.php ]")
77
+ # Exists, carry on
78
+ else
79
+ execute :php, '-dmemory_limit=-1', '-f', 'bin/magento', "module:enable", "--all"
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ desc 'Disable a module'
86
+ task 'disable', :module_name do |t, args|
87
+ on release_roles :staging do
88
+ within release_path + 'magento/' do
89
+ execute :php, '-dmemory_limit=-1', '-f', 'bin/magento', "module:disable", args[:module_name]
90
+ end
91
+ end
92
+ end
93
+
94
+ desc 'Enable a module'
95
+ task 'enable', :module_name do |t, args|
96
+ on release_roles :staging do
97
+ within release_path + 'magento/' do
98
+ execute :php, '-dmemory_limit=-1', '-f', 'bin/magento', "module:enable", args[:module_name], '-f'
99
+ invoke 'magento:setup:upgrade'
100
+ invoke 'magento:setup:static-content:deploy'
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ namespace :setup do
107
+
108
+ namespace :config do
109
+ desc 'Set a config item'
110
+ task :set do
111
+ on roles(:all) do
112
+ within release_path + 'magento/' do
113
+ ask(:parameter, '')
114
+ ask(:value, '')
115
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', "setup:config:set", "--#{fetch(:parameter)}=#{fetch(:value)}", "--no-interaction"
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ desc 'Composer install the deployed version of the composer file'
122
+ task :deployment do
123
+ on roles(:all) do
124
+ within release_path + 'magento/' do
125
+ invoke 'composer:install'
126
+ end
127
+ end
128
+ end
129
+
130
+ desc 'Run the Magento upgrade process'
131
+ task :upgrade do
132
+ on release_roles :all do
133
+ within release_path do
134
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'setup:upgrade', '-n'
135
+ end
136
+ end
137
+ end
138
+
139
+ desc 'Sets proper permissions on application'
140
+ task :permissions do
141
+ on release_roles(:staging, :production) do
142
+ within release_path do
143
+ execute :find, release_path, '-type d -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 770'
144
+ execute :find, release_path, '-type f -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 660'
145
+ execute :chmod, '-R g+s', release_path
146
+ execute :chmod, '+x', "#{release_path}/magento/bin/magento"
147
+ end
148
+ end
149
+
150
+ on release_roles(:testing) do
151
+ within release_path do
152
+ execute :find, release_path, '-type d -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 777'
153
+ execute :find, release_path, '-type f -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 666'
154
+ execute :chmod, '-R g+s', release_path
155
+ execute :chmod, '+x', "#{release_path}/magento/bin/magento"
156
+ end
157
+ end
158
+ end
159
+
160
+ desc 'Sets proper permissions on application'
161
+ task :ownership do
162
+ on roles(:testing, :production) do
163
+ within release_path do
164
+ execute :sudo, 'chown', "#{fetch(:username)}:#{fetch(:group)}", '-R', "#{release_path}"
165
+ execute :sudo, 'chown', "#{fetch(:username)}:#{fetch(:group)}", '-R', "#{deploy_to}/shared"
166
+ end
167
+ end
168
+ end
169
+
170
+ namespace :di do
171
+ desc 'Runs dependency injection compilation routine'
172
+ task :compile do
173
+ on release_roles :all do
174
+ within release_path do
175
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'setup:di:compile'
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ namespace 'static-content' do
182
+ desc 'Deploys static view files'
183
+ task :deploy do
184
+ on release_roles :all do
185
+ within release_path do
186
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'setup:static-content:deploy -f en_US en_GB -j6'
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ # @TODO these below functions target the current directory which may not exist on first deployment
194
+ namespace :maintenance do
195
+ desc 'Enable maintenance mode'
196
+ task :enable do
197
+ on release_roles :all do
198
+ within current_path do
199
+ if File.exist?("magento/bin/magento")
200
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'maintenance:enable'
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ desc 'Disable maintenance mode'
207
+ task :disable do
208
+ on release_roles :all do
209
+ within current_path do
210
+ if File.exist?("magento/bin/magento")
211
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'maintenance:disable'
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ desc 'Displays maintenance mode status'
218
+ task :status do
219
+ on release_roles :all do
220
+ within current_path do
221
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'maintenance:status'
222
+ end
223
+ end
224
+ end
225
+
226
+ desc 'Sets maintenance mode exempt IPs'
227
+ task 'allow-ips', :ip do |t, args|
228
+ on release_roles :all do
229
+ within current_path do
230
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'maintenance:allow-ips', args[:ip]
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ namespace :indexer do
237
+ desc 'Reindex data by all indexers'
238
+ task :reindex do
239
+ on release_roles :all do
240
+ within release_path do
241
+ execute :php, '-dmemory_limit=-1', '-f', 'magento/bin/magento', 'indexer:reindex'
242
+ end
243
+ end
244
+ end
245
+ end
246
+
247
+ end
@@ -0,0 +1,43 @@
1
+ namespace :provision do
2
+ desc "Setup the shared directory content"
3
+ task :shared do
4
+ invoke 'sozo:upload:dirs'
5
+ invoke 'sozo:upload:files'
6
+ end
7
+
8
+ desc "Setup permissions on the account"
9
+ task :permissions do
10
+ on release_roles :all do
11
+ within release_path do
12
+ execute :sudo, 'chown', "#{fetch(:username)}:#{fetch(:group)}", "#{release_path}/"
13
+ execute :sudo, "find", "#{deploy_to}/shared", '-not \(', "-name '#{fetch(:username)}' -or -group '#{fetch(:group)}'", '\) -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chown', "#{fetch(:username)}:#{fetch(:group)}"
14
+ execute :sudo, "chmod", "770 #{release_path}/"
15
+ execute :sudo, "find", "#{release_path}/magento", '-type d -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 770'
16
+ execute :sudo, "find", "#{release_path}/magento", '-type f -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chmod 660'
17
+
18
+ if test("[ -f #{release_path}/magento/bin/magento ]")
19
+ execute :sudo, "chmod", "+x", "#{release_path}/magento/bin/magento"
20
+ end
21
+
22
+ execute :sudo, "find", "#{release_path}/magento", '-print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chown', "#{fetch(:username)}:#{fetch(:group)}"
23
+
24
+ # Update symlinks permission
25
+ execute :sudo, "find", "#{release_path}/magento", '-type l', '-not \(', "-name '#{fetch(:username)}' -or -group '#{fetch(:group)}'", '\) -print0 | sudo xargs --no-run-if-empty --null --max-procs=0 chown', '-h', "#{fetch(:username)}:#{fetch(:group)}"
26
+ end
27
+ end
28
+ end
29
+
30
+ desc "Missing setup directory fix"
31
+ task :setup_dir do
32
+ on roles :app do
33
+ info ("Checking for setup directory - #{release_path}/magento/setup")
34
+
35
+ if test("[ -d #{release_path}/magento/setup/ ]")
36
+ else
37
+ upload! "#{fetch(:magento_dir)}/setup", "#{release_path}/magento/", recursive: true
38
+ invoke 'provision:permissions'
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,18 @@
1
+ namespace :server do
2
+ namespace :service do
3
+ desc "Restart the server services"
4
+ task :restart do
5
+ on roles(:gcloud, :aws, :cloud, :dedicated) do
6
+ within release_path do
7
+ execute :sudo, "systemctl", "restart", "php-fpm"
8
+ execute :sudo, "systemctl", "restart", "nginx"
9
+ end
10
+ end
11
+ on roles(:cluster) do
12
+ within release_path do
13
+ execute :sudo, "nginx", "-s", "reload"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ namespace :slack do
2
+ desc "Post to channel that the site has been deployed"
3
+ task :deployed do
4
+ on roles(:all) do
5
+ execute :curl, "-X", "POST", "--data-urlencode", "'payload={\"channel\": \"#{fetch(:slack_channel)}\", \"username\": \"SOZO Deploy Bot\", \"pretext\": \"Deployment Successful\", \"text\": \"<#{fetch(:url)}> Deployed\", \"icon_emoji\": \":satellite:\", \"color\": \"good\", \"fields\": [{ \"title\": \"Branch\", \"value\": \"#{fetch(:branch)}\", \"short\": \"true\" },{ \"title\": \"Environment\", \"value\": \"#{fetch(:environment)}\", \"short\": \"true\" }]}'", "#{fetch(:slack_webhook)}"
6
+ end
7
+ end
8
+
9
+ desc "Post to channel that the site is being deployed"
10
+ task :deploying do
11
+ on roles(:all) do
12
+ execute :curl, "-X", "POST", "--data-urlencode", "'payload={\"channel\": \"#{fetch(:slack_channel)}\", \"username\": \"SOZO Deploy Bot\", \"pretext\": \"Deployment Process Begun\", \"text\": \"<#{fetch(:url)}> is being Deployed\", \"icon_emoji\": \":satellite:\", \"color\": \"warning\", \"fields\": [{ \"title\": \"Branch\", \"value\": \"#{fetch(:branch)}\", \"short\": \"true\" },{ \"title\": \"Environment\", \"value\": \"#{fetch(:environment)}\", \"short\": \"true\" }]}'", "#{fetch(:slack_webhook)}"
13
+ end
14
+ end
15
+
16
+ desc "Post to channel that something is happening"
17
+ task :message do
18
+ on roles(:all) do
19
+ execute :curl, "-X", "POST", "--data-urlencode", "'payload={\"channel\": \"#{fetch(:slack_channel)}\", \"username\": \"SOZO Deploy Bot\", \"pretext\": \"Next stage\", \"text\": \"<#{fetch(:url)}> is stage change\", \"icon_emoji\": \":satellite:\", \"color\": \"good\", \"fields\": [{ \"title\": \"Branch\", \"value\": \"#{fetch(:branch)}\", \"short\": \"true\" },{ \"title\": \"Environment\", \"value\": \"#{fetch(:environment)}\", \"short\": \"true\" }]}'", "#{fetch(:slack_webhook)}"
20
+ end
21
+ end
22
+
23
+ desc "Post to channel that the site deployment has failed"
24
+ task :failed do
25
+ on roles(:all) do
26
+ execute :curl, "-X", "POST", "--data-urlencode", "'payload={\"channel\": \"#{fetch(:slack_channel)}\", \"username\": \"SOZO Deploy Bot\", \"pretext\": \"Deployment Process Failed\", \"text\": \"<#{fetch(:url)}> deployment has failed\", \"icon_emoji\": \":satellite:\", \"color\": \"warning\", \"fields\": [{ \"title\": \"Branch\", \"value\": \"#{fetch(:branch)}\", \"short\": \"true\" },{ \"title\": \"Environment\", \"value\": \"#{fetch(:environment)}\", \"short\": \"true\" }]}'", "#{fetch(:slack_webhook)}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,143 @@
1
+ namespace :sozo do
2
+
3
+ desc "Fix current directory if needed"
4
+ task :fix_current do
5
+ on roles(:all) do
6
+ releases = capture(:ls, "-x", releases_path).split
7
+ valid, invalid = releases.partition { |e| /^\d{14}$/ =~ e }
8
+
9
+ info "last release #{valid.last}"
10
+ info "Creating symlink from #{fetch(:deploy_to)}/releases/#{valid.last} to #{fetch(:deploy_to)}/current"
11
+
12
+ execute :ln, "-sf", "#{fetch(:deploy_to)}/releases/#{valid.last}", "#{fetch(:deploy_to)}/current"
13
+ end
14
+ end
15
+
16
+ desc "Move database connection files into place"
17
+ task :db_conn do
18
+ on roles(:all) do
19
+ within release_path do
20
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/app/etc/env.php", "#{release_path}/magento/app/etc/"
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Symlink the deployment to live"
26
+ task :symlink do
27
+ on roles :all do |host|
28
+ within release_path do
29
+ execute :rm, "-rf", "#{fetch(:mage_root)}", "&&", "ln", "-s", "#{release_path}/magento/", "#{fetch(:mage_root)}"
30
+
31
+ # Setup uploads
32
+ execute :ln, "-s", "#{fetch(:deploy_to)}/shared/magento/wp/wp-content/uploads", "#{release_path}/magento/wp/wp-content"
33
+
34
+ # Sitemap
35
+ execute :ln, "-sf", "#{fetch(:deploy_to)}/shared/magento/sitemap/", "#{release_path}/magento/"
36
+ execute :ln, "-sf", "#{fetch(:deploy_to)}/shared/magento/sitemap/", "#{release_path}/magento/pub/"
37
+ end
38
+ end
39
+
40
+ on roles :all do |host|
41
+ execute :ln, "-s", "#{fetch(:deploy_to)}/shared/magento/pub/.well-known", "#{release_path}/magento/pub/.well-known"
42
+ end
43
+
44
+ invoke! "sozo:fix_current"
45
+ end
46
+
47
+ desc "Production tasks"
48
+ task :optimise do
49
+ on roles :all do |host|
50
+ within release_path do
51
+ execute :rm, "-rf", "{.git*,*.sample,.ruby-version,*.md,Capfile,Gemfile*,deployment,dev,development,magento/*.sample}"
52
+
53
+ invoke!('provision:permissions')
54
+ end
55
+ end
56
+ on roles :production do
57
+ within release_path do
58
+ invoke 'magento:cache:enable'
59
+ invoke 'magento:cache:flush'
60
+ invoke 'magento:indexer:reindex'
61
+ end
62
+ end
63
+ end
64
+
65
+ namespace :config do
66
+ desc "Config file updates"
67
+ task :setup do
68
+ on roles(:all) do
69
+ within release_path do
70
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/pub/robots.txt", "#{release_path}/magento/pub/"
71
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/app/etc/env.php", "#{release_path}/magento/app/etc/"
72
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/pub/errors/local.xml", "#{release_path}/magento/pub/errors/"
73
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/wp/wp-config.php", "#{release_path}/magento/wp/wp-config.php"
74
+ end
75
+ end
76
+ on roles(:staging) do
77
+ within release_path do
78
+ execute :cp, "#{release_path}/environments/#{fetch(:environment)}/.htpasswd", "#{release_path}/magento/.htpasswd"
79
+ end
80
+ end
81
+ end
82
+
83
+ desc "Git Check"
84
+ task :git do
85
+ run_locally do
86
+ git = capture('git rev-parse HEAD')
87
+ last = capture('git rev-parse HEAD~1')
88
+ end
89
+ end
90
+ end
91
+
92
+ desc "Check to see if the setup directory has content"
93
+ task :setup_check do
94
+ on roles(:all) do
95
+ f = "#{fetch(:deploy_to)}/.setup"
96
+
97
+ within release_path do
98
+ if test("[ -f #{f} ]")
99
+ info "First Deploy File Exists"
100
+ set :first_deploy, 1
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ desc 'Upload linked files and directories'
107
+ task :upload do
108
+ invoke 'sozo:upload:dirs'
109
+ invoke 'sozo:upload:files'
110
+ end
111
+
112
+ task :upload_files do
113
+ invoke 'sozo:upload:files'
114
+ end
115
+
116
+ task :upload_dirs do
117
+ invoke 'sozo:upload:dirs'
118
+ end
119
+
120
+ namespace :upload do
121
+
122
+ task :files do
123
+ on roles :app do
124
+ fetch(:linked_files, []).each do |file|
125
+ upload! "#{file}", "#{shared_path}/#{file}"
126
+ end
127
+ end
128
+ end
129
+
130
+ task :dirs do
131
+ on roles :app do
132
+ fetch(:linked_dirs, []).each do |dir|
133
+ info "DIR: #{dir}"
134
+ upload! "#{dir}", "#{shared_path}/", recursive: true
135
+ end
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ before 'sozo:upload', 'deploy:check:make_linked_dirs'
142
+
143
+ end
File without changes
@@ -0,0 +1,24 @@
1
+ namespace :wordpress do
2
+
3
+ desc "Install the SOZO MU plugins to stop frontend output when logged into WordPress"
4
+ task :sozo_mu do
5
+ on roles(:all) do
6
+ execute :cp, '-a', "#{release_path}/environments/global/wp/wp-content/mu-plugins/.", "#{release_path}/magento/wp/wp-content/mu-plugins/"
7
+ end
8
+ end
9
+
10
+ desc "Tidy up the installation (remove un-needed files)"
11
+ task :cleanup do
12
+ on roles :all do |host|
13
+ within release_path + "magento/wp/" do
14
+ info "Removing default unused WordPress Plugins and Themes"
15
+ execute :wp, 'plugin', 'delete', 'hello'
16
+ execute :wp, 'theme', 'delete', 'twentyseventeen'
17
+ execute :wp, 'theme', 'delete', 'twentynineteen'
18
+ execute :wp, 'theme', 'delete', 'twentytwenty'
19
+ execute :rm, '-f', 'readme.html'
20
+ end
21
+ end
22
+ end
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-sozo_magento2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Clive Walkden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ description: Magento 2 support for Capistrano 3.x in SOZO hosted environments
42
+ email:
43
+ - clive@sozodesign.co.uk
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - capistrano-sozo_magento.gemspec
53
+ - lib/capistrano/sozo_magento2.rb
54
+ - lib/capistrano/sozo_magento2/defaults.rb
55
+ - lib/capistrano/sozo_magento2/version.rb
56
+ - lib/capistrano/tasks/composer.rake
57
+ - lib/capistrano/tasks/db.rake
58
+ - lib/capistrano/tasks/deploy.rake
59
+ - lib/capistrano/tasks/fishpig.rake
60
+ - lib/capistrano/tasks/magento2.rake
61
+ - lib/capistrano/tasks/provision.rake
62
+ - lib/capistrano/tasks/server.rake
63
+ - lib/capistrano/tasks/slack.rake
64
+ - lib/capistrano/tasks/sozo.rake
65
+ - lib/capistrano/tasks/sozo_magento2.rake
66
+ - lib/capistrano/tasks/wordpress.rake
67
+ homepage: https://github.com/sozodesign/capistrano-sozo-magento2
68
+ licenses:
69
+ - Proprietary
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Magento 2 support for Capistrano 3.x in SOZO hosted environments
91
+ test_files: []