Skip to content

Instantly share code, notes, and snippets.

@alettieri
Created August 30, 2012 17:26
Show Gist options
  • Save alettieri/3534278 to your computer and use it in GitHub Desktop.
Save alettieri/3534278 to your computer and use it in GitHub Desktop.
WordPress Capistrano deployment file (On Webfaction)
default_run_options[:pty] = true # Must be set for the password prompt from git to work
# WebFaction user account
# This is the server user account
set :server_user, "<server_username>"
# Server Domain
set :domain, "<domain_name>"
set :user, server_user
# Repository User
set :repo_user, "<repository_username>"
# Repository Name
set :repo_name, "<repository_name>"
# Application directory on the server
set :application, "<application_folder_name>"
# Repository location
set :repository, "<repository_url>"
# Default repository branch to checkout
set :branch, "master"
# We're using submodules [WordPress] & themes:[<theme_name>]
set :git_enable_submodules, 1
# We're using git as our repository
set :scm, :git
# Tell Capistrano to use agent forwarding with this command. uses your local keys instead of keys installed on the server.
ssh_options[:forward_agent] = true
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "<rsa_key_name>")]
# Deploy settings
set :deploy_to, "/home/#{server_user}/webapps-releases/#{application}"
# Fetch only the changes since the last.
set :deploy_via, :remote_cache
# Exclude the following files
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules", "env_local", "env_prod", "env_stage"]
set :copy_compression, :gzip
# Options
set :use_sudo, false
set :keep_releases, 5
set :env, "dev"
# Theme settings
set :theme_path, "<Local_WordPress_theme_path>"
# Timestamp
set :time_stamp, Time.now.to_i
# Roles & servers
role :app, domain
role :web, domain
role :db, domain, :primary => true
server "#{domain}", :app, :primary => true
# Taskst to perform during with production flag
# When using --`$: cap production deploy`
task :production do
set :application, "<production_application_folder>"
set :deploy_to, "/home/#{server_user}/webapps-releases/#{application}"
set :branch, "master"
set :env, "prod"
end
task :staging do
set :application, "<staging_application_folder>"
# Deploy Settings
set :deploy_to, "/home/#{server_user}/webapps-releases/#{application}"
set :branch, "master"
set :env, "stage"
end
# Custom deployment namespace
namespace :customs do
desc "Symlinking files"
task :make_symlink, :roles => :app do
run "ln -nfs #{shared_path}/uploads #{release_path}/application/wp-content/uploads"
run "ln -nfs #{shared_path}/blogs.dir #{release_path}/application/wp-content/blogs.dir"
end
desc "Set development flag"
task :set_environment, :roles => :app do
if env === "dev" then
run "touch #{release_path}/env_dev"
end
if env === "stage" then
run "touch #{release_path}/env_stage"
end
end
end
namespace :themes do
desc "Deploy WordPress Theme using Sass/Compass"
task :deploy_theme, :roles => :app do
set :asset_path, "<path_to_assets>"
#compile and upload sass files
run_locally( "cd #{theme_path}/#{asset_path}/<sass_compass_dir>; compass compile" )
upload( "#{theme_path}/#{asset_path}/css", "#{release_path}/<WordPress_theme_path>/#{asset_path}/css" )
end
desc "Minify Javascript"
task :minify_js, :roles => :app do
set :my_theme, "<theme_name>/assets"
if( env === "prod" || env === "stage" ) then
#Minify the script file
run_locally( "cd #{theme_path}/#{my_theme}/js; juicer merge -i script.js -o script.min.#{time_stamp}.js" )
#Upload the minified script
upload( "#{theme_path}/#{my_theme}/js/script.min.#{time_stamp}.js", "#{release_path}/application/wp-content/themes/#{my_theme}/js/script.min.#{time_stamp}.js" )
#Delete minified local script file
run_locally( "cd #{theme_path}/#{my_theme}/js; rm script.min.#{time_stamp}.js")
end
end
desc "Update the server side wp-config file with the new timestamp"
task :update_config, :roles => :app do
# Change to the release path app directory
# Find and replace the <TIMESTAMP> token with the timestamp.
# Remove the wp-config.php.bak file that's generated by the sed command
if( env === "prod" || env === "stage" ) then
run "cd #{release_path}/application/; sed -i.bak 's/<TIMESTAMP>/#{time_stamp}/g' wp-config.php; rm wp-config.php.bak"
end
end
end
after "deploy:finalize_update", "customs:make_symlink"
after "deploy:finalize_update", "customs:set_environment"
after "deploy:finalize_update", "themes:update_config"
after "deploy:update_code", "themes:deploy_theme"
after "deploy:update_code", "themes:minify_js"
after "deploy", "deploy:cleanup"
@alettieri
Copy link
Author

Juicer (https://github.com/cjohansen/juicer) runs JSHint, Yuicompressor and then concatenates all the js dependency files into one script file. It's awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment