capistrano-cul 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93214bb1fa3f153183f924a74216fc89974c091b
4
- data.tar.gz: 914740fa3ffadf58b9127f1ed085a70cbab364d0
3
+ metadata.gz: dca3bc890ad9faa20306aaed7454ad9d2ddb1db6
4
+ data.tar.gz: 5963b8b24d7f7c4b50dd62f96ba2f3d6d9e7a0a3
5
5
  SHA512:
6
- metadata.gz: 0da3180a64afe3b5344d6e439ccee76133a75b0223c4d3d41dd91f15e7878184453654b95ce3c3057390929bd8d8ea355140f005d5f6f5a539bef069abbaf87f
7
- data.tar.gz: e3a159f3db8871fc1aeef9720bc03b38211eb92362c7f87e48e77f3125cd97fdd16a91bdc1ed2d0988753593fd5dd0070daa39f6bf0d4cfaead559267903f2b4
6
+ metadata.gz: f3bd0ddad0c8c40937d698fdd1f9083de018653b1774626f72980d565269dd988799f751da06655987cff80ecaeab64044e4d1fc9cbc7eb60c09652488464dad
7
+ data.tar.gz: b5ec2011f7e9551442968a852e78949a36f8c6a9309cebec824ed8052eea445cb590af7e54858b28d259044f01a8217ed114c3d8eaf83fd02b8713f290cb1f4b
data/CHANGELOG.md CHANGED
@@ -4,9 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+
8
+
7
9
  ## [Unreleased]
10
+ ### Added
11
+
12
+ ## [0.0.2] - 2017-08-08
13
+ ### Added
14
+ - Adding Wordpress deployment capabilities
8
15
 
9
16
  ## [0.0.1] - 2017-08-05
10
17
  ### Added
11
- - Added cul:downtime task
12
- - Added cul:auto_tag task
18
+ - Added `cul:downtime` task
19
+ - Added `cul:auto_tag` task
data/README.md CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  Capistrano v3 tasks shared across CUL projects.
4
4
 
5
+ This gem provides common cap tasks that are used in almost every cul project. It also includes a set of cap tasks and hooks that are specific for Wordpress deployments. Do not include the Wordpress library if you are not deploying a Wordpress site.
6
+
5
7
  ## Installation
6
8
 
9
+ ### Install gem
7
10
  Add this line to your application's Gemfile:
8
11
 
9
12
  ```ruby
10
- gem 'capistrano-cul', git: 'https://github.com/cul/capistrano-cul'
13
+ gem 'capistrano-cul'
11
14
  ```
12
15
 
13
- _Note:_ If installing in a rails application, should only be in `:development` and `:test` groups.
16
+ _Note:_ If installing in a rails application, gem should only be installed in `:development` and `:test` groups.
14
17
 
15
18
 
16
19
  And then execute:
@@ -21,14 +24,21 @@ Or install it yourself as:
21
24
 
22
25
  $ gem install capistrano-cul
23
26
 
27
+ ### Add Capistrano::Cul tasks to `Capfile`
24
28
  In your application's `Capfile` include:
25
29
 
30
+ ```ruby
31
+ require 'capistrano/cul'
26
32
  ```
33
+
34
+ For Wordpress deployments, in your application's `Capfile` include:
35
+ ```ruby
27
36
  require 'capistrano/cul'
37
+ require 'capistrano/cul/wp'
28
38
  ```
29
39
 
30
40
  ## Usage
31
- Two tasks are provided as part of this gem:
41
+ ### Shared cap tasks (`capistrano/cul`)
32
42
  1. `cap {env} cul:auto_tag`
33
43
 
34
44
  Tags the current commit as the version number provided in `VERSION`.
@@ -36,6 +46,59 @@ Two tasks are provided as part of this gem:
36
46
 
37
47
  Pulls down the downtime branch of the repository to a `/downtime` directory and symlinks `current` to `downtime`. To undo this action, redeploy your application.
38
48
 
