wp-capistrano 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = wp-capistrano
2
+
3
+ == Usage
4
+
5
+ A sample Capfile and config.yml exist in lib/wp_generate/templates/capify.
6
+
7
+ Those should be copied into wp-content/Capfile and wp-content/lib/config.yml respectively.
8
+
9
+ For the initial run, you should first create the directory specified in deploy.*.path on the server, then run:
10
+
11
+ cap setup:wordpress
12
+
13
+ This will
14
+
15
+ == wp-generate
16
+
17
+ wp-capistrano can be used with wp-generate by doing the following:
18
+
19
+ gem install wp-generate
20
+ cd wp-content
21
+ wp-generate capify
22
+
23
+ Which creates Capfile and lib/config.yml.
24
+
25
+ == Credits
26
+
27
+ Code originally adapted from:
28
+ http://github.com/jestro/wordpress-capistrano
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "wp-capistrano"
7
+ gem.summary = %Q{Capistrano receipe bits for WordPress}
8
+ gem.description = %Q{}
9
+ gem.email = "tom@thedextrousweb.com"
10
+ gem.homepage = "http://github.com/dxw/wp-capistrano"
11
+ gem.authors = ["The Dextrous Web"]
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
16
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,88 @@
1
+ require 'wp_config'
2
+ require 'erb'
3
+ require 'digest'
4
+ require 'digest/sha1'
5
+
6
+ require 'wp_capistrano/namespace/deploy'
7
+ require 'wp_capistrano/namespace/setup'
8
+ require 'wp_capistrano/namespace/wp'
9
+
10
+ Capistrano::Configuration.instance.load do
11
+ default_run_options[:pty] = true
12
+
13
+ def set_target target
14
+ tt = WPConfig.instance.h['deploy'][target]
15
+ if tt
16
+ t = OpenStruct.new(tt)
17
+ set :domain, t.ssh_domain
18
+ set :user, t.ssh_user
19
+ set :deploy_to, t.path
20
+ set :wordpress_domain, t.vhost
21
+ set :wordpress_db_name, t.database.name
22
+ set :wordpress_db_user, t.database.user
23
+ set :wordpress_db_password, t.database.password
24
+ set :wordpress_db_host, t.database.host
25
+ set :use_sudo, t.use_sudo
26
+
27
+ @roles = {}
28
+ role :app, domain
29
+ role :web, domain
30
+ role :db, domain, :primary => true
31
+ end
32
+ end
33
+
34
+ WPConfig.instance.h['deploy'].each_pair do |k,v|
35
+ set_target k if v['default']
36
+ end
37
+
38
+ task :testing do
39
+ set_target 'testing'
40
+ end
41
+ task :staging do
42
+ set_target 'staging'
43
+ end
44
+ task :production do
45
+ set_target 'production'
46
+ end
47
+
48
+ # Load from config
49
+ set :wordpress_version, WPConfig.wordpress.version
50
+ set :wordpress_git_url, WPConfig.wordpress.repository
51
+ set :repository, WPConfig.application.repository
52
+
53
+ # Everything else
54
+ set :scm, "git"
55
+ set :deploy_via, :remote_cache
56
+ set :branch, "master"
57
+ set :git_shallow_clone, 1
58
+ set :git_enable_submodules, 1
59
+ set :wordpress_db_host, "localhost"
60
+ set :wordpress_auth_key, Digest::SHA1.hexdigest(rand.to_s)
61
+ set :wordpress_secure_auth_key, Digest::SHA1.hexdigest(rand.to_s)
62
+ set :wordpress_logged_in_key, Digest::SHA1.hexdigest(rand.to_s)
63
+ set :wordpress_nonce_key, Digest::SHA1.hexdigest(rand.to_s)
64
+
65
+ #allow deploys w/o having git installed locally
66
+ set(:real_revision) do
67
+ output = ""
68
+ invoke_command("git ls-remote #{repository} #{branch} | cut -f 1", :once => true) do |ch, stream, data|
69
+ case stream
70
+ when :out
71
+ if data =~ /\(yes\/no\)\?/ # first time connecting via ssh, add to known_hosts?
72
+ ch.send_data "yes\n"
73
+ elsif data =~ /Warning/
74
+ elsif data =~ /yes/
75
+ #
76
+ else
77
+ output << data
78
+ end
79
+ when :err then warn "[err :: #{ch[:server]}] #{data}"
80
+ end
81
+ end
82
+ output.gsub(/\\/, '').chomp
83
+ end
84
+
85
+ #no need for log and pids directory
86
+ set :shared_children, %w(system)
87
+
88
+ end
@@ -0,0 +1,65 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :deploy do
3
+
4
+ desc "Override deploy restart to not do anything"
5
+ task :restart do
6
+ #
7
+ end
8
+
9
+ task :finalize_update, :except => { :no_release => true } do
10
+ run "chmod -R g+w #{latest_release}"
11
+
12
+ # I've got submodules in my submodules
13
+ #run "cd #{latest_release} && git submodule foreach --recursive git submodule update --init"
14
+ # Git 1.5-compatability:
15
+ run "cd #{latest_release} && DIR=`pwd` && for D in `grep '^\\[submodule' .git/config | cut -d\\\" -f2`; do cd $DIR/$D && git submodule init && git submodule update; done"
16
+
17
+ deploy.sass
18
+
19
+ run <<-CMD
20
+ mkdir -p #{latest_release}/finalized &&
21
+ cp -rv #{shared_path}/wordpress/* #{latest_release}/finalized/ &&
22
+ cp -rv #{shared_path}/wp-config.php #{latest_release}/finalized/wp-config.php &&
23
+ cp -rv #{shared_path}/htaccess #{latest_release}/finalized/.htaccess &&
24
+ rm -rf #{latest_release}/finalized/wp-content &&
25
+ mkdir #{latest_release}/finalized/wp-content &&
26
+ rm -rf #{latest_release}/**/.git &&
27
+ cp -rv #{latest_release}/themes #{latest_release}/finalized/wp-content/ &&
28
+ cp -rv #{latest_release}/plugins #{latest_release}/finalized/wp-content/ &&
29
+ ln -s #{shared_path}/uploads #{latest_release}/finalized/wp-content/ &&
30
+ mkdir -p #{latest_release}/finalized/wp-content/cache/ ;
31
+ chmod -R 777 #{latest_release}/finalized/wp-content/cache/ ;
32
+ true
33
+ CMD
34
+ end
35
+
36
+ desc "Compile SASS locally and upload it"
37
+ task :sass do
38
+ Dir.glob("themes/*/*/sass_output.php").map {|d| d.match(%r&/([^/]+)/([^/]+)/sass_output.php$&)[1,2]}[0..0].each do |theme_dir,sass_dir|
39
+ p theme_dir
40
+ p sass_dir
41
+ system("cd themes/#{theme_dir}/#{sass_dir} && php sass_output.php > sass_output.css")
42
+ top.upload("themes/#{theme_dir}/#{sass_dir}/sass_output.css", "#{latest_release}/themes/#{theme_dir}/#{sass_dir}/" , :via => :scp)
43
+ run("sed -i 's/\.php/\.css/' #{latest_release}/themes/#{theme_dir}/style.css")
44
+ end
45
+ end
46
+
47
+ task :symlink, :except => { :no_release => true } do
48
+ on_rollback do
49
+ if previous_release
50
+ run "rm -f #{current_path}; ln -s #{previous_release}/finalized #{current_path}; true"
51
+ else
52
+ logger.important "no previous release to rollback to, rollback of symlink skipped"
53
+ end
54
+ end
55
+
56
+ run "rm -f #{current_path} && ln -s #{latest_release}/finalized #{current_path}"
57
+ end
58
+
59
+ namespace :revision do
60
+ task :revision do
61
+ puts 'hhh'
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :setup do
3
+
4
+ desc "Setup this server for a new wordpress site."
5
+ task :wordpress do
6
+ "mkdir -p #{deploy_to}"
7
+ deploy.setup
8
+ wp.config
9
+ wp.htaccess
10
+ wp.checkout
11
+ setup.uploads
12
+ setup.mysql
13
+ end
14
+
15
+ desc "Creates uploads dir"
16
+ task :uploads do
17
+ chmod = true
18
+ if File.exist? 'uploads'
19
+ begin
20
+ upload("uploads", shared_path, :recursive => true, :via => :scp)
21
+ rescue
22
+ STDERR.puts '*** uploads dir already exists and does not belong to us. Not re-uploading.'
23
+ chmod = false
24
+ end
25
+ else
26
+ run "mkdir -p #{shared_path}/uploads"
27
+ end
28
+ run "chmod -R 777 #{shared_path}/uploads" if chmod
29
+ end
30
+
31
+ desc "Creates the DB, and loads the dump"
32
+ task :mysql do
33
+ upload("data/dump.sql.gz", shared_path, :via => :scp)
34
+ run <<-CMD
35
+ test #{wordpress_db_name}X != `echo 'show databases' | mysql -u root | grep '^#{wordpress_db_name}$'`X &&
36
+ echo 'create database if not exists `#{wordpress_db_name}`' | mysql -u root &&
37
+ zcat #{shared_path}/dump.sql.gz | sed 's/localhost/#{wordpress_domain}/g' | mysql -u root #{wordpress_db_name} || true
38
+ CMD
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :wp do
3
+
4
+ desc "Checks out a copy of wordpress to a shared location"
5
+ task :checkout do
6
+ run "rm -rf #{shared_path}/wordpress || true"
7
+ raise Exception, 'wordpress.repository must be set in config.yml' if wordpress_git_url.nil?
8
+ run "git clone --depth 1 #{wordpress_git_url} #{shared_path}/wordpress"
9
+ run "cd #{shared_path}/wordpress && git fetch --tags && git checkout #{wordpress_version}"
10
+ end
11
+
12
+ desc "Sets up wp-config.php"
13
+ task :config do
14
+ file = File.join(File.dirname(__FILE__), "../wp-config.php.erb")
15
+ template = File.read(file)
16
+ buffer = ERB.new(template).result(binding)
17
+
18
+ put buffer, "#{shared_path}/wp-config.php"
19
+ puts "New wp-config.php uploaded! Please run cap:deploy to activate these changes."
20
+ end
21
+
22
+ desc "Sets up .htaccess"
23
+ task :htaccess do
24
+ run 'env echo -e \'<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase /\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\n</IfModule>\' > '"#{shared_path}/htaccess"
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,89 @@
1
+ <?php
2
+ /**
3
+ * !!!
4
+ * DO NOT EDIT THIS FILE DIRECTLY ON YOUR SERVER
5
+ * !!!
6
+ *
7
+ * Edit it in your wordpress-capistrano repo, commit and push it,
8
+ * then run cap wordpress:configure to update it on the server.
9
+ *
10
+ * The base configurations of the WordPress.
11
+ *
12
+ * This file has the following configurations: MySQL settings, Table Prefix,
13
+ * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
14
+ * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
15
+ * wp-config.php} Codex page. You can get the MySQL settings from your web host.
16
+ *
17
+ * This file is used by the wp-config.php creation script during the
18
+ * installation. You don't have to use the web site, you can just copy this file
19
+ * to "wp-config.php" and fill in the values.
20
+ *
21
+ * @package WordPress
22
+ */
23
+
24
+ // ** MySQL settings - You can get this info from your web host ** //
25
+ /** The name of the database for WordPress */
26
+ define('DB_NAME', '<%= wordpress_db_name %>');
27
+
28
+ /** MySQL database username */
29
+ define('DB_USER', '<%= wordpress_db_user %>');
30
+
31
+ /** MySQL database password */
32
+ define('DB_PASSWORD', '<%= wordpress_db_password %>');
33
+
34
+ /** MySQL hostname */
35
+ define('DB_HOST', '<%= wordpress_db_host %>');
36
+
37
+ /** Database Charset to use in creating database tables. */
38
+ define('DB_CHARSET', 'utf8');
39
+
40
+ /** The Database Collate type. Don't change this if in doubt. */
41
+ define('DB_COLLATE', '');
42
+
43
+ /** Set Path of your WordPress install if specified in your capfile **/
44
+ <% if fetch(:wordpress_domain, false) %>
45
+ define('WP_HOME', 'http://<%= wordpress_domain %>' );
46
+ define('WP_SITEURL', 'http://<%= wordpress_domain %>');
47
+ <% end %>
48
+
49
+ /**#@+
50
+ * Authentication Unique Keys.
51
+ *
52
+ * Change these to different unique phrases!
53
+ * You can generate these using the {@link http://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
54
+ *
55
+ * @since 2.6.0
56
+ */
57
+ define('AUTH_KEY', '<%= wordpress_auth_key %>');
58
+ define('SECURE_AUTH_KEY', '<%= wordpress_secure_auth_key %>');
59
+ define('LOGGED_IN_KEY', '<%= wordpress_logged_in_key %>');
60
+ define('NONCE_KEY', '<%= wordpress_logged_in_key %>');
61
+ /**#@-*/
62
+
63
+ /**
64
+ * WordPress Database Table prefix.
65
+ *
66
+ * You can have multiple installations in one database if you give each a unique
67
+ * prefix. Only numbers, letters, and underscores please!
68
+ */
69
+ $table_prefix = 'wp_';
70
+
71
+ /**
72
+ * WordPress Localized Language, defaults to English.
73
+ *
74
+ * Change this to localize WordPress. A corresponding MO file for the chosen
75
+ * language must be installed to wp-content/languages. For example, install
76
+ * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
77
+ * language support.
78
+ */
79
+ define ('WPLANG', '');
80
+
81
+ /* That's all, stop editing! Happy blogging. */
82
+
83
+ /** WordPress absolute path to the Wordpress directory. */
84
+ if ( !defined('ABSPATH') )
85
+ define('ABSPATH', dirname(__FILE__) . '/');
86
+
87
+ /** Sets up WordPress vars and included files. */
88
+ require_once(ABSPATH . 'wp-settings.php');
89
+ ?>
data/lib/wp_config.rb ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'singleton'
4
+
5
+ class OpenStruct
6
+ def method_missing(method)
7
+ method = method.to_s
8
+ if @hsh[method].is_a? Hash
9
+ OpenStruct.new(@hsh[method])
10
+ else
11
+ @hsh[method]
12
+ end
13
+ end
14
+ def initialize(hsh)
15
+ @hsh = hsh
16
+ end
17
+ end
18
+
19
+ class WPConfig
20
+ include Singleton
21
+
22
+ def self.method_missing(method, *args)
23
+ self.instance.config.send(method, *args)
24
+ end
25
+
26
+ attr_reader :config, :h
27
+
28
+ def initialize
29
+ @h = YAML.load(open(File.join(Dir.pwd,'lib','config.yml')).read)
30
+ @config = OpenStruct.new(@h)
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ class WpGenerate::Generator::Capify < WpGenerate::Generator
2
+ def initialize args, options
3
+ @options = options
4
+ @templates = {"Capfile" => "Capfile", "config.yml" => "lib/config.yml"}
5
+ @vars = {}
6
+ end
7
+ def templates_dir
8
+ File.join(File.dirname(__FILE__), '../templates')
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ load 'deploy'
2
+ require 'wp_capistrano/deploy'
@@ -0,0 +1,38 @@
1
+ ---
2
+ application:
3
+ repository: "git@github.com:user/repo.git"
4
+ wordpress:
5
+ repository: "git://github.com/dxw/wordpress.git"
6
+ version: "v2.9.2"
7
+ deploy:
8
+ testing:
9
+ default: true
10
+ ssh_user: deploy
11
+ ssh_domain: "example.com"
12
+ path: "/var/vhosts/example.com/testing/app"
13
+ vhost: "app.testing.example.com"
14
+ database:
15
+ name: "app_testing"
16
+ user: "app_testing"
17
+ password: ""
18
+ host: "localhost"
19
+ staging:
20
+ ssh_user: deploy
21
+ ssh_domain: "example.com"
22
+ path: "/var/vhosts/example.com/staging/app"
23
+ vhost: "app.staging.example.com"
24
+ database:
25
+ name: "app_staging"
26
+ user: "app_staging"
27
+ password: ""
28
+ host: "localhost"
29
+ production:
30
+ ssh_user: deploy
31
+ ssh_domain: "example.com"
32
+ path: "/var/vhosts/example.com/production/app"
33
+ vhost: "app.com"
34
+ database:
35
+ name: "app_production"
36
+ user: "app_production"
37
+ password: ""
38
+ host: "localhost"
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wp-capistrano
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - The Dextrous Web
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-25 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: ""
22
+ email: tom@thedextrousweb.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/wp_capistrano/deploy.rb
33
+ - lib/wp_capistrano/namespace/deploy.rb
34
+ - lib/wp_capistrano/namespace/setup.rb
35
+ - lib/wp_capistrano/namespace/wp.rb
36
+ - lib/wp_capistrano/wp-config.php.erb
37
+ - lib/wp_config.rb
38
+ - lib/wp_generate/generator/capify.rb
39
+ - lib/wp_generate/templates/capify/Capfile
40
+ - lib/wp_generate/templates/capify/config.yml
41
+ - README.rdoc
42
+ has_rdoc: true
43
+ homepage: http://github.com/dxw/wp-capistrano
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Capistrano receipe bits for WordPress
72
+ test_files: []
73
+