matthewtodd-wordpress 0.6.2 → 0.7.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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.7.0
2
+
3
+ * Rather than copy-pasting Capistrano's deploy.rb, we just add some behavior in after hooks. (Excellent idea from Michael Hale, http://github.com/mikehale.) So, while "require 'wordpress/recipes/deploy'" will work for now, albeit with a deprecation notice, you should change your Capfile to look something like:
4
+
5
+ require 'rubygems'
6
+ require 'wordpress'
7
+ load 'deploy'
8
+ load 'deploy/wordpress'
9
+ load 'config/deploy'
10
+
1
11
  == 0.6.2
2
12
 
3
13
  * BUGFIX: escape string interpolation when setting up config/deploy.rb. (Thanks to Alex MacCaw, http://github.com/maccman)
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@ Manages a Wordpress project Rails-ishly.
2
2
 
3
3
  * <tt>wordpressify</tt> sets up a new project and upgrades an existing one to the latest Wordpress.
4
4
  * <tt>cap deploy:setup</tt> and <tt>cap deploy</tt> do the right thing, handling <tt>wp-config.php</tt>.
5
- * <tt>cap deploy:upgrade</tt> additionally backs up your database and disables your plugins, as recommended[http://codex.wordpress.org/Upgrading_WordPress_Extended].
5
+ * <tt>cap wordpress:upgrade</tt> additionally backs up your database and disables your plugins, as recommended[http://codex.wordpress.org/Upgrading_WordPress_Extended].
6
6
  * <tt>script/server</tt> fires up lighttpd for local development.
7
7
 
8
8
  ==Installation
@@ -0,0 +1,5 @@
1
+ # Add our recipies directory to Capistrano's load_path.
2
+ if defined?(Capistrano)
3
+ config = Capistrano::Configuration.instance
4
+ config.load_paths << File.expand_path(File.join(File.dirname(__FILE__), 'recipes')) unless config.nil?
5
+ end
data/lib/wordpress/cli.rb CHANGED
@@ -15,8 +15,11 @@ module Wordpress
15
15
  def run
16
16
  directory(base) do
17
17
  file 'Capfile', <<-END
18
- %w(rubygems wordpress).each { |lib| require lib }
19
- require 'wordpress/recipes/deploy'
18
+ require 'rubygems'
19
+ require 'wordpress'
20
+
21
+ load 'deploy'
22
+ load 'deploy/wordpress'
20
23
  load 'config/deploy'
21
24
  END
22
25
 
@@ -0,0 +1,55 @@
1
+ _cset(:database_name) { abort "Please specify the name of your Wordpress database, set :database_name, 'foo'" }
2
+ _cset(:database_username) { abort "Please specify the username for your Wordpress database, set :database_username, 'foo'" }
3
+ _cset(:database_password) { Capistrano::CLI.password_prompt("Please enter the database password for #{database_username} on #{database_name}: ") }
4
+
5
+ # QUESTION is there a better way than whacking what came before?
6
+ set :shared_children, %w(backups uploads)
7
+
8
+ def wordpress_config
9
+ require 'digest/sha1'
10
+ Wordpress.config(:db_name => database_name,
11
+ :db_user => database_username,
12
+ :db_password => database_password,
13
+ :auth_key => Digest::SHA1.hexdigest(rand.to_s),
14
+ :secure_auth_key => Digest::SHA1.hexdigest(rand.to_s),
15
+ :logged_in_key => Digest::SHA1.hexdigest(rand.to_s),
16
+ :nonce_key => Digest::SHA1.hexdigest(rand.to_s),
17
+ :abspath => '/../current/public/')
18
+ end
19
+
20
+ def wordpress_restore_script
21
+ "#!/bin/sh\ngzcat $1 | mysql -u #{database_username} -p #{database_name}"
22
+ end
23
+
24
+ # QUESTION is there a better way than overwriting these tasks?
25
+ namespace :deploy do
26
+ task(:start) {}
27
+ task(:restart) {}
28
+ task(:stop) {}
29
+ end
30
+
31
+ namespace :wordpress do
32
+ task :setup do
33
+ put wordpress_config, "#{shared_path}/wp-config.php", :mode => 0600
34
+ put wordpress_restore_script, "#{shared_path}/backups/restore", :mode => 0755
35
+ end
36
+
37
+ task :finalize_update do
38
+ run <<-CMD
39
+ rm -rf #{latest_release}/public/wp-config.php #{latest_release}/public/wp-content/uploads &&
40
+ ln -s #{shared_path}/wp-config.php #{latest_release}/public/wp-config.php &&
41
+ ln -s #{shared_path}/uploads #{latest_release}/public/wp-content/uploads
42
+ CMD
43
+ end
44
+
45
+ desc "Use this instead of `cap deploy` when you're deploying an upgraded version of Wordpress."
46
+ task :upgrade do
47
+ run "mysqldump -u #{database_username} -p#{database_password} --compress --opt --lock-tables=false --skip-add-locks --skip-extended-insert #{database_name} | gzip > #{shared_path}/backups/#{release_name}.sql.gz"
48
+ run "mysql -u #{database_username} -p#{database_password} -e 'update wp_options set option_value=\"a:0:{}\" where option_name=\"active_plugins\"' #{database_name}"
49
+ deploy.default
50
+ puts 'You should now visit wp-admin/upgrade.php and manually reactivate your plugins.'
51
+ end
52
+ end
53
+
54
+ after 'deploy:setup', 'wordpress:setup'
55
+ after 'deploy:finalize_update', 'wordpress:finalize_update'
@@ -1,335 +1,17 @@
1
- # =========================================================================
2
- # This file started as a direct copy of capistrano/recipes/deploy.
3
- # Thanks so much for Capistrano, Jamis!
4
- # =========================================================================
5
- require 'yaml'
6
- require 'capistrano/recipes/deploy/scm'
7
- require 'capistrano/recipes/deploy/strategy'
1
+ puts '-' * 72
2
+ puts 'DEPRECATION WARNING'
3
+ puts '-' * 72
4
+ puts 'wordpress/recipes/deploy will be removed in a future version.'
5
+ puts 'Please adjust your Capfile to look like this:'
6
+ puts
7
+ puts "require 'rubygems'"
8
+ puts "require 'wordpress'"
9
+ puts "load 'deploy'"
10
+ puts "load 'deploy/wordpress'"
11
+ puts "load 'config/deploy'"
12
+ puts
8
13
 
9
14
  Capistrano::Configuration.instance(:must_exist).load do
10
- def _cset(name, *args, &block) #:nodoc:
11
- unless exists?(name)
12
- set(name, *args, &block)
13
- end
14
- end
15
-
16
- # =========================================================================
17
- # These variables MUST be set in the client capfiles. If they are not set,
18
- # the deploy will fail with an error.
19
- # =========================================================================
20
-
21
- _cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
22
- _cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
23
- _cset(:database_name) { abort "Please specify the name of your Wordpress database, set :database_name, 'foo'" }
24
- _cset(:database_username) { abort "Please specify the username for your Wordpress database, set :database_username, 'foo'" }
25
-
26
- # =========================================================================
27
- # These variables may be set in the client capfile if their default values
28
- # are not sufficient.
29
- # =========================================================================
30
-
31
- _cset :scm, :subversion
32
- _cset :deploy_via, :checkout
33
-
34
- _cset(:deploy_to) { "/u/apps/#{application}" }
35
- _cset(:revision) { source.head }
36
-
37
- # =========================================================================
38
- # These variables should NOT be changed unless you are very confident in
39
- # what you are doing. Make sure you understand all the implications of your
40
- # changes if you do decide to muck with these!
41
- # =========================================================================
42
-
43
- _cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
44
- _cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { `#{cmd}` } } }
45
-
46
- _cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
47
-
48
- _cset(:release_name) { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
49
-
50
- _cset :version_dir, "releases"
51
- _cset :shared_dir, "shared"
52
- _cset :current_dir, "current"
53
-
54
- _cset(:releases_path) { File.join(deploy_to, version_dir) }
55
- _cset(:shared_path) { File.join(deploy_to, shared_dir) }
56
- _cset(:current_path) { File.join(deploy_to, current_dir) }
57
- _cset(:release_path) { File.join(releases_path, release_name) }
58
-
59
- _cset(:releases) { capture("ls -x #{releases_path}").split.sort }
60
- _cset(:current_release) { File.join(releases_path, releases.last) }
61
- _cset(:previous_release) { File.join(releases_path, releases[-2]) }
62
-
63
- _cset(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
64
- _cset(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
65
- _cset(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
66
-
67
- _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
68
-
69
- _cset(:database_password) { Capistrano::CLI.password_prompt("Please enter the database password for #{database_username} on #{database_name}: ") }
70
-
71
- # some tasks, like symlink, need to always point at the latest release, but
72
- # they can also (occassionally) be called standalone. In the standalone case,
73
- # the timestamped release_path will be inaccurate, since the directory won't
74
- # actually exist. This variable lets tasks like symlink work either in the
75
- # standalone case, or during deployment.
76
- _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
77
-
78
- # =========================================================================
79
- # These are helper methods that will be available to your recipes.
80
- # =========================================================================
81
-
82
- # Auxiliary helper method for the `deploy:check' task. Lets you set up your
83
- # own dependencies.
84
- def depend(location, type, *args) #:nodoc:
85
- deps = fetch(:dependencies, {})
86
- deps[location] ||= {}
87
- deps[location][type] ||= []
88
- deps[location][type] << args
89
- set :dependencies, deps
90
- end
91
-
92
- # Temporarily sets an environment variable, yields to a block, and restores
93
- # the value when it is done.
94
- def with_env(name, value) #:nodoc:
95
- saved, ENV[name] = ENV[name], value
96
- yield
97
- ensure
98
- ENV[name] = saved
99
- end
100
-
101
- # =========================================================================
102
- # These are the tasks that are available to help with deploying web apps,
103
- # and specifically, Wordpress. You can have cap give you a summary
104
- # of them with `cap -T'.
105
- # =========================================================================
106
-
107
- namespace :deploy do
108
- desc <<-DESC
109
- Copies your project and updates the symlink. It does this in a \
110
- transaction, so that if either `update_code' or `symlink' fail, all \
111
- changes made to the remote servers will be rolled back, leaving your \
112
- system in the same state it was in before `update' was invoked.
113
- DESC
114
- task :default do
115
- transaction do
116
- update_code
117
- symlink
118
- end
119
- end
120
-
121
- namespace :setup do
122
- desc <<-DESC
123
- Prepares one or more servers for deployment. Before you can use any \
124
- of the Capistrano deployment tasks with your project, you will need to \
125
- make sure all of your servers have been prepared with `cap deploy:setup'. When \
126
- you add a new server to your cluster, you can easily run the setup task \
127
- on just that server by specifying the HOSTS environment variable:
128
-
129
- $ cap HOSTS=new.server.com deploy:setup
130
-
131
- It is safe to run this task on servers that have already been set up; it \
132
- will not destroy any deployed revisions or data.
133
- DESC
134
- task :default, :except => { :no_release => true } do
135
- directories
136
- restore
137
- config
138
- end
139
-
140
- desc <<-DESC
141
- [internal] Creates deployment directories.
142
- DESC
143
- task :directories, :except => { :no_release => true } do
144
- dirs = [deploy_to, releases_path, shared_path]
145
- dirs += %w(backups uploads).map { |d| File.join(shared_path, d) }
146
- run "umask 02 && mkdir -p #{dirs.join(' ')}"
147
- end
148
-
149
- desc <<-DESC
150
- [internal] Writes a script to restore a database backup.
151
- DESC
152
- task :restore, :except => { :no_release => true } do
153
- put <<-END.gsub(/^ */, ''), "#{shared_path}/backups/restore", :mode => 0755
154
- #!/bin/sh
155
- gzcat $1 | mysql -u #{database_username} -p #{database_name}
156
- END
157
- end
158
-
159
- desc <<-DESC
160
- Creates a shared wp-config.php.
161
- DESC
162
- task :config, :except => { :no_release => true } do
163
- require 'digest/sha1'
164
- wp_config = Wordpress.config(:db_name => database_name,
165
- :db_user => database_username,
166
- :db_password => database_password,
167
- :auth_key => Digest::SHA1.hexdigest(rand.to_s),
168
- :secure_auth_key => Digest::SHA1.hexdigest(rand.to_s),
169
- :logged_in_key => Digest::SHA1.hexdigest(rand.to_s),
170
- :nonce_key => Digest::SHA1.hexdigest(rand.to_s),
171
- :abspath => '/../current/public/')
172
-
173
- put wp_config, "#{shared_path}/wp-config.php", :mode => 0600
174
- end
175
- end
176
-
177
- desc <<-DESC
178
- [internal] Copies your project to the remote servers. This is the first stage \
179
- of any deployment; moving your updated code and assets to the deployment \
180
- servers. You will rarely call this task directly, however; instead, you \
181
- should call the `deploy' task (to do a complete deploy) or the `update' \
182
- task (if you want to perform the `restart' task separately).
183
-
184
- You will need to make sure you set the :scm variable to the source \
185
- control software you are using (it defaults to :subversion), and the \
186
- :deploy_via variable to the strategy you want to use to deploy (it \
187
- defaults to :checkout).
188
- DESC
189
- task :update_code, :except => { :no_release => true } do
190
- on_rollback { run "rm -rf #{release_path}; true" }
191
- strategy.deploy!
192
- finalize_update.default
193
- end
194
-
195
- namespace :finalize_update do
196
- desc <<-DESC
197
- [internal] Touches up the released code. This is called by update_code \
198
- after the basic deploy finishes.
199
-
200
- This task will make the release group-writable (if the :group_writable \
201
- variable is set to true, which is the default). It will then set up \
202
- symlinks to the shared directory for the uploads directory.
203
- DESC
204
- task :default, :except => { :no_release => true } do
205
- chmod
206
- symlink_shared_paths
207
- config
208
- end
209
-
210
- desc <<-DESC
211
- [internal] Makes the release group writable, if desired.
212
- DESC
213
- task :chmod, :except => { :no_release => true } do
214
- run "chmod -fR g+w #{latest_release}" if fetch(:group_writable, true)
215
- end
216
-
217
- desc <<-DESC
218
- [internal] Symlinks shared paths, like uploads, into the release.
219
- DESC
220
- task :symlink_shared_paths, :except => { :no_release => true } do
221
- run <<-CMD
222
- rm -rf #{latest_release}/public/wp-content/uploads &&
223
- ln -s #{shared_path}/uploads #{latest_release}/public/wp-content/uploads
224
- CMD
225
- end
226
-
227
- desc <<-DESC
228
- [internal] Symlinks the shared wp-config.php into the release.
229
- DESC
230
- task :config, :except => { :no_release => true } do
231
- run <<-CMD
232
- rm -f #{latest_release}/public/wp-config.php &&
233
- ln -s #{shared_path}/wp-config.php #{latest_release}/public/wp-config.php
234
- CMD
235
- end
236
- end
237
-
238
- desc <<-DESC
239
- [internal] Updates the symlink to the most recently deployed version. Capistrano works \
240
- by putting each new release of your application in its own directory. When \
241
- you deploy a new version, this task's job is to update the `current' symlink \
242
- to point at the new version. You will rarely need to call this task \
243
- directly; instead, use the `deploy' task (which performs a complete \
244
- deploy, including `restart') or the 'update' task (which does everything \
245
- except `restart').
246
- DESC
247
- task :symlink, :except => { :no_release => true } do
248
- on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
249
- run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
250
- end
251
-
252
- desc <<-DESC
253
- Rolls back to a previous version. This is handy if you ever \
254
- discover that you've deployed a lemon; `cap rollback' and you're right \
255
- back where you were, on the previously deployed version.
256
- DESC
257
- task :rollback do
258
- if releases.length < 2
259
- abort "could not rollback the code because there is no prior release"
260
- else
261
- run "rm #{current_path}; ln -s #{previous_release} #{current_path} && rm -rf #{current_release}"
262
- end
263
- end
264
-
265
- namespace :database do
266
- desc <<-DESC
267
- Backup the database. This is HIGHLY recommended before upgrading \
268
- Wordpress.
269
-
270
- Backups may be restored manually by running
271
- \#{shared_path}/backups/restore filename.sql.gz.
272
- DESC
273
- task :backup do
274
- run "mysqldump -u #{database_username} -p#{database_password} --compress --opt --lock-tables=false --skip-add-locks --skip-extended-insert #{database_name} | gzip > #{shared_path}/backups/#{release_name}.sql.gz"
275
- end
276
- end
277
-
278
- namespace :plugins do
279
- desc 'Disable all plugins.'
280
- task :disable do
281
- run "mysql -u #{database_username} -p#{database_password} -e 'update wp_options set option_value=\"a:0:{}\" where option_name=\"active_plugins\"' #{database_name}"
282
- end
283
- end
284
-
285
- desc 'Backup the database, disable all plugins, and deploy.'
286
- task :upgrade do
287
- database.backup
288
- plugins.disable
289
- deploy.default
290
- puts 'You should now visit wp-admin/upgrade.php and manually reactivate your plugins.'
291
- end
292
-
293
- desc <<-DESC
294
- Clean up old releases. By default, the last 5 releases are kept on each \
295
- server (though you can change this with the keep_releases variable). All \
296
- other deployed revisions are removed from the servers. By default, this \
297
- will use sudo to clean up the old releases, but if sudo is not available \
298
- for your environment, set the :use_sudo variable to false instead.
299
- DESC
300
- task :cleanup, :except => { :no_release => true } do
301
- count = fetch(:keep_releases, 5).to_i
302
- if count >= releases.length
303
- logger.important "no old releases to clean up"
304
- else
305
- logger.info "keeping #{count} of #{releases.length} deployed releases"
306
-
307
- directories = (releases - releases.last(count)).map { |release|
308
- File.join(releases_path, release) }.join(" ")
309
-
310
- invoke_command "rm -rf #{directories}", :via => run_method
311
- end
312
- end
313
-
314
- namespace :pending do
315
- desc <<-DESC
316
- Displays the `diff' since your last deploy. This is useful if you want \
317
- to examine what changes are about to be deployed. Note that this might \
318
- not be supported on all SCM's.
319
- DESC
320
- task :diff, :except => { :no_release => true } do
321
- system(source.local.diff(current_revision))
322
- end
323
-
324
- desc <<-DESC
325
- Displays the commits since your last deploy. This is good for a summary \
326
- of the changes that have occurred since the last deploy. Note that this \
327
- might not be supported on all SCM's.
328
- DESC
329
- task :default, :except => { :no_release => true } do
330
- from = source.next_revision(current_revision)
331
- system(source.local.log(from))
332
- end
333
- end
334
- end
335
- end
15
+ load 'deploy'
16
+ load 'deploy/wordpress'
17
+ end
data/lib/wordpress.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'wordpress/release'
2
2
 
3
3
  module Wordpress #:nodoc:
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7.0'
5
5
 
6
6
  def self.config(options={})
7
7
  config = release.contents('wp-config-sample.php')
@@ -18,4 +18,5 @@ module Wordpress #:nodoc:
18
18
  end
19
19
  end
20
20
 
21
+ require 'wordpress/capistrano'
21
22
  require 'wordpress/cli'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matthewtodd-wordpress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Todd
@@ -9,20 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-21 00:00:00 -08:00
12
+ date: 2009-03-09 00:00:00 -07:00
13
13
  default_executable: wordpressify
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capistrano
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 2.2.0
23
+ version: 2.5.1
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: matthewtodd-wordpress-release
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -45,7 +47,9 @@ files:
45
47
  - README.rdoc
46
48
  - TODO.rdoc
47
49
  - bin/wordpressify
50
+ - lib/wordpress/capistrano.rb
48
51
  - lib/wordpress/cli.rb
52
+ - lib/wordpress/recipes/deploy/wordpress.rb
49
53
  - lib/wordpress/recipes/deploy.rb
50
54
  - lib/wordpress/servers/lighttpd.rb
51
55
  - lib/wordpress.rb
@@ -56,7 +60,7 @@ rdoc_options:
56
60
  - --main
57
61
  - README.rdoc
58
62
  - --title
59
- - wordpress-0.6.2
63
+ - wordpress-0.7.0
60
64
  - --inline-source
61
65
  - --line-numbers
62
66
  - --all