49
+ ### Wordpress deployment (`capistrano/cul/wp`)
50
+ #### Tasks
51
+ 1. `cap {env} cul:wp:setup`
52
+
53
+ Sets up a WordPress docroot and runs deployment; does not install WordPress and does not create any users.
54
+ 2. `cap {env} cul:wp:install`
55
+
56
+ Runs a WordPress installation for a newly set up instance and creates a new admin user.
57
+ 3. `cap {env} cul:wp:symlink_custom_plugins_and_themes`
58
+
59
+ Creates symlinks for custom plugins and themes as part of a WordPress deployment. Generally run as an `after :deploy` hook.
60
+ 4. `cap {env} cul:wp:update:core`
61
+
62
+ Updates WordPress core to the latest version.
63
+ 5. `cap {env} cul:wp:update:plugins`
64
+
65
+ Updates non-repo-managed plugins to the latest version.
66
+ 6. `cap {env} cul:wp:update:themes`
67
+
68
+ Updates non-repo-managed themes to the latest version.
69
+ 7. `cap {env} cul:wp:update:all`
70
+
71
+ Updates WordPress core, plugins, and themes (in that order) by calling update:core, update:plugins and update:themes tasks.
72
+
73
+ #### Configurable variables
74
+ The Wordpress tasks listed above require the following variables .
75
+ ```ruby
76
+ set :wp_docroot # (string) Path to webserver document root for site
77
+ set :wp_data_path # (string) Path to data directory (outside of wp_docroot) that contains wp-content
78
+ set :url # (string) Public website URL
79
+ set :title # (string) Website title
80
+ set :multisite # (boolean) Whether or not this is a multisite wordpress installation
81
+ set :wp_custom_plugins # (hash) Map of custom plugin file/directory names to repo-relative paths
82
+ set :wp_custom_themes # (hash) Map of custom theme file/directory names to repo-relative paths
83
+ ```
84
+
85
+ Here's a sample configuration:
86
+
87
+ ```ruby
88
+ set :wp_docroot, "#{fetch(:deploy_to)}/wp_docroot"
89
+ set :wp_data_path, "/path/to/data/directory/#{fetch(:application)}_#{fetch(:stage)}"
90
+ set :multisite, false
91
+ set :title, 'Amazing WordPress Site'
92
+
93
+ set :wp_custom_plugins, {
94
+ 'custom-plugin-file.php' => 'plugins/custom-plugin-file.php',
95
+ 'custom-plugin-directory' => 'plugins/custom-plugin-directory'
96
+ }
97
+ set :wp_custom_themes, {
98
+ 'mytheme' => 'themes/mytheme'
99
+ }
100
+ ```
101
+
39
102
  ## Development
40
103
 
41
104
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
2
 
4
3
  # Do nothing by default
5
4
  task :default
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,2 @@
1
+ load File.expand_path('../../tasks/wp.cap', __FILE__)
2
+ load File.expand_path('../../tasks/wp/update.cap', __FILE__)
@@ -1,2 +1 @@
1
1
  require_relative 'cul/tasks'
