capistrano-wp 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,27 +11,239 @@ also deploy multisite environments with WP at the root).
11
11
 
12
12
  ## Usage
13
13
 
14
- See `doc/examples` for an example Capfile and capistrano config directory.
14
+ This is a plugin for the Capistrano deployment tool. If you are unfamiliar
15
+ with Capistrano, we would suggest at least familiarizing yoruself with
16
+ the general concepts outlined in the [Capistrano Wiki](https://github.com/capistrano/capistrano/wiki).
15
17
 
16
- General Capistrano usage:
18
+ ### Assumptions (Requirements)
19
+
20
+ - Your code repository is your webroot
21
+
22
+ ### Install / Setup
23
+
24
+ gem install capistrano-wp
25
+ cd /path/to/repository
26
+ capify-wp .
27
+
28
+ ### Abridged General Capistrano Usage
17
29
 
18
30
  1. Create a user for deploying your WordPress install
19
31
  2. Create an SSH key for the deploy user, and make sure you can SSH to it from your local machine
20
32
  3. [Install RubyGems][rubygems]. Crowd Favorite prefers to use [RVM][rvm] to maintain ruby versions, rubygems, and self-contained sets of gems.
21
33
  4. Install the capistrano-wp gem (which will install Capistrano and friends): `gem install capistrano-wp`
22
- 5. Ensure that your project is in a repository starting at the web root
23
- 6. Copy the example configuration (from doc/examples) into the root of your repository, and customize as appropriate
24
- 7. Make sure your `:deploy_to` path exists and is owned by the deploy user
25
- 8. Run `cap deploy:setup` to set up the initial directories
26
- 9. Run `cap deploy` to push out a new version of your code
27
- 10. Update your web server configuration to point to the current-release directory (in the `:deply_to` directory, named `httpdocs` by default)
28
- 11. Relax and enjoy painless deployment
34
+ 5. Follow **Install / Setup** steps above
35
+ 6. Make sure your `:deploy_to` path exists and is owned by the deploy user
36
+ 7. Run `cap deploy:setup` to set up the initial directories
37
+ 8. Run `cap deploy` to push out a new version of your code
38
+ 9. Update your web server configuration to point to the current-release directory (in the `:deply_to` directory, named `httpdocs` by default)
39
+ 10. Relax and enjoy painless deployment
29
40
 
30
- [rubygems]: http://rubygems.org/pages/download
31
- [rvm]: https://rvm.io/
41
+ ## Capistrano Multi-stage
42
+
43
+ This deployment strategy comes with multi-stage support baked in.
44
+
45
+ For documentation regarding this portion of functionality, see the
46
+ [Capistrano Multistage Documentation](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension).
47
+
48
+ ## Capistrano-WP Specific Features
49
+
50
+ ### Handling of WordPress
51
+
52
+ This gem handles WordPress via SVN directly from WordPress.org.
53
+
54
+ In your main `config/deploy.rb` file you will see how to decalare what
55
+ version of WordPress you wish to use by defining an SVN location
56
+ like `branches/3.6`, `tags/3.6.1` or even `trunk`
57
+
58
+ ```ruby
59
+ set :wordpress_version, "branches/3.5"
60
+ ```
61
+
62
+ It then places WordPress where you declare it to live within the stage
63
+ specific configuration files, for example `config/deploy/production.rb`
64
+
65
+ ```ruby
66
+ set(:wp_path) { File.join(release_path, "wp") }
67
+ ```
68
+
69
+ This places WordPress in a directory called "wp" within your webroot.
70
+
71
+ It also gracefully handles the situation where both your code repository
72
+ and WordPress live at the webroot
73
+
74
+ This process enables you to not have to track WordPress within your code repository.
75
+
76
+ ### Persistent file/directory symlinks
77
+
78
+ This gem augments the way capistrano handles directories you need to "persist"
79
+ between releases. Providing a declaritive interface for these items.
80
+
81
+ There are some common directories that WordPress needs to act this way. By
82
+ default, if the following directories exist in the "shared" directory, they
83
+ will be symlinked into every release.
84
+
85
+ - `cache` is linked to `wp-content/cache`
86
+ - `uploads` is linked to `wp-content/uploads`
87
+ - `blogs.dir` is linked to `wp-content/blogs.dir`
88
+
89
+ This is the way these would be declared, either in the main `config/deploy.rb` or
90
+ in your stage specific files, if they weren't defaults
91
+
92
+ ```ruby
93
+ set :wp_symlinks, [{
94
+ "cache" => "wp-content/cache"
95
+ "uploads" => "wp-content/uploads"
96
+ "blogs.dir" => "wp-content/blogs.dir"
97
+ }]
98
+ ```
99
+
100
+ These will happen without any further configuration changes. If you wish
101
+ to override any of these defaults, you can set the target of the link to `nil`
102
+
103
+ ```ruby
104
+ set :wp_symlinks, [{
105
+ "cache" => nil
106
+ }]
107
+ ```
108
+
109
+ This would turn off the default `cache` symlink
110
+
111
+ You can easily add your own project (or even stage) specific links
112
+
113
+ If you have a `customlink` directory in the shared directory, you can add
114
+ a custom link like so.
115
+
116
+ ```ruby
117
+ set :wp_symlinks, [{
118
+ "customlink" => "wp-content/themes/mytheme/customlinktarget"
119
+ }]
120
+ ```
121
+
122
+ ### Persistent Configs
123
+
124
+ These are handled almost identically as above except they are copied
125
+ from the shared directory instead of symlinked.
126
+
127
+ This is primarily for config files that are sometimes written
128
+ to by plugins. In some cases when php tries to write to a symbolic
129
+ link, the link is destroyed and becomes a zero byte file.
130
+
131
+ By default the following copies are attempted
132
+
133
+ ```ruby
134
+ set :wp_configs, [{
135
+ "db-config.php" => "/",
136
+ "advanced-cache.php" => "wp-content/",
137
+ "object-cache.php" => "wp-content/",
138
+ "*.html" => "/",
139
+ }]
140
+ ```
141
+
142
+ You can follow the same steps as the symlinks for modification or addition
143
+ to the default config copying rules.
144
+
145
+ ### Stage specfiic overrides
146
+
147
+ Stage specific overrides allow you to target specific configuration
148
+ files to their respective stage.
149
+
150
+ You need to use a specific set of `.htaccess` rules for production.
151
+
152
+ If you place a file named `production-htaccess` in your `config/` directory
153
+
154
+ and add it to your `:stage_specific_overrides` in your `config/deploy/production.rb`
155
+
156
+ ```ruby
157
+ set :stage_specific_overrides, {
158
+ ".htaccess" => ".htaccess"
159
+ }
160
+ ```
161
+
162
+ This will place the proper `production-htaccess` file in the root of
163
+ your next release, overriding any existing file of the same name.
164
+
165
+ By default, it looks for the common `.htaccess` situation
166
+ along withh `local-config.php`
167
+
168
+ ```ruby
169
+ set :stage_specific_overrides, {
170
+ "local-config.php" => "local-config.php",
171
+ ".htaccess" => ".htaccess"
172
+ }
173
+ ```
174
+
175
+ Modifications and additions are handled similarly to symlinks and
176
+ configs, but note the lack of a wrapping `[]`
177
+
178
+ ### Stripping out unnecessary files and directories
179
+
180
+ You can remove specific files and directories from your releases
181
+ at the time of deploy.
182
+
183
+ By default the list of things the gem strips out looks like this
184
+
185
+ ```ruby
186
+ set :copy_exclude, [
187
+ ".git",
188
+ "Capfile",
189
+ "/config",
190
+ "capinfo.json",
191
+ ".DS_Store",
192
+ ]
193
+ ```
194
+
195
+ This excludes the listed files from making it into a release
196
+
197
+ **For this you actually need to re-declare the set to add / remove these exclusions.**
198
+
199
+ For example, to allow the `.git` directory to exist in the releases, you would
200
+ re-declare the option completely. Removing the `.git` entry.
201
+
202
+ ```ruby
203
+ set :copy_exclude, [
204
+ "Capfile",
205
+ "/config",
206
+ "capinfo.json",
207
+ ".DS_Store",
208
+ ]
209
+ ```
210
+
211
+ This is usually placed in `config/deploy.rb` but can also be placed at the stage level.
212
+
213
+ ### Detecting Local Changes
214
+
215
+ This gem by default checks the current release for modifications since
216
+ it was deployed. Either you're dealing with clients that like to make
217
+ changes in production, or you have plugins that write configs and other
218
+ things to the file system. This step protects you against moving changes
219
+ that have happend in the target stage out of use.
220
+
221
+ When deploying, if it detects a change it will stop the deploy process, and
222
+ provide you with a listing of all the files that have been either added,
223
+ changed, or deleted.
224
+
225
+ At this point you can rectify the changes yourself if you wish, adding them to
226
+ your source control, or verifying you don't need them.
227
+
228
+ Then you call the deploy like this to force it to create the new release.
229
+
230
+ cap cf:localchanges:allow_differences deploy
231
+
232
+ This will tell the deploy to ignore any of these changes and proceed.
233
+
234
+ If you would like to turn this feature off, you can have it force this by
235
+ default with the following option set in either your main `config/deploy.rb`
236
+ or your stage specific files.
237
+
238
+ ```ruby
239
+ set :snapshot_allow_differences, true
240
+ ```
32
241
 
33
242
  ## Development
34
243
 
244
+ [rubygems]: http://rubygems.org/pages/download
245
+ [rvm]: https://rvm.io/
246
+
35
247
  gem install bundle
36
248
  bundle install
37
249
  rake install
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: #{File.basename($0)} [path]"
8
+
9
+ opts.on("-h", "--help", "Displays this help info") do
10
+ puts opts
11
+ exit 0
12
+ end
13
+
14
+ begin
15
+ opts.parse!(ARGV)
16
+ rescue OptionParser::ParseError => e
17
+ warn e.message
18
+ puts opts
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ if ARGV.empty?
24
+ abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
25
+ elsif !File.exists?(ARGV.first)
26
+ abort "`#{ARGV.first}' does not exist."
27
+ elsif !File.directory?(ARGV.first)
28
+ abort "`#{ARGV.first}' is not a directory."
29
+ elsif !File.writable?(ARGV.first)
30
+ abort "`#{ARGV.first}' is not writable by you."
31
+ elsif ARGV.length > 1
32
+ abort "Too many arguments; please specify only the directory to capify-wp."
33
+ end
34
+
35
+ def template_dir()
36
+ t = ["#{File.dirname(File.expand_path(__FILE__))}/../lib/capistrano/templates",
37
+ "#{Gem::Specification.find_by_name("capistrano-wp")}/lib/capisrano/templates"]
38
+ t.each { |dir| return dir if File.readable? dir }
39
+ raise "Paths invalid: #{t}" if not File.readable? t
40
+ end
41
+
42
+ base = ARGV.shift
43
+ templates = template_dir()
44
+
45
+ Dir.glob("#{templates}/**/*").each do |file|
46
+ target = file.gsub(templates, "")
47
+ next if target.empty?
48
+
49
+ target = File.join(base, target)
50
+
51
+ if File.exists? target
52
+ warn "[skip] '#{target}' already exists"
53
+ elsif File.exists? target.downcase
54
+ warn "[skip] '#{target.downcase}' exists, which could conflict with `#{target}'"
55
+ else
56
+ if File.directory? file
57
+ puts "[add] making directory '#{target}'"
58
+ FileUtils.mkdir_p(target)
59
+ else
60
+ puts "[add] writing '#{target}'"
61
+ FileUtils.cp file, target
62
+ end
63
+ end
64
+ end
65
+
66
+ puts "[done] capify-wped!"
@@ -5,12 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "capistrano-wp"
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Crowd Favorite"]
12
- s.date = "2013-07-15"
12
+ s.date = "2013-09-25"
13
13
  s.description = "Recipes for deploying and maintaining remote WordPress installations with\nCapistrano. Pulls in WordPress from SVN, optionally using a local or\nremote cache, and supports a number of common operations and tasks towards\nthe care and feeding of sites that may not be 100% maintained through\nversion control.\n"
14
+ s.executables = ["capify-wp"]
14
15
  s.extra_rdoc_files = [
15
16
  "LICENSE.txt",
16
17
  "README.md"
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
23
24
  "README.md",
24
25
  "Rakefile",
25
26
  "VERSION",
27
+ "bin/capify-wp",
26
28
  "capistrano-wp.gemspec",
27
29
  "doc/examples/Capfile",
28
30
  "doc/examples/config/deploy.rb",
@@ -31,6 +33,9 @@ Gem::Specification.new do |s|
31
33
  "doc/examples/config/staging-local-config.php",
32
34
  "lib/capistrano-wp.rb",
33
35
  "lib/capistrano/crowdfavorite/wordpress.rb",
36
+ "lib/capistrano/templates/Capfile",
37
+ "lib/capistrano/templates/config/deploy.rb",
38
+ "lib/capistrano/templates/config/deploy/production.rb",
34
39
  "lib/crowdfavorite.rb",
35
40
  "lib/crowdfavorite/support/capistrano_extensions.rb",
36
41
  "lib/crowdfavorite/support/namespace.rb",
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'railsless-deploy'
3
+ require 'crowdfavorite/wordpress'
4
+ load 'config/deploy' # remove this line to skip loading any of the default tasks
5
+
@@ -0,0 +1,26 @@
1
+ set :stages, %w(production)
2
+ set :default_stage, "production"
3
+
4
+ require 'capistrano/ext/multistage'
5
+
6
+ #=============================================================================
7
+ # app details and WordPress requirements
8
+
9
+ # tags/3.5.1, branches/3.5, trunk
10
+ set :wordpress_version, "trunk"
11
+ set :application, "my-wordpress-site.com"
12
+
13
+ #=============================================================================
14
+ # app source repository configuration
15
+
16
+ set :scm, :git
17
+ set :repository, ""
18
+ set :git_enable_submodules, 1
19
+ #set :git_shallow_clone, 1
20
+
21
+ #=============================================================================
22
+ # Housekeeping
23
+ # clean up old releases on each deploy
24
+ set :keep_releases, 5
25
+ after "deploy:create_symlink", "deploy:cleanup"
26
+
@@ -0,0 +1,80 @@
1
+ set :stage, "production"
2
+
3
+ set :user, 'deployuser'
4
+ set :use_sudo, false
5
+
6
+ server '0.0.0.0', :app, :web, :db, :primary => true
7
+
8
+ ## For multiple server setups
9
+ #
10
+ # server '0.0.0.0', :app, :web, :primary => true
11
+ # server '0.0.0.0', :app, :web
12
+ # # Don't push code to this server with 'cap deploy'
13
+ # server '0.0.0.0', :db, :no_release => true
14
+
15
+ # Site base directory
16
+ set :base_dir, "/var/local/www/example"
17
+ set :deploy_to, File.join(fetch(:base_dir))
18
+
19
+ # Webroot
20
+ set :current_dir, "httpdocs"
21
+
22
+ # Path to WordPress, supports WP at the root (empty string) and WordPress
23
+ # in a custom location (webroot/wp in our example).
24
+ set(:wp_path) { File.join(release_path, "wp") }
25
+
26
+ # Deploy strategy - use :remote_cache when possible, but some servers need :copy
27
+ #set :deploy_via, :copy
28
+ set :deploy_via, :remote_cache
29
+
30
+ # Specify a git branch to deploy
31
+ #
32
+ # Using fetch() here allows you to set your branch from the command line,
33
+ # but allows a default, "master" in this case.
34
+ #
35
+ # cap deploy -s branch=my-custom-branch
36
+ #
37
+ set :branch, fetch(:branch, "master")
38
+
39
+ #=============================================================================
40
+ # Files to link or copy into web root from capistrano's shared directory
41
+ # Symlinks are symlinked in
42
+
43
+ # wp_symlinks defaults to:
44
+ # "cache" => "wp-content/cache"
45
+ # "uploads" => "wp-content/uploads"
46
+ # "blogs.dir" => "wp-content/blogs.dir"
47
+ #
48
+ # To override, set the target to nil:
49
+ #
50
+ #set :wp_symlinks, [{
51
+ # "cache" => nil
52
+ #}]
53
+ #
54
+ # Or add other files:
55
+ #
56
+ #set :wp_symlinks, [{
57
+ # "authcache" => "wp-content/authcache"
58
+ #}]
59
+ #
60
+ # Configs are copied in, and default to:
61
+ # "db-config.php" => "/",
62
+ # "advanced-cache.php" => "wp-content/",
63
+ # "object-cache.php" => "wp-content/",
64
+ # "*.html" => "/",
65
+ #
66
+ # To override (like wp_symlinks):
67
+ #set :wp_configs, [{
68
+ #}]
69
+ #
70
+ # Stage-specific overrides are copied from the config directory,
71
+ # like production-example.txt or staging-example.txt
72
+ # Default list:
73
+ #
74
+ # "local-config.php" => "local-config.php",
75
+ # ".htaccess" => ".htaccess"
76
+ #
77
+ # To override or add other files (as above, but note no []):
78
+ #
79
+ #set :stage_specific_overrides, {
80
+ #}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-wp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-15 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -168,7 +168,8 @@ description: ! 'Recipes for deploying and maintaining remote WordPress installat
168
168
 
169
169
  '
170
170
  email:
171
- executables: []
171
+ executables:
172
+ - capify-wp
172
173
  extensions: []
173
174
  extra_rdoc_files:
174
175
  - LICENSE.txt
@@ -181,6 +182,7 @@ files:
181
182
  - README.md
182
183
  - Rakefile
183
184
  - VERSION
185
+ - bin/capify-wp
184
186
  - capistrano-wp.gemspec
185
187
  - doc/examples/Capfile
186
188
  - doc/examples/config/deploy.rb
@@ -189,6 +191,9 @@ files:
189
191
  - doc/examples/config/staging-local-config.php
190
192
  - lib/capistrano-wp.rb
191
193
  - lib/capistrano/crowdfavorite/wordpress.rb
194
+ - lib/capistrano/templates/Capfile
195
+ - lib/capistrano/templates/config/deploy.rb
196
+ - lib/capistrano/templates/config/deploy/production.rb
192
197
  - lib/crowdfavorite.rb
193
198
  - lib/crowdfavorite/support/capistrano_extensions.rb
194
199
  - lib/crowdfavorite/support/namespace.rb