wpcap 0.1.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.
@@ -0,0 +1,17 @@
1
+ configuration = Capistrano::Configuration.respond_to?(:instance) ?
2
+ Capistrano::Configuration.instance(:must_exist) :
3
+ Capistrano.configuration(:must_exist)
4
+
5
+ configuration.load do
6
+ namespace :varnish do
7
+ desc "Install the latest release of Varnish"
8
+ task :install, roles: :app do
9
+
10
+ run "#{sudo} curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -"
11
+ run "#{sudo} echo 'deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0' | sudo tee -a /etc/apt/sources.list"
12
+ run "#{sudo} apt-get -y update"
13
+ run "#{sudo} apt-get -y install varnish"
14
+ end
15
+ after "deploy:install", "varnish:install"
16
+ end
17
+ end
@@ -0,0 +1,185 @@
1
+ require 'wpcap'
2
+ require 'wpcap/utility'
3
+
4
+ configuration = Capistrano::Configuration.respond_to?(:instance) ?
5
+ Capistrano::Configuration.instance(:must_exist) :
6
+ Capistrano.configuration(:must_exist)
7
+
8
+ configuration.load do
9
+ extraction_terms = [ {"DB_CHARSET" => "encoding"}, {"DB_NAME" => "database"} , {"DB_USER" => "username"} , {"DB_PASSWORD" => "password" } , {"DB_HOST" => "host"}]
10
+
11
+ set_default :uploads_path, "wp-content/uploads"
12
+
13
+ if mamp
14
+ set_default :local_mysql_path , "/Applications/MAMP/Library/bin/"
15
+ set_default :local_httpd_conf_path , "/Applications/MAMP/conf/apache/httpd.conf"
16
+ else
17
+ set_default :local_mysql_path , ""
18
+ set_default :local_httpd_conf_path , "/etc/apache2/httpd.conf"
19
+ end
20
+
21
+
22
+ namespace :db do
23
+ desc "Alias for db:mysql:pull"
24
+ task :pull , :roles => :db do
25
+ db.mysql.pull
26
+ end
27
+
28
+ desc "Alias for db:mysql:push"
29
+ task :push , :roles => :db do
30
+ db.mysql.push
31
+ end
32
+ end
33
+
34
+ namespace :deploy do
35
+ desc "Setup shared application directories and permissions after initial setup"
36
+ task :setup, :roles => :web do
37
+ # remove Capistrano specific directories
38
+
39
+ run "rm -Rf #{shared_path}/pids"
40
+ run "rm -Rf #{shared_path}/system"
41
+
42
+ # create shared directories
43
+ run "mkdir -p #{shared_path}/uploads"
44
+ run "mkdir -p #{shared_path}/cache"
45
+ run "mkdir -p #{shared_path}/logs"
46
+ run "mkdir -p #{shared_path}/config"
47
+ run "mkdir -p #{backups_path}"
48
+
49
+ # setup for wp total cache
50
+ run "touch #{shared_path}/config/nginx.conf"
51
+
52
+ # set correct permissions
53
+ run "chmod -R 755 #{shared_path}/uploads"
54
+ run "chmod -R 755 #{shared_path}/cache"
55
+ end
56
+
57
+ desc "[internal] Touches up the released code. This is called by update_code after the basic deploy finishes."
58
+ task :finalize_update, :roles => :web, :except => { :no_release => true } do
59
+ # remove shared directories
60
+ run "rm -Rf #{latest_release}/app/#{uploads_path}"
61
+ run "rm -Rf #{latest_release}/wp-content/cache"
62
+ run "rm -Rf #{latest_release}/nginx.conf"
63
+
64
+ # Removing cruft files.
65
+ run "rm -Rf #{latest_release}/license.txt"
66
+ run "rm -Rf #{latest_release}/readme.html"
67
+
68
+ end
69
+ desc "[internal] Verify Code and repo is ready to be released"
70
+ task :check_code, :except => { :no_release => true } do
71
+ #make sure the user has actually set up the wordpress install
72
+ unless File.exists?("app/wp-config.php")
73
+ Wpcap::Utility.error("This Wordpress Installation does not appear to have a wp-config.php file (Please create one at app/wp-config.php )")
74
+ abort
75
+ end
76
+ end
77
+ before "deploy", "deploy:check_code"
78
+ before "deploy:setup", "deploy:check_code"
79
+ end
80
+
81
+ namespace :wordpress do
82
+
83
+ desc "Links the correct settings file"
84
+ task :symlink, :roles => :web, :except => { :no_release => true } do
85
+ run "ln -nfs #{shared_path}/uploads #{latest_release}/app/#{uploads_path}"
86
+ run "ln -nfs #{shared_path}/cache #{latest_release}/app/wp-content/cache"
87
+ run "ln -nfs #{shared_path}/config/nginx.conf #{latest_release}/app/nginx.conf"
88
+ end
89
+
90
+ desc "Generate a wp-config.php based upon the app server geneated db password"
91
+ task :create_config, :roles => :web, :except => { :no_release => true } do
92
+ run "rm #{latest_release}/app/wp-config.php"
93
+ wpconfig = run_locally "cat app/wp-config.php"
94
+ stage_config = "/tmp/wp-config.#{stage}"
95
+ db.mysql.prepare_env
96
+
97
+ extraction_terms.each do |env|
98
+ term = env.keys.first
99
+ sym = env.values.first
100
+ wpconfig = wpconfig.gsub(/define\('#{term}', '.{1,16}'\);/, "define\('#{term}', '#{send("db_"+sym)}');")
101
+ end
102
+ #define('DB_NAME', 'database_name');
103
+ wpconfig = wpconfig.gsub(/\$table_prefix = '.{1,16}';/, "$table_prefix = '#{send("db_prefix")}';")
104
+ File.open(stage_config, 'w') {|f| f.write(wpconfig) }
105
+ upload stage_config, "#{latest_release}/app/wp-config.php"
106
+ run_locally "rm #{stage_config}"
107
+ end
108
+
109
+ desc "Sync Local Assets to Remote"
110
+ task "assets_push", :roles => :web do
111
+ servers = find_servers_for_task(current_task)
112
+ servers.each do |server|
113
+ run_locally "if [ -d app/#{uploads_path} ]; then rsync -avhru app/#{uploads_path}/* -delete -e 'ssh -p #{port}' #{user}@#{server}:#{shared_path}/uploads; fi"
114
+ end
115
+ end
116
+
117
+ desc "Sync Remote Assets to Local"
118
+ task "assets_pull", :roles => :web do
119
+ servers = find_servers_for_task(current_task)
120
+ servers.each do |server|
121
+ run_locally "if [ -d app/#{uploads_path} ]; then rsync -avhru -delete -e 'ssh -p #{port}' #{user}@#{server}:#{shared_path}/uploads/* app/#{uploads_path}; fi"
122
+ end
123
+ end
124
+
125
+ desc "Extract PHP DB Env Vars"
126
+ task :extract_local_db, :except => { :no_release => true } do
127
+ wpconfig = run_locally "cat app/wp-config.php"
128
+ dev_env = {"development" => {}}
129
+ extraction_terms.each do |env|
130
+ db.mysql.prepare_env
131
+ term = env.keys.first
132
+ sym = env.values.first
133
+ dev_env["development"][sym] = wpconfig.match(/define\('#{term}', '(.{1,16})'\);/)[1]
134
+ end
135
+
136
+ dev_env["development"]["prefix"] = wpconfig.match(/\$table_prefix = '(.{1,16})';/)[1]
137
+ db.mysql.update_db_config(dev_env)
138
+ print dev_env
139
+ end
140
+ before "deploy:setup", "wordpress:extract_local_db"
141
+
142
+ desc "Set URL in database"
143
+ task :updatedb, :roles => :db, :except => { :no_release => true } do
144
+ db.mysql.prepare_env
145
+ run "mysql -u #{db_username} -p #{db_database} -e 'UPDATE #{db_prefix}options SET option_value = \"#{application_url}\" WHERE option_name = \"siteurl\" OR option_name = \"home\"'" do |ch, stream, out|
146
+ ch.send_data "#{db_password}\n" if out =~ /^Enter password:/
147
+ puts out
148
+ end
149
+ end
150
+ after "db:mysql:push", "wordpress:updatedb"
151
+ after "db:mysql:push", "wordpress:assets_push"
152
+
153
+ desc "Set URL in local database"
154
+ task :update_local_db, :except => { :no_release => true } do
155
+ db.mysql.prepare_env(:development)
156
+ httpd_conf = File.read(local_httpd_conf_path)
157
+ document_root = httpd_conf.match(/^(?!#)DocumentRoot "(.+)"\n/)[1]
158
+ apache_listen = httpd_conf.match(/^(?!#)Listen ([0-9]{1,16})\n/)[1]
159
+ current_path = Dir.pwd
160
+ local_uri = "http://localhost:#{apache_listen}#{Dir.pwd.gsub(document_root, '')}/app"
161
+ run_locally "#{local_mysql_path}mysql -u #{db_username} -p#{db_password} #{db_database} -e 'UPDATE #{db_prefix}options SET option_value = \"#{local_uri}\" WHERE option_name = \"siteurl\" OR option_name = \"home\"'"
162
+ end
163
+ after "db:mysql:pull", "wordpress:update_local_db"
164
+ after "db:mysql:pull", "wordpress:assets_pull"
165
+
166
+ desc "Protect system files"
167
+ task :protect, :except => { :no_release => true } do
168
+ run "chmod 444 #{latest_release}/app/wp-config.php*"
169
+ run "cd #{current_path} && chown -R #{user} . && find . -type d -print0 | xargs -0 chmod 755"
170
+ run "cd #{shared_path}/uploads && chown -R #{user} . && chmod 755 -R ."
171
+ end
172
+
173
+ desc "[internal] get current wp template from local db"
174
+ task :current_wp_template, :except => { :no_release => true } do
175
+ db.mysql.prepare_env(:development)
176
+ template = run_locally "#{local_mysql_path}mysql -u #{db_username} -p#{db_password} #{db_database} -e 'SELECT `option_value` FROM `#{db_prefix}options` WHERE `option_name` = \"template\"'"
177
+ set(:wp_template) { template.split("\n")[1] }
178
+ end
179
+ before "nginx:setup", "wordpress:current_wp_template"
180
+
181
+ after "wordpress:symlink", "wordpress:create_config"
182
+ after "wordpress:create_config", "wordpress:protect"
183
+ after "deploy", "wordpress:symlink"
184
+ end
185
+ end
@@ -0,0 +1,14 @@
1
+ class Wpcap::Utility
2
+
3
+ def self.error(text)
4
+ puts red("****#{text}****")
5
+ end
6
+
7
+ def self.colorize(text, color_code)
8
+ "\e[#{color_code}m#{text}\e[0m"
9
+ end
10
+
11
+ def self.red(text); self.colorize(text, 31); end
12
+ def self.green(text); self.colorize(text, 32); end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module Wpcap
2
+ VERSION = "0.1.0"
3
+ end
data/lib/wpcap.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "wpcap/version"
2
+
3
+ module Wpcap
4
+
5
+ end
data/wpcap.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/wpcap/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Russell Osborne"]
6
+ gem.email = ["russell@burningpony.com"]
7
+ gem.description = "A Tool to Setup, Maintain, and Deploy Capistrano Driven Wordpress Sites"
8
+ gem.summary = "A Tool to Setup, Maintain, and Deploy Capistrano Driven Wordpress Sites on any cloud server or linux macine"
9
+ gem.homepage = "https://github.com/rposborne/wpcap"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "wpcap"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Wpcap::VERSION
17
+ gem.add_dependency('capistrano')
18
+ gem.add_dependency('railsless-deploy')
19
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wpcap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russell Osborne
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: railsless-deploy
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A Tool to Setup, Maintain, and Deploy Capistrano Driven Wordpress Sites
47
+ email:
48
+ - russell@burningpony.com
49
+ executables:
50
+ - wpcap
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - bin/wpcap
60
+ - lib/wpcap.rb
61
+ - lib/wpcap/command.rb
62
+ - lib/wpcap/recipes/base.rb
63
+ - lib/wpcap/recipes/check.rb
64
+ - lib/wpcap/recipes/memcached.rb
65
+ - lib/wpcap/recipes/mysql.rb
66
+ - lib/wpcap/recipes/nginx.rb
67
+ - lib/wpcap/recipes/php.rb
68
+ - lib/wpcap/recipes/server.rb
69
+ - lib/wpcap/recipes/templates/deploy-stage.rb.erb
70
+ - lib/wpcap/recipes/templates/deploy.rb.erb
71
+ - lib/wpcap/recipes/templates/maintenance.html.erb
72
+ - lib/wpcap/recipes/templates/mysql.yml.erb
73
+ - lib/wpcap/recipes/templates/nginx_php.erb
74
+ - lib/wpcap/recipes/templates/php-fpm.conf.erb
75
+ - lib/wpcap/recipes/templates/php.ini.erb
76
+ - lib/wpcap/recipes/varnish.rb
77
+ - lib/wpcap/recipes/wordpress.rb
78
+ - lib/wpcap/utility.rb
79
+ - lib/wpcap/version.rb
80
+ - wpcap.gemspec
81
+ homepage: https://github.com/rposborne/wpcap
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.24
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: A Tool to Setup, Maintain, and Deploy Capistrano Driven Wordpress Sites on
105
+ any cloud server or linux macine
106
+ test_files: []