2
- require_relative 'cul/hooks'
@@ -0,0 +1,39 @@
1
+ namespace :cul do
2
+ namespace :wp do
3
+ namespace :update do
4
+ desc "Updates WordPress core to the latest version."
5
+ task :core do
6
+ on roles(:web) do
7
+ within fetch(:wp_docroot) do
8
+ execute :wp, 'core', 'update'
9
+ end
10
+ end
11
+ end
12
+
13
+ desc "Updates non-repo-managed plugins to the latest version."
14
+ task :plugins do
15
+ on roles(:web) do
16
+ within fetch(:wp_docroot) do
17
+ execute :wp, 'plugin', 'update', '--all'
18
+ end
19
+ end
20
+ end
21
+
22
+ desc "Updates non-repo-managed themes to the latest version."
23
+ task :themes do
24
+ on roles(:web) do
25
+ within fetch(:wp_docroot) do
26
+ execute :wp, 'theme', 'update', '--all'
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "Updates WordPress core, plugins, and themes (in that order)."
32
+ task :all do
33
+ invoke 'cul:wp:update:core'
34
+ invoke 'cul:wp:update:plugins'
35
+ invoke 'cul:wp:update:themes'
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,137 @@
1
+ namespace :cul do
2
+ namespace :wp do
3
+ after :deploy, 'cul:wp:symlink_custom_plugins_and_themes'
4
+
5
+ desc "Creates symlinks for custom plugins and themes as part of a WordPress deployment. Generally run as an `after :deploy` hook."
6
+ task :symlink_custom_plugins_and_themes do
7
+ symlink_custom_plugins_and_themes
8
+ end
9
+
10
+ # Runs normal deploy task, downloads new copy of WP, sets up docroot, runs
11
+ # deploy command, sets up symlinks. Does not run WP install and does not
12
+ # create any wp users.
13
+ desc "Sets up a WordPress docroot and runs deployment; does not install wordpress and does not create any users"
14
+ task :setup do
15
+ puts "Deploying repo branch: #{fetch(:branch)}"
16
+
17
+ set :wp_version, ask('WordPress version to download:', 'latest')
18
+ # Printing out wp_version here because the `set` command above only runs
19
+ # the first time its associated symbol is referenced, and we want to
20
+ # capture version before running any other commands.
21
+ puts "Setting up wp_version: #{fetch(:wp_version)}"
22
+
23
+ require_cap_params!([:branch, :wp_version, :wp_docroot, :wp_data_path])
24
+
25
+ on roles(:web) do
26
+ wp_docroot_wp_config_file_path = File.join(fetch(:wp_docroot), 'wp-config.php')
27
+ wp_docroot_robots_txt_file_path = File.join(fetch(:wp_docroot), 'robots.txt')
28
+ wp_docroot_wp_content_path = File.join(fetch(:wp_docroot), 'wp-content')
29
+
30
+ shared_wp_config_file_path = shared_path.join('wp-config.php')
31
+ shared_robots_txt_file_path = shared_path.join('robots.txt')
32
+
33
+ wp_data_wp_content_path = File.join(fetch(:wp_data_path), 'wp-content')
34
+
35
+ invoke 'deploy' # Deploy before doing setup
36
+
37
+ # Create nginx logs directory if it doesn't already exist
38
+ execute :mkdir, '-p', deploy_path.join('logs')
39
+
40
+ # Make full path to wp_docroot directory if not exist
41
+ execute :mkdir, '-p', fetch(:wp_docroot)
42
+
43
+ # Make full path to wp_data_path if not exist
44
+ execute :mkdir, '-p', fetch(:wp_data_path)
45
+
46
+ # If wp_docroot/wp-includes does not exist, do wordpress download
47
+ unless test("[ -d #{File.join(fetch(:wp_docroot), 'wp-includes')} ]")
48
+ # Download and unpack new WP instance to wp_docroot
49
+ execute :wp, 'core', ['download', "--version=#{fetch(:wp_version)}", "--path=#{fetch(:wp_docroot)}"]
50
+ end
51
+
52
+ # Check for wp-config.php file in shared. Create if it doesn't exist.
53
+ unless test("[ -f #{shared_wp_config_file_path} ]")
54
+ # If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
55
+ execute :cp, File.join(fetch(:wp_docroot), 'wp-config-sample.php'), shared_wp_config_file_path
56
+ end
57
+
58
+ # Delete original wp-sample-config.php
59
+ execute :rm, '-f', File.join(fetch(:wp_docroot), 'wp-config-sample.php')
60
+ # Create symlink for wp_document_root wp-config.php to 'shared' version.
61
+ execute :ln, '-sf', shared_wp_config_file_path, wp_docroot_wp_config_file_path
62
+
63
+ # Check for robots.txt file in shared. Create if it doesn't exist.
64
+ unless test("[ -f #{shared_robots_txt_file_path} ]")
65
+ execute "echo -e \"User-agent: *\nDisallow: /\" > #{shared_robots_txt_file_path}"
66
+ end
67
+ # Create symlink for wp_document_root robots.txt to 'shared' version.
68
+ execute :ln, '-sf', shared_robots_txt_file_path, wp_docroot_robots_txt_file_path
69
+
70
+ # Check for wp-content directory at wp_data_wp_content_path. Create if it doesn't exist.
71
+ unless test("[ -d #{wp_data_wp_content_path} ]")
72
+ # If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
73
+ execute :cp, '-r', wp_docroot_wp_content_path, wp_data_wp_content_path
74
+ end
75
+ # Delete original wp-content directory
76
+ execute :rm, '-rf', wp_docroot_wp_content_path
77
+ # Create symlink for wp_document_root wp-content to wp_data_wp_content_path
78
+ execute :ln, '-sf', wp_data_wp_content_path, wp_docroot_wp_content_path
79
+ end
80
+
81
+ symlink_custom_plugins_and_themes
82
+ end
83
+
84
+ desc "Runs a WordPress installation for a newly set up instance and creates a new admin user"
85
+ task :install do
86
+ puts "Please provide administrative credentials:"
87
+ ask(:admin_user, "Admin username:")
88
+ ask(:admin_password, "Admin password:")
89
+ ask(:admin_email, "Admin email:")
90
+
91
+ require_cap_params!([:url, :title, :admin_user, :admin_password, :admin_email])
92
+
93
+ on roles(:web) do
94
+ within fetch(:wp_docroot) do
95
+ execute :wp, 'core', fetch(:multisite) ? 'multisite-install' : 'install',
96
+ "--url='#{fetch(:url)}'",
97
+ "--title='#{fetch(:title)}'",
98
+ "--admin_user='#{fetch(:admin_user)}'",
99
+ "--admin_password='#{fetch(:admin_password)}'",
100
+ "--admin_email='#{fetch(:admin_email)}'"
101
+ end
102
+ end
103
+ end
104
+
105
+ def self.require_cap_params!(vars)
106
+ validate vars do |key, value|
107
+ if value.nil? || value.empty?
108
+ raise Capistrano::ValidationError, "Missing required parameter #{key}"
109
+ end
110
+ end
111
+ end
112
+
113
+ def self.symlink_custom_plugins_and_themes
114
+ on roles(:web) do
115
+ wp_data_wp_content_path = File.join(fetch(:wp_data_path), 'wp-content')
116
+ wp_data_plugin_path = File.join(wp_data_wp_content_path, 'plugins')
117
+ wp_data_themes_path = File.join(wp_data_wp_content_path, 'themes')
118
+
119
+ if test("[ -d #{wp_data_wp_content_path} ]")
120
+ # Remove old symlinks
121
+ [wp_data_plugin_path, wp_data_themes_path].each do |dir|
122
+ execute :find, dir, '-maxdepth 1', '-type l', '-exec rm {} \;'
123
+ end
124
+
125
+ # Add latest symlinks
126
+ fetch(:wp_custom_plugins, {}).each do |plugin, repo_relative_path|
127
+ execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_data_plugin_path, plugin)
128
+ end
129
+
130
+ fetch(:wp_custom_themes, {}).each do |theme, repo_relative_path|
131
+ execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_data_themes_path, theme)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-cul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carla Galarza
@@ -55,10 +55,11 @@ files:
55
55
  - VERSION
56
56
  - capistrano-cul.gemspec
57
57
  - lib/capistrano/cul.rb
58
- - lib/capistrano/cul/hooks.rb
59
58
  - lib/capistrano/cul/tasks.rb
59
+ - lib/capistrano/cul/wp.rb
60
60
  - lib/capistrano/tasks/cul.cap
61
- - lib/capistrano/tasks/hooks.cap
61
+ - lib/capistrano/tasks/wp.cap
62
+ - lib/capistrano/tasks/wp/update.cap
62
63
  homepage: https://github.com/cul/capistrano-cul
63
64
  licenses:
64
65
  - MIT
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  requirements: []
81
82
  rubyforge_project:
82
- rubygems_version: 2.5.2
83
+ rubygems_version: 2.6.12
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: Common capistrano tasks shared across projects at CUL
@@ -1 +0,0 @@
1
- load File.expand_path('../../tasks/hooks.cap', __FILE__)
File without changes