wslave 0.0.15 → 0.2.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 +5 -5
- data/base/.gitignore +5 -0
- data/base/Rakefile +22 -6
- data/base/config/deploy-tools/gen-nginx-vhost.rb +11 -0
- data/base/config/deploy-tools/nginx.vhost.erb +51 -0
- data/base/config/deploy.rb +1 -1
- data/base/config/deploy/production.rb +135 -7
- data/base/config/deploy/staging.rb +135 -8
- data/base/docker-compose.yml +14 -9
- data/base/{Dockerfile → docker/apache/Dockerfile} +2 -4
- data/base/docker/nginx/Dockerfile +24 -0
- data/base/docker/nginx/nginx.vhost +48 -0
- data/base/docker/nginx/supervisord.conf +23 -0
- data/base/public/.htaccess +11 -0
- data/bin/wslave +76 -22
- data/lib/wslave_docker.rb +34 -3
- data/lib/wslave_new.rb +48 -9
- data/lib/wslave_sage.rb +70 -3
- data/lib/wslave_tools.rb +0 -1
- data/lib/wslave_update.rb +2 -2
- data/templates/config/definitions.yml +6 -1
- data/wslave.gemspec +9 -6
- metadata +78 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f166ebdd86359e239e14471ae7eabe907ac34adae44529e1e420f437feee2a32
|
4
|
+
data.tar.gz: 42e606369d33accbaf8fa6a00428547b45c340d437bfb543af674dbe9e05f2bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ed2dad207e47644c602cf9017c465166dd504bd054d1f0f4be37f8c455fd1177a4e455ea981f8d49c1ca6fa251b8388f2ab1f1866be1d37a2ba4c432d730d3d
|
7
|
+
data.tar.gz: 6d2333831378f71024e36f56fc960260369427c42f7b93404ff4901d8f8878310f8884815155ab9aac7e43aa41d8b33a4db7db2497e55347516c9840d6c6b31b
|
data/base/Rakefile
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
@opts = YAML.load_file('config/definitions.yml')
|
2
5
|
|
3
6
|
def rm_dbfile(profile)
|
4
7
|
puts "Deleting db/#{profile}/wordpress.sql"
|
@@ -34,6 +37,7 @@ namespace :db do
|
|
34
37
|
task :activate do
|
35
38
|
rm_dbfile('active')
|
36
39
|
FileUtils.cp('db/staging/wordpress.sql', 'db/active/wordpress.sql')
|
40
|
+
_replace_active_urls
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -42,24 +46,36 @@ namespace :db do
|
|
42
46
|
task :activate do
|
43
47
|
rm_dbfile('active')
|
44
48
|
FileUtils.cp('db/production/wordpress.sql', 'db/active/wordpress.sql')
|
49
|
+
_replace_active_urls
|
45
50
|
end
|
46
51
|
end
|
52
|
+
|
53
|
+
# Converts staging and production URL entries in DB backup with localhost:8000
|
54
|
+
def _replace_active_urls()
|
55
|
+
puts 'Replacing Production and Staging URLs for local development/re-deployment...'
|
56
|
+
db_data = File.read('db/active/wordpress.sql')
|
57
|
+
|
58
|
+
if @opts['deployer']['fqdn']['staging'] != ''
|
59
|
+
db_data = db_data.gsub(/#{@opts['deployer']['fqdn']['staging']}/, 'localhost:8000')
|
60
|
+
end
|
61
|
+
if @opts['deployer']['fqdn']['production'] != ''
|
62
|
+
db_data = db_data.gsub(/#{@opts['deployer']['fqdn']['production']}/, 'localhost:8000')
|
63
|
+
end
|
64
|
+
|
65
|
+
File.open('db/active/wordpress.sql', "w") {|file| file.puts db_data }
|
66
|
+
end
|
47
67
|
end
|
48
68
|
|
49
69
|
namespace :staging do
|
50
70
|
desc 'Open an SSH session to the staging host in the staging directory'
|
51
71
|
task :ssh do
|
52
|
-
|
53
|
-
opts = YAML.load_file('config/definitions.yml')
|
54
|
-
exec("ssh #{opts['deployer']['user']}@#{opts['deployer']['host']['staging']} -t \"cd #{opts['deployer']['root']}/#{opts['deployer']['fqdn']['staging']}; exec \$SHELL -l\"")
|
72
|
+
exec("ssh #{@opts['deployer']['user']}@#{@opts['deployer']['host']['staging']} -t \"cd #{@opts['deployer']['root']}/#{@opts['deployer']['fqdn']['staging']}; exec \$SHELL -l\"")
|
55
73
|
end
|
56
74
|
end
|
57
75
|
|
58
76
|
namespace :production do
|
59
77
|
desc 'Open an SSH session to the staging host in the production directory'
|
60
78
|
task :ssh do
|
61
|
-
|
62
|
-
opts = YAML.load_file('config/definitions.yml')
|
63
|
-
exec("ssh #{opts['deployer']['user']}@#{opts['deployer']['host']['production']} -t \"cd #{opts['deployer']['root']}/#{opts['deployer']['fqdn']['production']}; exec \$SHELL -l\"")
|
79
|
+
exec("ssh #{@opts['deployer']['user']}@#{@opts['deployer']['host']['production']} -t \"cd #{@opts['deployer']['root']}/#{@opts['deployer']['fqdn']['production']}; exec \$SHELL -l\"")
|
64
80
|
end
|
65
81
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
def GenerateNginxConfig(profile = 'production', out_path= './')
|
6
|
+
config_path = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
7
|
+
server = {}
|
8
|
+
#server[:name] =
|
9
|
+
#server[:root] =
|
10
|
+
#server[:php_sock_path] =
|
11
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
server {
|
2
|
+
listen 80;
|
3
|
+
listen [::]:80;
|
4
|
+
|
5
|
+
server_name <%= server[:name] %>;
|
6
|
+
|
7
|
+
root <%= server[:root] %>;
|
8
|
+
|
9
|
+
access_log <%= server[:root] %>/access.log;
|
10
|
+
error_log <%= server[:root] %>/error.log;
|
11
|
+
|
12
|
+
index index.php;
|
13
|
+
|
14
|
+
location / {
|
15
|
+
rewrite ^/(wp-(admin|includes).*) /wordpress/$1 last;
|
16
|
+
|
17
|
+
rewrite ^/$ /wordpress/index.php last;
|
18
|
+
|
19
|
+
location ~ \.php {
|
20
|
+
if ($request_uri !~* "/wp-config.php") {
|
21
|
+
rewrite ^/wp-(.*)\.php$ /wordpress/wp-$1.php last;
|
22
|
+
}
|
23
|
+
rewrite ^/index\.php$ /wordpress/index.php last;
|
24
|
+
rewrite ^/wp-login\.php$ /hello.php last;
|
25
|
+
include snippets/fastcgi-php.conf;
|
26
|
+
fastcgi_pass unix:<%= server[:php_sock_path] %>;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
location ~ /\. {
|
31
|
+
deny all;
|
32
|
+
access_log off;
|
33
|
+
log_not_found off;
|
34
|
+
}
|
35
|
+
|
36
|
+
location ~- \.(blade\.php)$ {
|
37
|
+
deny all;
|
38
|
+
}
|
39
|
+
|
40
|
+
location ~- composer\.(json|lock)$ {
|
41
|
+
deny all;
|
42
|
+
}
|
43
|
+
|
44
|
+
location ~- package(-lock)?\.json$ {
|
45
|
+
deny all;
|
46
|
+
}
|
47
|
+
|
48
|
+
location ~- yarn\.lock$ {
|
49
|
+
deny all;
|
50
|
+
}
|
51
|
+
}
|
data/base/config/deploy.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'date'
|
3
|
+
require 'wslave_sage'
|
2
4
|
|
3
5
|
opts = YAML.load_file('config/definitions.yml')
|
4
6
|
db_info = YAML.load_file('config/database.yml')
|
5
7
|
|
6
8
|
deploy_user = opts['deployer']['user']
|
9
|
+
deploy_group = opts['deployer']['www_data_group']
|
7
10
|
host_addr = opts['deployer']['host']['production']
|
8
11
|
multisite_root = opts['deployer']['root']
|
9
12
|
site_fqdn = opts['deployer']['fqdn']['production']
|
10
13
|
|
14
|
+
disable_rsync = (opts.include?('options') && opts['options'].include?('rsync_enabled') &&
|
15
|
+
opts['options']['rsync_enabled'] == false)
|
16
|
+
|
17
|
+
set :branch, fetch(opts['deployer']['branch']['production'], 'master')
|
18
|
+
|
11
19
|
role :web, "#{deploy_user}@#{host_addr}"
|
12
20
|
|
13
21
|
set :tmp_dir, "#{multisite_root}/tmp"
|
@@ -72,6 +80,107 @@ namespace :deploy do
|
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
83
|
+
desc 'Builds and Syncs the project Sage theme'
|
84
|
+
task :sync_sage_theme do
|
85
|
+
on roles(:web) do
|
86
|
+
wss = WSlaveSage.new()
|
87
|
+
sage_theme_name = wss.theme_name?
|
88
|
+
if (sage_theme_name == '')
|
89
|
+
puts "Couldn't find a Sage theme for this project."
|
90
|
+
else
|
91
|
+
wss.production()
|
92
|
+
`rsync -avzPhu --delete ./public/wp-content/themes/#{sage_theme_name}/vendor #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/vendor`
|
93
|
+
`rsync -avzPhu --delete ./public/wp-content/themes/#{sage_theme_name}/dist #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/dist`
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'Builds and Uploads the project Sage theme'
|
99
|
+
task :upload_sage_theme do
|
100
|
+
on roles(:web) do
|
101
|
+
wss = WSlaveSage.new()
|
102
|
+
sage_theme_name = wss.theme_name?
|
103
|
+
if (sage_theme_name == '')
|
104
|
+
puts "Couldn't find a Sage theme for this project."
|
105
|
+
else
|
106
|
+
wss.production()
|
107
|
+
upload! "./public/wp-content/themes/#{sage_theme_name}/vendor", "#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/", recursive: true
|
108
|
+
upload! "./public/wp-content/themes/#{sage_theme_name}/dist", "#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/", recursive: true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'Builds and Deploys the project Sage theme'
|
114
|
+
task :sage do
|
115
|
+
on roles(:web) do
|
116
|
+
if disable_rsync
|
117
|
+
invoke('deploy:upload_sage_theme')
|
118
|
+
else
|
119
|
+
invoke('deploy:sync_sage_theme')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc 'Finds and replaces localhost:8000 and your Staging address with the Production address'
|
125
|
+
task :chikan do
|
126
|
+
on roles(:web) do
|
127
|
+
puts 'Replacing localhost:8000 and Production URLs with Staging URLs...'
|
128
|
+
|
129
|
+
# Set an anchor to first homogonize instances of URL's, then replace all the anchors
|
130
|
+
anchor = "URL_REPLACEMENT_ANCHOR_00000"
|
131
|
+
|
132
|
+
# Create a backup, download it, and remove remote copy
|
133
|
+
execute "mkdir -p #{deploy_path}/db/tmp"
|
134
|
+
execute "mysqldump --opt --user=#{db_info['production']['username']} --password=#{db_info['production']['password']} --host=#{db_info['production']['host']} #{db_info['production']['database']} > #{deploy_path}/db/tmp/wordpress.sql"
|
135
|
+
FileUtils.mkdir_p('./db/tmp') unless Dir.exist?('./db/tmp')
|
136
|
+
download! "#{deploy_path}/db/tmp/wordpress.sql", "db/tmp/wordpress.sql"
|
137
|
+
execute "rm #{deploy_path}/db/tmp/*.sql"
|
138
|
+
|
139
|
+
# Regex replace in file
|
140
|
+
db_data = File.read('db/tmp/wordpress.sql')
|
141
|
+
|
142
|
+
# This may seem roundabout, but in order to avoid mangling the target URL we need to first
|
143
|
+
# replace instances of it with something that won't match
|
144
|
+
db_data = db_data.gsub(/#{opts['deployer']['fqdn']['production']}/, anchor)
|
145
|
+
|
146
|
+
# Set staging URL's to the anchor
|
147
|
+
if opts['deployer']['fqdn']['staging'] != ''
|
148
|
+
db_data = db_data.gsub(/#{opts['deployer']['fqdn']['staging']}/, anchor)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Set localhost entries to the anchor
|
152
|
+
db_data = db_data.gsub(/localhost\%3A8000/, anchor)
|
153
|
+
db_data = db_data.gsub(/localhost:8000/, anchor)
|
154
|
+
|
155
|
+
# Replace anchors with the correct target URL
|
156
|
+
db_data = db_data.gsub(anchor, "#{opts['deployer']['fqdn']['production']}")
|
157
|
+
|
158
|
+
# Save results
|
159
|
+
File.open('db/tmp/wordpress.sql', "w") {|file| file.puts db_data }
|
160
|
+
|
161
|
+
# Upload file and seed
|
162
|
+
upload! 'db/tmp/wordpress.sql', "#{deploy_path}/db/tmp/wordpress.sql"
|
163
|
+
execute "mysql -h#{db_info['production']['host']} -u#{db_info['production']['username']} -p#{db_info['production']['password']} #{db_info['production']['database']} < #{deploy_path}/db/tmp/wordpress.sql"
|
164
|
+
execute "rm #{deploy_path}/db/tmp/*.sql"
|
165
|
+
|
166
|
+
# Remove work file
|
167
|
+
# `rm db/tmp/wordpress.sql`
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
desc 'Sets ownership permissions'
|
172
|
+
task :set_permissions do
|
173
|
+
on roles(:web) do
|
174
|
+
puts 'Setting permissions'
|
175
|
+
if deploy_group != nil
|
176
|
+
puts "Recrusively setting group to #{deploy_group}..."
|
177
|
+
execute "chown -R :#{deploy_group} #{deploy_path}"
|
178
|
+
puts 'Allowing group level Write permission...'
|
179
|
+
execute "chmod -R g+w #{deploy_path}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
75
184
|
desc 'Perform special seed tasks required on intial seed'
|
76
185
|
task :initial do
|
77
186
|
on roles(:web) do
|
@@ -79,8 +188,7 @@ namespace :deploy do
|
|
79
188
|
invoke!('deploy:check:linked_dirs')
|
80
189
|
invoke!('deploy:check:make_linked_dirs')
|
81
190
|
invoke('deploy:wp_config')
|
82
|
-
if
|
83
|
-
opts['options']['rsync_enabled'] == false)
|
191
|
+
if disable_rsync
|
84
192
|
invoke('deploy:upload_wp')
|
85
193
|
invoke('deploy:upload_plugins')
|
86
194
|
invoke('deploy:upload_uploads')
|
@@ -90,18 +198,22 @@ namespace :deploy do
|
|
90
198
|
invoke('deploy:sync_uploads')
|
91
199
|
end
|
92
200
|
invoke('deploy')
|
201
|
+
invoke('sage')
|
93
202
|
invoke('db:seed')
|
203
|
+
invoke('deploy:chikan')
|
204
|
+
invoke('deploy:set_permissions')
|
94
205
|
end
|
95
206
|
end
|
96
207
|
|
97
208
|
desc 'Clear out remote DB tables and delete all remote files in deploy target directory'
|
98
209
|
task :destruct do
|
99
210
|
on roles(:web) do
|
100
|
-
execute "
|
211
|
+
execute "mysql --user=#{db_info['production']['username']} " \
|
212
|
+
"--password=#{db_info['production']['password']} --host=#{db_info['production']['host']} " \
|
213
|
+
"-Nse 'show tables' #{db_info['production']['database']} | " \
|
214
|
+
"while read table; do echo \"drop table $table;\"; done | " \
|
215
|
+
"mysql --user=#{db_info['production']['username']} " \
|
101
216
|
"--password=#{db_info['production']['password']} --host=#{db_info['production']['host']} " \
|
102
|
-
"--add-drop-table --no-data #{db_info['production']['database']} | " \
|
103
|
-
"grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -u#{db_info['production']['username']} " \
|
104
|
-
"-p#{db_info['production']['password']} -h#{db_info['production']['host']} " \
|
105
217
|
"#{db_info['production']['database']}"
|
106
218
|
|
107
219
|
execute "rm -rf #{deploy_path}/*"
|
@@ -147,6 +259,18 @@ namespace :data do
|
|
147
259
|
download! "#{deploy_path}/shared/public/wp-content/uploads", "./public/wp-content/", recursive: true
|
148
260
|
download! "#{deploy_path}/shared/public/wp-content/plugins", "./public/wp-content/", recursive: true
|
149
261
|
download! "#{deploy_path}/shared/public/wp-content/upgrade", "./public/wp-content/", recursive: true
|
262
|
+
download! "#{deploy_path}/current/public/wp-content/themes", "./public/wp-content/", recursive: true
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
desc "Backup data with rsync"
|
267
|
+
task :sync_backup do
|
268
|
+
on roles(:web) do
|
269
|
+
puts "Syncing Backup..."
|
270
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/uploads/ ./public/wp-content/uploads/`
|
271
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/plugins/ ./public/wp-content/plugins/`
|
272
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/upgrade/ ./public/wp-content/upgrade/`
|
273
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/ ./public/wp-content/themes/`
|
150
274
|
end
|
151
275
|
end
|
152
276
|
end
|
@@ -154,5 +278,9 @@ end
|
|
154
278
|
desc 'Backup DB and remote uploads/content'
|
155
279
|
task :backup do
|
156
280
|
invoke('db:backup')
|
157
|
-
|
281
|
+
if disable_rsync
|
282
|
+
invoke('data:backup')
|
283
|
+
else
|
284
|
+
invoke('data:sync_backup')
|
285
|
+
end
|
158
286
|
end
|
@@ -1,13 +1,21 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'date'
|
3
|
+
require 'wslave_sage'
|
2
4
|
|
3
5
|
opts = YAML.load_file('config/definitions.yml')
|
4
6
|
db_info = YAML.load_file('config/database.yml')
|
5
7
|
|
6
8
|
deploy_user = opts['deployer']['user']
|
9
|
+
deploy_group = opts['deployer']['www_data_group']
|
7
10
|
host_addr = opts['deployer']['host']['staging']
|
8
11
|
multisite_root = opts['deployer']['root']
|
9
12
|
site_fqdn = opts['deployer']['fqdn']['staging']
|
10
13
|
|
14
|
+
disable_rsync = (opts.include?('options') && opts['options'].include?('rsync_enabled') &&
|
15
|
+
opts['options']['rsync_enabled'] == false)
|
16
|
+
|
17
|
+
set :branch, fetch(opts['deployer']['branch']['staging'], 'master')
|
18
|
+
|
11
19
|
role :web, "#{deploy_user}@#{host_addr}"
|
12
20
|
|
13
21
|
set :tmp_dir, "#{multisite_root}/tmp"
|
@@ -18,7 +26,6 @@ set :linked_files, %w{public/wp-config.php}
|
|
18
26
|
|
19
27
|
set :deploy_to, deploy_path
|
20
28
|
|
21
|
-
|
22
29
|
namespace :deploy do
|
23
30
|
desc "Generate wp-config.php for profile"
|
24
31
|
task :wp_config do
|
@@ -72,6 +79,107 @@ namespace :deploy do
|
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
82
|
+
desc 'Builds and Syncs the project Sage theme'
|
83
|
+
task :sync_sage_theme do
|
84
|
+
on roles(:web) do
|
85
|
+
wss = WSlaveSage.new()
|
86
|
+
sage_theme_name = wss.theme_name?
|
87
|
+
if (sage_theme_name == '')
|
88
|
+
puts "Couldn't find a Sage theme for this project."
|
89
|
+
else
|
90
|
+
wss.production()
|
91
|
+
`rsync -avzPhu --delete ./public/wp-content/themes/#{sage_theme_name}/vendor #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/vendor`
|
92
|
+
`rsync -avzPhu --delete ./public/wp-content/themes/#{sage_theme_name}/dist #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/dist`
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
desc 'Builds and Uploads the project Sage theme'
|
98
|
+
task :upload_sage_theme do
|
99
|
+
on roles(:web) do
|
100
|
+
wss = WSlaveSage.new()
|
101
|
+
sage_theme_name = wss.theme_name?
|
102
|
+
if (sage_theme_name == '')
|
103
|
+
puts "Couldn't find a Sage theme for this project."
|
104
|
+
else
|
105
|
+
wss.production()
|
106
|
+
upload! "./public/wp-content/themes/#{sage_theme_name}/vendor", "#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/", recursive: true
|
107
|
+
upload! "./public/wp-content/themes/#{sage_theme_name}/dist", "#{deploy_path}/current/public/wp-content/themes/#{sage_theme_name}/", recursive: true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
desc 'Builds and Deploys the project Sage theme'
|
113
|
+
task :sage do
|
114
|
+
on roles(:web) do
|
115
|
+
if disable_rsync
|
116
|
+
invoke('deploy:upload_sage_theme')
|
117
|
+
else
|
118
|
+
invoke('deploy:sync_sage_theme')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
desc 'Finds and replaces localhost:8000 and your Production address with the Staging address'
|
124
|
+
task :chikan do
|
125
|
+
on roles(:web) do
|
126
|
+
puts 'Replacing localhost:8000 and Production URLs with Staging URLs...'
|
127
|
+
|
128
|
+
# Set an anchor to first homogonize instances of URL's, then replace all the anchors
|
129
|
+
anchor = "URL_REPLACEMENT_ANCHOR_00000"
|
130
|
+
|
131
|
+
# Create a backup, download it, and remove remote copy
|
132
|
+
execute "mkdir -p #{deploy_path}/db/tmp"
|
133
|
+
execute "mysqldump --opt --user=#{db_info['staging']['username']} --password=#{db_info['staging']['password']} --host=#{db_info['staging']['host']} #{db_info['staging']['database']} > #{deploy_path}/db/tmp/wordpress.sql"
|
134
|
+
FileUtils.mkdir_p('./db/tmp') unless Dir.exist?('./db/tmp')
|
135
|
+
download! "#{deploy_path}/db/tmp/wordpress.sql", "db/tmp/wordpress.sql"
|
136
|
+
execute "rm #{deploy_path}/db/tmp/*.sql"
|
137
|
+
|
138
|
+
# Regex replace in file
|
139
|
+
db_data = File.read('db/tmp/wordpress.sql')
|
140
|
+
|
141
|
+
# This may seem roundabout, but in order to avoid mangling the target URL we need to first
|
142
|
+
# replace instances of it with something that won't match
|
143
|
+
db_data = db_data.gsub(/#{opts['deployer']['fqdn']['staging']}/, anchor)
|
144
|
+
|
145
|
+
# Set production URL's to the anchor
|
146
|
+
if opts['deployer']['fqdn']['production'] != ''
|
147
|
+
db_data = db_data.gsub(/#{opts['deployer']['fqdn']['production']}/, anchor)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Set localhost entries to the anchor
|
151
|
+
db_data = db_data.gsub(/localhost\%3A8000/, anchor)
|
152
|
+
db_data = db_data.gsub(/localhost:8000/, anchor)
|
153
|
+
|
154
|
+
# Replace anchors with the correct target URL
|
155
|
+
db_data = db_data.gsub(anchor, "#{opts['deployer']['fqdn']['staging']}")
|
156
|
+
|
157
|
+
# Save results
|
158
|
+
File.open('db/tmp/wordpress.sql', "w") {|file| file.puts db_data }
|
159
|
+
|
160
|
+
# Upload file and seed
|
161
|
+
upload! 'db/tmp/wordpress.sql', "#{deploy_path}/db/tmp/wordpress.sql"
|
162
|
+
execute "mysql -h#{db_info['staging']['host']} -u#{db_info['staging']['username']} -p#{db_info['staging']['password']} #{db_info['staging']['database']} < #{deploy_path}/db/tmp/wordpress.sql"
|
163
|
+
execute "rm #{deploy_path}/db/tmp/*.sql"
|
164
|
+
|
165
|
+
# Remove work file
|
166
|
+
# `rm db/tmp/wordpress.sql`
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
desc 'Sets ownership permissions'
|
171
|
+
task :set_permissions do
|
172
|
+
on roles(:web) do
|
173
|
+
puts 'Setting permissions'
|
174
|
+
if deploy_group != nil
|
175
|
+
puts "Recrusively setting group to #{deploy_group}..."
|
176
|
+
execute "chown -R :#{deploy_group} #{deploy_path}"
|
177
|
+
puts 'Allowing group level Write permission...'
|
178
|
+
execute "chmod -R g+w #{deploy_path}"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
75
183
|
desc 'Perform special seed tasks required on intial seed'
|
76
184
|
task :initial do
|
77
185
|
on roles(:web) do
|
@@ -79,8 +187,7 @@ namespace :deploy do
|
|
79
187
|
invoke!('deploy:check:linked_dirs')
|
80
188
|
invoke!('deploy:check:make_linked_dirs')
|
81
189
|
invoke('deploy:wp_config')
|
82
|
-
if
|
83
|
-
opts['options']['rsync_enabled'] == false)
|
190
|
+
if disable_rsync
|
84
191
|
invoke('deploy:upload_wp')
|
85
192
|
invoke('deploy:upload_plugins')
|
86
193
|
invoke('deploy:upload_uploads')
|
@@ -90,18 +197,22 @@ namespace :deploy do
|
|
90
197
|
invoke('deploy:sync_uploads')
|
91
198
|
end
|
92
199
|
invoke('deploy')
|
200
|
+
invoke('sage')
|
93
201
|
invoke('db:seed')
|
202
|
+
invoke('deploy:chikan')
|
203
|
+
invoke('deploy:set_permissions')
|
94
204
|
end
|
95
205
|
end
|
96
206
|
|
97
207
|
desc 'Clear out remote DB tables and delete all remote files in deploy target directory'
|
98
208
|
task :destruct do
|
99
209
|
on roles(:web) do
|
100
|
-
execute "
|
210
|
+
execute "mysql --user=#{db_info['staging']['username']} " \
|
211
|
+
"--password=#{db_info['staging']['password']} --host=#{db_info['staging']['host']} " \
|
212
|
+
"-Nse 'show tables' #{db_info['staging']['database']} | " \
|
213
|
+
"while read table; do echo \"drop table $table;\"; done | " \
|
214
|
+
"mysql --user=#{db_info['staging']['username']} " \
|
101
215
|
"--password=#{db_info['staging']['password']} --host=#{db_info['staging']['host']} " \
|
102
|
-
"--add-drop-table --no-data #{db_info['staging']['database']} | " \
|
103
|
-
"grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -u#{db_info['staging']['username']} " \
|
104
|
-
"-p#{db_info['staging']['password']} -h#{db_info['staging']['host']} " \
|
105
216
|
"#{db_info['staging']['database']}"
|
106
217
|
|
107
218
|
execute "rm -rf #{deploy_path}/*"
|
@@ -147,6 +258,18 @@ namespace :data do
|
|
147
258
|
download! "#{deploy_path}/shared/public/wp-content/uploads", "./public/wp-content/", recursive: true
|
148
259
|
download! "#{deploy_path}/shared/public/wp-content/plugins", "./public/wp-content/", recursive: true
|
149
260
|
download! "#{deploy_path}/shared/public/wp-content/upgrade", "./public/wp-content/", recursive: true
|
261
|
+
download! "#{deploy_path}/current/public/wp-content/themes", "./public/wp-content/", recursive: true
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
desc "Backup data with rsync"
|
266
|
+
task :sync_backup do
|
267
|
+
on roles(:web) do
|
268
|
+
puts "Syncing Backup..."
|
269
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/uploads/ ./public/wp-content/uploads/`
|
270
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/plugins/ ./public/wp-content/plugins/`
|
271
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/shared/public/wp-content/upgrade/ ./public/wp-content/upgrade/`
|
272
|
+
`rsync -avzPhu --delete #{deploy_user}@#{host_addr}:#{deploy_path}/current/public/wp-content/themes/ ./public/wp-content/themes/`
|
150
273
|
end
|
151
274
|
end
|
152
275
|
end
|
@@ -154,5 +277,9 @@ end
|
|
154
277
|
desc 'Backup DB and remote uploads/content'
|
155
278
|
task :backup do
|
156
279
|
invoke('db:backup')
|
157
|
-
|
280
|
+
if disable_rsync
|
281
|
+
invoke('data:backup')
|
282
|
+
else
|
283
|
+
invoke('data:sync_backup')
|
284
|
+
end
|
158
285
|
end
|