wordpresstrano 0.2.2 → 0.2.3
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 +4 -4
- data/lib/capistrano/wordpress/hooks.rb +31 -44
- data/lib/capistrano/wordpress/tasks/binaries.rake +9 -15
- data/lib/capistrano/wordpress/tasks/database.rake +44 -136
- data/lib/capistrano/wordpress/tasks/deploy.rake +44 -20
- data/lib/capistrano/wordpress/tasks/htaccess.rake +0 -70
- data/lib/capistrano/wordpress/tasks/maintenance.rake +25 -0
- data/lib/capistrano/wordpress/tasks/uploads.rake +0 -61
- data/wordpresstrano.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61fd148512fb3279807ba2e5afaffd510de22b2e
|
4
|
+
data.tar.gz: 1dd7e3d9601695732cae56e36beccfafae86f046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e35f1b198560f0a973dd770e8af7c02fa80e96c2310d9879e15fbff30d7ed580d3af4c0bd3a667c9dc038d9e8a6dacb4c7a352929bce5862c904be36fb0edee
|
7
|
+
data.tar.gz: 6d8e28ae42045e052d675072c69116593798fa54213837888f57d5663ef87ad16c14fc52030c39b07d62352777b418bc299b9ec1a28d70cc30dc514bd843ef27
|
@@ -1,38 +1,23 @@
|
|
1
|
-
#
|
2
|
-
before "
|
3
|
-
before "db:
|
4
|
-
before "db:
|
5
|
-
before "db:
|
6
|
-
before "db:push", "
|
7
|
-
before "db:reset", "
|
8
|
-
before "db:restore", "
|
9
|
-
before "deploy", "
|
10
|
-
before "
|
11
|
-
before "
|
12
|
-
before "
|
13
|
-
before "
|
14
|
-
before "uploads:
|
15
|
-
before "
|
16
|
-
before "wp:core:
|
17
|
-
|
18
|
-
# Check directories before performing tasks
|
19
|
-
before "config:generate", "deploy:check:directories"
|
20
|
-
before "db:backup", "deploy:check:directories"
|
21
|
-
before "db:create", "deploy:check:directories"
|
22
|
-
before "db:list_backups", "deploy:check:directories"
|
23
|
-
before "db:pull", "deploy:check:directories"
|
24
|
-
before "db:push", "deploy:check:directories"
|
25
|
-
before "db:reset", "deploy:check:directories"
|
26
|
-
before "db:restore", "deploy:check:directories"
|
27
|
-
before "deploy:shared_configs", "deploy:check:directories"
|
28
|
-
before "htaccess:pull", "deploy:check:directories"
|
29
|
-
before "htaccess:push", "deploy:check:directories"
|
30
|
-
before "robots:generate", "deploy:check:directories"
|
31
|
-
before "uploads:pull", "deploy:check:directories"
|
32
|
-
before "uploads:push", "deploy:check:directories"
|
1
|
+
# Perform a safety check before running tasks
|
2
|
+
before "config:generate", "deploy:safety_check"
|
3
|
+
before "db:backup", "deploy:safety_check"
|
4
|
+
before "db:create", "deploy:safety_check"
|
5
|
+
before "db:list_backups", "deploy:safety_check"
|
6
|
+
before "db:push", "deploy:safety_check"
|
7
|
+
before "db:reset", "deploy:safety_check"
|
8
|
+
before "db:restore", "deploy:safety_check"
|
9
|
+
before "deploy", "deploy:safety_check"
|
10
|
+
before "deploy:all", "deploy:safety_check"
|
11
|
+
before "deploy:configs", "deploy:safety_check"
|
12
|
+
before "htaccess:push", "deploy:safety_check"
|
13
|
+
before "robots:generate", "deploy:safety_check"
|
14
|
+
before "uploads:push", "deploy:safety_check"
|
15
|
+
before "uploads:setperms", "deploy:safety_check"
|
16
|
+
before "wp:core:download", "deploy:safety_check"
|
17
|
+
before "wp:core:remove", "deploy:safety_check"
|
33
18
|
|
34
19
|
# Check if maintenance mode should be enabled before pushing the database
|
35
|
-
before "db:push", "
|
20
|
+
before "db:push", "maintenance:enable_if_previous_deployment"
|
36
21
|
|
37
22
|
# Create the MySQL database before pushing content to it
|
38
23
|
before "db:push", "db:create"
|
@@ -41,31 +26,33 @@ before "db:push", "db:create"
|
|
41
26
|
before "db:push", "db:backup"
|
42
27
|
|
43
28
|
# Check if maintenance mode should be enabled before restoring the database
|
44
|
-
before "db:restore", "
|
29
|
+
before "db:restore", "maintenance:enable_if_previous_deployment"
|
45
30
|
|
46
31
|
# Create the database before restoring
|
47
32
|
before "db:restore", "db:create"
|
48
33
|
|
49
|
-
#
|
50
|
-
|
34
|
+
# Check if there is a previous deployment before performing
|
35
|
+
# a partial deployment.
|
36
|
+
before "deploy", "deploy:check_for_previous_deployment"
|
37
|
+
|
38
|
+
# Set the timestamp to be used by the db:backup task
|
39
|
+
before "deploy:all", "db:match_backup_timestamp_with_release"
|
40
|
+
before "deploy:rollback", "db:match_backup_timestamp_with_release"
|
51
41
|
|
52
42
|
# Move the database backup from the release we rolled away from
|
53
43
|
# into the release's root before it's archived
|
54
44
|
before "deploy:cleanup_rollback", "db:cleanup_rollback_database"
|
55
45
|
|
46
|
+
# Remove the existing WordPress core before downloading a new one
|
47
|
+
before "wp:core:download", "wp:core:remove"
|
48
|
+
|
56
49
|
# Load the local WordPress version so that when downloading the
|
57
50
|
# WordPress core on a remote server, the version matches the local installation.
|
58
51
|
before "deploy:updated", "wp:core:load_local_version"
|
59
52
|
|
60
|
-
# Remove the existing WordPress core before downloading a new one
|
61
|
-
before "wp:core:download", "wp:core:remove"
|
62
|
-
|
63
53
|
# Download the WordPress core files before finishing deploy:updated
|
64
54
|
before "deploy:updated", "wp:core:download"
|
65
55
|
|
66
|
-
# Check if we can deploy without pushing htaccess/uploads/database
|
67
|
-
before "deploy", "deploy:check_for_previous_deployment"
|
68
|
-
|
69
56
|
# Link the release into the website root
|
70
57
|
after "deploy:finished", "webroot:symlink"
|
71
58
|
|
@@ -86,10 +73,10 @@ after "uploads:push", "uploads:setperms"
|
|
86
73
|
after "deploy:finished", "webroot:setperms"
|
87
74
|
|
88
75
|
# Check if maintenance mode should be disabled after pushing the database
|
89
|
-
after "db:push", "
|
76
|
+
after "db:push", "maintenance:disable_if_previous_deployment"
|
90
77
|
|
91
78
|
# Check if maintenance mode should be disabled after restoring the database
|
92
|
-
after "db:restore", "
|
79
|
+
after "db:restore", "maintenance:disable_if_previous_deployment"
|
93
80
|
|
94
81
|
# Rollback the database after rolling back the files
|
95
82
|
after "deploy:reverted", "db:rollback"
|
@@ -1,31 +1,25 @@
|
|
1
1
|
namespace :binaries do
|
2
2
|
desc "Check that all required binaries are installed"
|
3
3
|
task :check do
|
4
|
-
next if
|
4
|
+
next if fetch(:checked_binaries, false)
|
5
5
|
|
6
6
|
required_binaries = {
|
7
7
|
local: [:mysql, :mysqldump, :mysqlshow, :php, :rm, :rsync, :wp],
|
8
|
-
remote:
|
9
|
-
:all => [:chmod, :find, :mysql, :mysqldump, :mysqlshow, :rm, :wp],
|
10
|
-
:app => [:ln, :readlink, :rsync],
|
11
|
-
:db => [:du, :grep]
|
12
|
-
}
|
8
|
+
remote: [:chmod, :du, :find, :grep, :ln, :mysql, :mysqldump, :mysqlshow, :readlink, :rm, :rsync, :wp]
|
13
9
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
|
11
|
+
required_binaries[:local].each do |binary|
|
12
|
+
run_locally do
|
17
13
|
unless test :which, binary
|
18
14
|
abort "The binary '#{binary}' is missing from the local system"
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
required_binaries[:remote].each do |
|
24
|
-
on roles(
|
25
|
-
|
26
|
-
|
27
|
-
abort "The binary '#{binary}' is missing from #{server.user}@#{server.hostname}"
|
28
|
-
end
|
19
|
+
required_binaries[:remote].each do |binary|
|
20
|
+
on roles(:app) do |server|
|
21
|
+
unless test :which, binary
|
22
|
+
abort "The binary '#{binary}' is missing from #{server.user}@#{server.hostname}"
|
29
23
|
end
|
30
24
|
end
|
31
25
|
end
|
@@ -1,65 +1,4 @@
|
|
1
1
|
namespace :db do
|
2
|
-
desc "Pull down the WordPress database"
|
3
|
-
task :pull do
|
4
|
-
file = "#{SecureRandom.hex(8)}.sql"
|
5
|
-
|
6
|
-
local_path = File.join(Dir.pwd, file)
|
7
|
-
remote_path = File.join(fetch(:tmp_dir), file)
|
8
|
-
|
9
|
-
next if 0 == roles(:db).count
|
10
|
-
|
11
|
-
if 1 < roles(:db).count
|
12
|
-
run_locally do
|
13
|
-
info "Found #{roles(:db).count} database servers"
|
14
|
-
|
15
|
-
roles(:db).each_with_index do |server, index|
|
16
|
-
info "#{index + 1}) #{server.user}@#{server.hostname} (Port #{server.port or 22})"
|
17
|
-
end
|
18
|
-
|
19
|
-
set :database_pull_server, ask("the number of the server to pull the database from", "1")
|
20
|
-
end
|
21
|
-
else
|
22
|
-
set :database_pull_server, "1"
|
23
|
-
end
|
24
|
-
|
25
|
-
database_pull_server = fetch(:database_pull_server).to_i
|
26
|
-
|
27
|
-
if 1 > database_pull_server or roles(:db).count < database_pull_server
|
28
|
-
run_locally do
|
29
|
-
error "Unable to locate a server with an id '#{database_pull_server}'"
|
30
|
-
end
|
31
|
-
|
32
|
-
next
|
33
|
-
end
|
34
|
-
|
35
|
-
database_pull_server = roles(:db)[database_pull_server - 1]
|
36
|
-
|
37
|
-
on roles(:db) do |server|
|
38
|
-
next unless server.matches? database_pull_server
|
39
|
-
|
40
|
-
info "Pulling WordPress database from #{server.user}@#{server.hostname}"
|
41
|
-
|
42
|
-
within release_path do
|
43
|
-
execute :wp, "db", "export", remote_path
|
44
|
-
end
|
45
|
-
|
46
|
-
download! remote_path, local_path
|
47
|
-
|
48
|
-
execute :rm, "-f", remote_path
|
49
|
-
|
50
|
-
run_locally do
|
51
|
-
execute :wp, "db", "import", local_path
|
52
|
-
execute :rm, "-f", local_path
|
53
|
-
|
54
|
-
if fetch(:local_site_url) and fetch(:site_url)
|
55
|
-
execute :wp, "search-replace", fetch(:site_url), fetch(:local_site_url)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
set :database_pull_server, nil
|
61
|
-
end
|
62
|
-
|
63
2
|
desc "Push up the WordPress database"
|
64
3
|
task :push do
|
65
4
|
file = "#{SecureRandom.hex(8)}.sql"
|
@@ -67,11 +6,11 @@ namespace :db do
|
|
67
6
|
local_path = File.join(Dir.pwd, file)
|
68
7
|
remote_path = File.join(fetch(:tmp_dir), file)
|
69
8
|
|
70
|
-
on roles(:
|
9
|
+
on roles(:app) do |server|
|
71
10
|
info "Pushing WordPress database to #{server.user}@#{server.hostname}"
|
72
11
|
|
73
12
|
run_locally do
|
74
|
-
execute :wp,
|
13
|
+
execute :wp, :db, :export, local_path
|
75
14
|
end
|
76
15
|
|
77
16
|
upload! local_path, remote_path
|
@@ -81,7 +20,7 @@ namespace :db do
|
|
81
20
|
end
|
82
21
|
|
83
22
|
within release_path do
|
84
|
-
execute :wp,
|
23
|
+
execute :wp, :db, :import, remote_path
|
85
24
|
execute :rm, "-f", remote_path
|
86
25
|
|
87
26
|
if fetch(:local_site_url) and fetch(:site_url)
|
@@ -104,17 +43,17 @@ namespace :db do
|
|
104
43
|
database_username = database_config[:username]
|
105
44
|
database_password = database_config[:password]
|
106
45
|
|
107
|
-
on roles(:
|
46
|
+
on roles(:app) do |server|
|
108
47
|
within release_path do
|
109
48
|
if test("[ \"#{database_name}\" == $(mysqlshow --user=\"#{database_username}\" --password=\"#{database_password}\" #{database_name} | grep -v Wildcard | grep -o #{database_name}) ]")
|
110
|
-
|
49
|
+
error "The MySQL database already exists on #{server.user}@#{server.hostname}"
|
111
50
|
|
112
51
|
next
|
113
52
|
end
|
114
53
|
|
115
54
|
info "Creating MySQL database on #{server.user}@#{server.hostname}"
|
116
55
|
|
117
|
-
execute :wp,
|
56
|
+
execute :wp, :db, :create
|
118
57
|
end
|
119
58
|
end
|
120
59
|
end
|
@@ -132,34 +71,34 @@ namespace :db do
|
|
132
71
|
database_username = database_config[:username]
|
133
72
|
database_password = database_config[:password]
|
134
73
|
|
135
|
-
on roles(:
|
74
|
+
on roles(:app) do |server|
|
136
75
|
within release_path do
|
137
76
|
unless test("[ \"#{database_name}\" == $(mysqlshow --user=\"#{database_username}\" --password=\"#{database_password}\" #{database_name} | grep -v Wildcard | grep -o #{database_name}) ]")
|
138
|
-
|
77
|
+
error "The MySQL database does not exist on #{server.user}@#{server.hostname}"
|
139
78
|
|
140
79
|
next
|
141
80
|
end
|
142
81
|
|
143
82
|
info "Deleting MySQL database on #{server.user}@#{server.hostname}"
|
144
83
|
|
145
|
-
execute :wp,
|
84
|
+
execute :wp, :db, :drop, "--yes"
|
146
85
|
end
|
147
86
|
end
|
148
87
|
end
|
149
88
|
|
150
89
|
desc "Reset the MySQL database"
|
151
90
|
task :reset do
|
152
|
-
on roles(:
|
91
|
+
on roles(:app) do |server|
|
153
92
|
within release_path do
|
154
|
-
unless test :wp,
|
155
|
-
|
93
|
+
unless test :wp, :core, "is-installed"
|
94
|
+
error "The WordPress database does not appear to be installed on #{server.user}@#{server.hostname}"
|
156
95
|
|
157
96
|
next
|
158
97
|
end
|
159
98
|
|
160
99
|
info "Resetting the WordPress database on #{server.user}@#{server.hostname}"
|
161
100
|
|
162
|
-
execute :wp,
|
101
|
+
execute :wp, :db, :reset, "--yes"
|
163
102
|
end
|
164
103
|
end
|
165
104
|
end
|
@@ -168,14 +107,13 @@ namespace :db do
|
|
168
107
|
task :backup do
|
169
108
|
backups_directory = File.join(fetch(:deploy_to), "backups", "database")
|
170
109
|
|
171
|
-
on roles(:
|
110
|
+
on roles(:app) do |server|
|
172
111
|
next unless test("[ -d #{current_path} ]")
|
173
112
|
|
174
|
-
|
113
|
+
timestamp = fetch(:db_backup_timestamp, Time.now.strftime("%Y%m%d%H%M%S"))
|
114
|
+
|
115
|
+
file = "#{timestamp}.sql"
|
175
116
|
|
176
|
-
file = File.basename(actual_current_path)
|
177
|
-
file = "#{file}.sql"
|
178
|
-
|
179
117
|
remote_path = File.join(backups_directory, file)
|
180
118
|
|
181
119
|
info "Backing up WordPress database on #{server.user}@#{server.hostname}"
|
@@ -187,7 +125,7 @@ namespace :db do
|
|
187
125
|
end
|
188
126
|
|
189
127
|
within release_path do
|
190
|
-
execute :wp,
|
128
|
+
execute :wp, :db, :export, remote_path
|
191
129
|
end
|
192
130
|
end
|
193
131
|
end
|
@@ -196,44 +134,42 @@ namespace :db do
|
|
196
134
|
task :restore do
|
197
135
|
backups_directory = File.join(fetch(:deploy_to), "backups", "database")
|
198
136
|
|
199
|
-
backup_id = fetch(:
|
137
|
+
backup_id = fetch(:db_restore_timestamp, ENV['id'])
|
200
138
|
|
201
139
|
unless backup_id
|
202
140
|
run_locally do
|
203
|
-
|
141
|
+
error "You must provide the ID of the backup to restore!"
|
204
142
|
end
|
205
143
|
|
206
144
|
next
|
207
145
|
end
|
208
146
|
|
209
|
-
on roles(:
|
147
|
+
on roles(:app) do |server|
|
210
148
|
file = "#{backup_id}.sql"
|
211
149
|
|
212
150
|
remote_path = File.join(backups_directory, file)
|
213
151
|
|
214
152
|
unless test("[ -f #{remote_path} ]")
|
215
|
-
info "
|
153
|
+
info "No database backup found for the id '#{backup_id}' on #{server.user}@#{server.hostname}"
|
216
154
|
|
217
155
|
next
|
218
156
|
end
|
219
157
|
|
220
|
-
info "
|
158
|
+
info "Rolling back the database to '#{backup_id}' on #{server.user}@#{server.hostname}"
|
221
159
|
|
222
160
|
within release_path do
|
223
|
-
execute :wp,
|
161
|
+
execute :wp, :db, :import, remote_path
|
224
162
|
end
|
225
163
|
end
|
226
164
|
end
|
227
165
|
|
228
166
|
desc "List all WordPress database backups"
|
229
167
|
task :list_backups do
|
230
|
-
on roles(:
|
231
|
-
next unless server.matches? roles(:db).first # Hack to make sure we run only once
|
232
|
-
|
168
|
+
on roles(:app) do |server|
|
233
169
|
backups_directory = File.join(fetch(:deploy_to), "backups", "database")
|
234
170
|
|
235
171
|
unless test("[ -d #{backups_directory} ]")
|
236
|
-
|
172
|
+
error "No database backups found on #{server.user}@#{server.hostname}"
|
237
173
|
|
238
174
|
next
|
239
175
|
end
|
@@ -241,16 +177,12 @@ namespace :db do
|
|
241
177
|
backup_paths = capture("find #{backups_directory} -name '*.sql' -maxdepth 1")
|
242
178
|
|
243
179
|
if backup_paths.nil? or backup_paths.empty?
|
244
|
-
|
180
|
+
error "No database backups found on #{server.user}@#{server.hostname}"
|
245
181
|
|
246
182
|
next
|
247
183
|
end
|
248
184
|
|
249
|
-
|
250
|
-
info "Found 1 database backup"
|
251
|
-
else
|
252
|
-
info "Found #{backup_paths.lines.count} database backups"
|
253
|
-
end
|
185
|
+
info "Found #{backup_paths.lines.count} database backup(s) on #{server.user}@#{server.hostname}"
|
254
186
|
|
255
187
|
backup_paths.each_line do |backup_path|
|
256
188
|
backup_path = backup_path.strip
|
@@ -273,9 +205,7 @@ namespace :db do
|
|
273
205
|
actual_current_path = nil
|
274
206
|
actual_release_path = nil
|
275
207
|
|
276
|
-
on roles(:
|
277
|
-
next unless server.matches? roles(:db).first # Hack to make sure we run only once
|
278
|
-
|
208
|
+
on roles(:app) do |server|
|
279
209
|
actual_current_path = capture("readlink -f #{current_path}").strip
|
280
210
|
actual_release_path = capture("readlink -f #{release_path}").strip
|
281
211
|
end
|
@@ -288,68 +218,46 @@ namespace :db do
|
|
288
218
|
next
|
289
219
|
end
|
290
220
|
|
221
|
+
set :db_restore_timestamp, File.basename(actual_release_path)
|
222
|
+
|
291
223
|
invoke 'db:backup'
|
292
224
|
invoke 'db:restore'
|
293
|
-
|
294
|
-
set :rollback_from_timestamp, File.basename(actual_current_path)
|
295
225
|
end
|
296
226
|
|
297
227
|
# Move the database backup from the release we rolled away from
|
298
228
|
# into the release's root before it's archived
|
299
229
|
task :cleanup_rollback_database do
|
300
|
-
|
230
|
+
db_backup_timestamp = fetch(:db_backup_timestamp)
|
301
231
|
|
302
|
-
unless
|
303
|
-
run_locally do
|
304
|
-
error "No timestamp set for the release we rolled away from"
|
305
|
-
end
|
306
|
-
|
307
|
-
next
|
308
|
-
end
|
232
|
+
next unless db_backup_timestamp
|
309
233
|
|
310
|
-
file = "
|
234
|
+
file = "database.sql"
|
311
235
|
|
312
236
|
backups_directory = File.join(fetch(:deploy_to), "backups", "database")
|
313
237
|
|
314
238
|
source_path = File.join(backups_directory, file)
|
315
|
-
destination_path = File.join(releases_path,
|
239
|
+
destination_path = File.join(releases_path, db_backup_timestamp, file)
|
316
240
|
|
317
|
-
on roles(:
|
241
|
+
on roles(:app) do |server|
|
318
242
|
unless test("[ -f #{source_path} ]")
|
319
|
-
error "The database backup
|
243
|
+
error "The database backup (#{db_backup_timestamp}) does not exist on #{server.user}@#{server.hostname}"
|
320
244
|
|
321
245
|
next
|
322
246
|
end
|
323
247
|
|
324
|
-
info "Moving database backup #{
|
248
|
+
info "Moving database backup #{db_backup_timestamp} into release on #{server.user}@#{server.hostname}"
|
325
249
|
|
326
250
|
execute :mv, source_path, destination_path
|
327
251
|
end
|
328
252
|
end
|
329
253
|
|
330
|
-
#
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
next if test("[ -f #{maintenance_path} ]")
|
337
|
-
next if true == fetch(:db_enabled_maintenance_mode)
|
338
|
-
|
339
|
-
within current_path do
|
340
|
-
if test :wp, "core", "is-installed"
|
341
|
-
set :db_enabled_maintenance_mode, true
|
342
|
-
|
343
|
-
invoke 'maintenance:enable'
|
344
|
-
end
|
254
|
+
# Set the timestamp for the backup task to match
|
255
|
+
# the timestamp of the current release.
|
256
|
+
task :match_backup_timestamp_with_release do
|
257
|
+
on roles(:app) do
|
258
|
+
if test("[ -d #{current_path} ]")
|
259
|
+
set :db_backup_timestamp, File.basename(capture("readlink -f #{current_path}").strip)
|
345
260
|
end
|
346
261
|
end
|
347
262
|
end
|
348
|
-
|
349
|
-
# Disable maintenance mode if it was enabled by check_maintenance_enable
|
350
|
-
task :check_maintenance_disable do
|
351
|
-
next unless true == fetch(:db_enabled_maintenance_mode)
|
352
|
-
|
353
|
-
invoke 'maintenance:disable'
|
354
|
-
end
|
355
263
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
namespace :deploy do
|
2
|
+
desc "Deploy all resources to the remote servers"
|
2
3
|
task :all do
|
3
4
|
Rake::Task["deploy"].prerequisites.delete("deploy:check_for_previous_deployment")
|
4
5
|
Rake::Task["deploy:updated"].prerequisites.delete("htaccess:clone_from_previous_release")
|
5
6
|
|
7
|
+
before "deploy", "deploy:configs"
|
8
|
+
|
6
9
|
after "deploy:updated", "htaccess:push"
|
7
10
|
after "deploy:updated", "uploads:push"
|
8
11
|
after "deploy:updated", "db:push"
|
@@ -10,23 +13,8 @@ namespace :deploy do
|
|
10
13
|
invoke "deploy"
|
11
14
|
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
on roles(:all) do |server|
|
17
|
-
unless test("[ -d #{current_path} ]")
|
18
|
-
error "Unable to locate a current release on #{server.user}@#{server.hostname}"
|
19
|
-
|
20
|
-
previous_deployment = false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
unless previous_deployment
|
25
|
-
raise "One or more servers don't have a current release on them. You should run 'deploy:all' first."
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
task :shared_configs do
|
16
|
+
desc "Deploy the wp-config.php and robots.txt configuration files"
|
17
|
+
task :configs do
|
30
18
|
config_path = File.join(shared_path, "wp-config.php")
|
31
19
|
robots_path = File.join(shared_path, "robots.txt")
|
32
20
|
|
@@ -41,11 +29,47 @@ namespace :deploy do
|
|
41
29
|
end
|
42
30
|
end
|
43
31
|
|
32
|
+
desc "Perform a safety check"
|
33
|
+
task :safety_check do
|
34
|
+
unless fetch(:website_root)
|
35
|
+
raise "You must set the :website_root variable in your deployment configuration!"
|
36
|
+
end
|
37
|
+
|
38
|
+
if 1 < roles(:app).count
|
39
|
+
raise "You can't deploy to more than one server!"
|
40
|
+
end
|
41
|
+
|
42
|
+
invoke "binaries:check"
|
43
|
+
invoke "deploy:check:directories"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Touch the most recent release directory on the remote servers"
|
44
47
|
task :touch_release do
|
45
48
|
on roles(:app) do |server|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if test("[ -d #{release_path} ]")
|
50
|
+
info "Touching release directory on #{server.user}@#{server.hostname}"
|
51
|
+
|
52
|
+
execute :touch, release_path
|
53
|
+
else
|
54
|
+
error "No release directory found on #{server.user}@#{server.hostname}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Check if a previous deployment exists on the remote servers.
|
60
|
+
# If one or more servers don't have a release on them, we should
|
61
|
+
# raise an error.
|
62
|
+
task :check_for_previous_deployment do
|
63
|
+
on roles(:app) do |server|
|
64
|
+
unless test("[ -d #{current_path} ]")
|
65
|
+
error "No releases found on #{server.user}@#{server.hostname}"
|
66
|
+
|
67
|
+
set :all_servers_have_deployments, false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
unless fetch(:all_servers_have_deployments, true)
|
72
|
+
raise "You need to run the 'deploy:all' task first!"
|
49
73
|
end
|
50
74
|
end
|
51
75
|
end
|
@@ -1,74 +1,4 @@
|
|
1
1
|
namespace :htaccess do
|
2
|
-
desc "Pull down the .htaccess file"
|
3
|
-
task :pull do
|
4
|
-
file = ".htaccess"
|
5
|
-
|
6
|
-
remote_file = File.join(release_path, file)
|
7
|
-
|
8
|
-
next if 0 == roles(:app).count
|
9
|
-
|
10
|
-
if 1 < roles(:app).count
|
11
|
-
run_locally do
|
12
|
-
info "Found #{roles(:app).count} application servers"
|
13
|
-
|
14
|
-
roles(:app).each_with_index do |server, index|
|
15
|
-
info "#{index + 1}) #{server.user}@#{server.hostname} (Port #{server.port or 22})"
|
16
|
-
end
|
17
|
-
|
18
|
-
set :htaccess_pull_server, ask("the number of the server to pull the #{file} file from", "1")
|
19
|
-
end
|
20
|
-
else
|
21
|
-
set :htaccess_pull_server, "1"
|
22
|
-
end
|
23
|
-
|
24
|
-
htaccess_pull_server = fetch(:htaccess_pull_server).to_i
|
25
|
-
|
26
|
-
if 1 > htaccess_pull_server or roles(:app).count < htaccess_pull_server
|
27
|
-
run_locally do
|
28
|
-
error "Unable to locate a server with an id '#{htaccess_pull_server}'"
|
29
|
-
end
|
30
|
-
|
31
|
-
next
|
32
|
-
end
|
33
|
-
|
34
|
-
htaccess_pull_server = roles(:app)[htaccess_pull_server - 1]
|
35
|
-
|
36
|
-
on roles(:app) do |server|
|
37
|
-
next unless server.matches? htaccess_pull_server
|
38
|
-
|
39
|
-
unless test("[ -f #{remote_file} ]")
|
40
|
-
error "There isn't a #{file} file on #{server.user}@#{server.hostname}"
|
41
|
-
|
42
|
-
next
|
43
|
-
end
|
44
|
-
|
45
|
-
if File.file? file
|
46
|
-
local_sha256sum = Digest::SHA256.hexdigest(File.read(file))
|
47
|
-
remote_sha256sum = capture("sha256sum #{remote_file}").split(' ').first
|
48
|
-
|
49
|
-
if local_sha256sum == remote_sha256sum
|
50
|
-
info "No changes detected in #{file} file on #{server.user}@#{server.hostname}"
|
51
|
-
|
52
|
-
next
|
53
|
-
end
|
54
|
-
|
55
|
-
unless fetch(:confirm_pull_htaccess)
|
56
|
-
set :confirm_pull_htaccess, ask("confirmation for local #{file} file overwrite", "Y/n")
|
57
|
-
end
|
58
|
-
|
59
|
-
next unless [true, "y", "yes"].include? fetch(:confirm_pull_htaccess).downcase
|
60
|
-
end
|
61
|
-
|
62
|
-
info "Pulling #{file} file from #{server.user}@#{server.hostname}"
|
63
|
-
|
64
|
-
download! remote_file, file
|
65
|
-
|
66
|
-
break
|
67
|
-
end
|
68
|
-
|
69
|
-
set :htaccess_pull_server, nil
|
70
|
-
end
|
71
|
-
|
72
2
|
desc "Push up the .htaccess file"
|
73
3
|
task :push do
|
74
4
|
file = ".htaccess"
|
@@ -65,4 +65,29 @@ namespace :maintenance do
|
|
65
65
|
execute :rm, "-f", remote_path
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
# Enable maintenance mode if there is already a WordPress deployment.
|
70
|
+
task :enable_if_previous_deployment do
|
71
|
+
maintenance_path = File.join(current_path, ".maintenance")
|
72
|
+
|
73
|
+
on roles(:app) do
|
74
|
+
next unless test("[ -d #{current_path} ]")
|
75
|
+
next if test("[ -f #{maintenance_path} ]")
|
76
|
+
|
77
|
+
within current_path do
|
78
|
+
if test :wp, :core, "is-installed"
|
79
|
+
set :previous_deployment_maintenance_enabled, true
|
80
|
+
|
81
|
+
invoke 'maintenance:enable'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Disable maintenance mode if it was enabled by the :enable_if_previous_deployment task.
|
88
|
+
task :disable_if_previous_deployment do
|
89
|
+
next unless true == fetch(:previous_deployment_maintenance_enabled)
|
90
|
+
|
91
|
+
invoke 'maintenance:disable'
|
92
|
+
end
|
68
93
|
end
|
@@ -1,65 +1,4 @@
|
|
1
1
|
namespace :uploads do
|
2
|
-
desc "Pull down the uploads directory"
|
3
|
-
task :pull do
|
4
|
-
directory = File.join("wp-content", "uploads")
|
5
|
-
|
6
|
-
local_path = File.join(Dir.pwd, directory)
|
7
|
-
remote_path = File.join(release_path, directory)
|
8
|
-
|
9
|
-
next if 0 == roles(:app).count
|
10
|
-
|
11
|
-
if 1 < roles(:app).count
|
12
|
-
run_locally do
|
13
|
-
info "Found #{roles(:app).count} application servers"
|
14
|
-
|
15
|
-
roles(:app).each_with_index do |server, index|
|
16
|
-
info "#{index + 1}) #{server.user}@#{server.hostname} (Port #{server.port or 22})"
|
17
|
-
end
|
18
|
-
|
19
|
-
set :uploads_pull_server, ask("the number of the server to pull the #{directory} directory from", "1")
|
20
|
-
end
|
21
|
-
else
|
22
|
-
set :uploads_pull_server, "1"
|
23
|
-
end
|
24
|
-
|
25
|
-
uploads_pull_server = fetch(:uploads_pull_server).to_i
|
26
|
-
|
27
|
-
if 1 > uploads_pull_server or roles(:app).count < uploads_pull_server
|
28
|
-
run_locally do
|
29
|
-
error "Unable to locate a server with an id '#{uploads_pull_server}'"
|
30
|
-
end
|
31
|
-
|
32
|
-
next
|
33
|
-
end
|
34
|
-
|
35
|
-
uploads_pull_server = roles(:app)[uploads_pull_server - 1]
|
36
|
-
|
37
|
-
on roles(:app) do |server|
|
38
|
-
next unless server.matches? uploads_pull_server
|
39
|
-
|
40
|
-
unless test("[ -d #{remote_path} ]")
|
41
|
-
error "There isn't a #{directory} directory on #{server.user}@#{server.hostname}"
|
42
|
-
|
43
|
-
next
|
44
|
-
end
|
45
|
-
|
46
|
-
run_locally do
|
47
|
-
execute :mkdir, "-p", local_path
|
48
|
-
end
|
49
|
-
|
50
|
-
info "Pulling #{directory} directory from #{server.user}@#{server.hostname}"
|
51
|
-
|
52
|
-
# Fix for rsync
|
53
|
-
remote_path += "/"
|
54
|
-
|
55
|
-
run_locally do
|
56
|
-
execute :rsync, "-lrtvzO", "--delete-before", (server.port ? "-e 'ssh -p #{server.port}'" : nil), "#{server.user}@#{server.hostname}:#{remote_path}", local_path
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
set :uploads_pull_server, nil
|
61
|
-
end
|
62
|
-
|
63
2
|
desc "Push up the uploads directory"
|
64
3
|
task :push do
|
65
4
|
directory = File.join("wp-content", "uploads")
|
data/wordpresstrano.gemspec
CHANGED