Skip to content

Instantly share code, notes, and snippets.

@swalkinshaw
Last active December 14, 2016 10:01
Show Gist options
  • Save swalkinshaw/9e4556d4b0c402eba29a to your computer and use it in GitHub Desktop.
Save swalkinshaw/9e4556d4b0c402eba29a to your computer and use it in GitHub Desktop.
set :application, 'my_app_name'
set :repo_url, '[email protected]:me/my_repo.git'
set :branch, :master
set :deploy_to, -> { "/srv/www/#{fetch(:application)}" }
set :log_level, :info
set :linked_files, fetch(:linked_files, []).push('.env')
set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads')
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :service, :nginx, :reload
end
end
end
# The above restart task is not run by default
# Uncomment the following line to run it on deploys if needed
# after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
desc 'Update WordPress template root paths to point to the new release'
task :update_option_paths do
on roles(:app) do
within fetch(:release_path) do
if test :wp, :core, 'is-installed'
[:stylesheet_root, :template_root].each do |option|
# Only change the value if it's an absolute path
# i.e. The relative path "/themes" must remain unchanged
# Also, the option might not be set, in which case we leave it like that
value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false
if value != '' && value != '/themes'
execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes')
end
end
end
end
end
end
end
# The above update_option_paths task is not run by default
# Note that you need to have WP-CLI installed on your server
# Uncomment the following line to run it on deploys if needed
# after 'deploy:publishing', 'deploy:update_option_paths'
set :theme_path, Pathname.new('web/app/themes/sage')
set :local_app_path, Pathname.new('/path/to/local/sage/repo')
set :local_theme_path, fetch(:local_app_path).join(fetch(:theme_path))
namespace :assets do
task :compile do
run_locally do
within fetch(:local_theme_path) do
execute :gulp, '--production'
end
end
end
task :copy do
on roles(:web) do
upload! fetch(:local_theme_path).join('dist'), release_path.join(fetch(:theme_path)), recursive: true
end
end
task deploy: %w(compile copy)
end
before 'deploy:updated', 'assets:deploy'
@southerneer
Copy link

I was kind of interested to know if there was an rsync flavor of this scheme. It would save a lot of time vs uploading the same image and font files from the dist folder in every deploy. I found capistrano-rsync but haven't taken the time to try it out yet. It's been 2+ years since the last update to it so it's probably out of date at this point, but was wondering if anyone else had tried out something similar.

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