├── CHANGELOG.md ├── CONTRIBUTING.md ├── Capfile ├── Gemfile ├── Gemfile.lock ├── LICENSE.md ├── README.md └── config ├── deploy.rb └── deploy ├── production.rb └── staging.rb /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### HEAD 2 | 3 | * Initial move to standalone repo 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please read [Contributing to Roots Projects](https://github.com/roots/guidelines/blob/master/CONTRIBUTING.md) 2 | -------------------------------------------------------------------------------- /Capfile: -------------------------------------------------------------------------------- 1 | # Load DSL and Setup Up Stages 2 | require 'capistrano/setup' 3 | 4 | # Includes default deployment tasks 5 | require 'capistrano/deploy' 6 | 7 | # Load tasks from gems 8 | require 'capistrano/composer' 9 | 10 | # Load tasks from Capistrano WPCLI 11 | require 'capistrano/wpcli' 12 | 13 | # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. 14 | # Customize this path to change the location of your custom tasks. 15 | Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } 16 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'capistrano' 4 | gem 'capistrano-composer' 5 | 6 | # Capistrano WPCLI 7 | gem 'capistrano-wpcli' -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | capistrano (3.2.1) 5 | i18n 6 | rake (>= 10.0.0) 7 | sshkit (~> 1.3) 8 | capistrano-composer (0.0.4) 9 | capistrano (>= 3.0.0.pre) 10 | colorize (0.7.3) 11 | i18n (0.6.9) 12 | net-scp (1.2.1) 13 | net-ssh (>= 2.6.5) 14 | net-ssh (2.9.1) 15 | rake (10.3.2) 16 | sshkit (1.5.1) 17 | colorize 18 | net-scp (>= 1.1.2) 19 | net-ssh (>= 2.8.0) 20 | 21 | PLATFORMS 22 | ruby 23 | 24 | DEPENDENCIES 25 | capistrano (~> 3.2.0) 26 | capistrano-composer 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Roots 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bedrock-capistrano 2 | 3 | These are the Capistrano configs for deploying [Bedrock](https://github.com/roots/bedrock) projects. 4 | 5 | [Capistrano](http://www.capistranorb.com/) is a remote server automation and deployment tool. It will let you deploy or rollback your application in one command: 6 | 7 | Screencast (:moneybag:): [Deploying WordPress with Capistrano](https://roots.io/screencasts/deploying-wordpress-with-capistrano/) 8 | 9 | **Status**: This project is stable, feature complete, and production ready. This means that we won't be adding new features. Only fixing existing bugs and ensuring that base functionality works. 10 | 11 | ## Requirements 12 | 13 | * Ruby >= 1.9 14 | 15 | Required Gems: 16 | 17 | * `capistrano` (> 3.1.0) 18 | * `capistrano-composer` 19 | 20 | These can be installed manually with `gem install ` but it's highly suggested you use [Bundler](http://bundler.io/) to manage them. Bundler is basically the Ruby equivalent to PHP's Composer. Just as Composer manages your PHP packages/dependencies, Bundler manages your Ruby gems/dependencies. Bundler itself is a Gem and can be installed via `gem install bundler` (sudo may be required). 21 | 22 | The `Gemfile` in the root of this repo specifies the required Gems (just like `composer.json`). Once you have Bundler installed, run `bundle install` to install the Gems in the `Gemfile`. When using Bundler, you'll need to prefix the `cap` command with `bundle exec` as seen below (this ensures you're not using system Gems which can cause conflicts). 23 | 24 | See http://capistranorb.com/documentation/getting-started/authentication-and-authorisation/ for the best way to set up SSH key authentication to your servers for password-less (and secure) deploys. 25 | 26 | ## Installation/configuration 27 | 28 | 1. Copy the following files into the root of your Bedrock project: 29 | * `Capfile` 30 | * `Gemfile` 31 | * `Gemfile.lock` 32 | 2. Copy the following files/folders into your `config` directory: 33 | * `config/deploy/*` 34 | * `config/deploy.rb` 35 | 3. Edit your `config/deploy/` stage/environment configs to set the roles/servers and connection options. 36 | 4. Before your first deploy, run `bundle exec cap deploy:check` to create the necessary folders/symlinks. 37 | 5. Add your `.env` file to `shared/` in your `deploy_to` path on the remote server for all the stages you use (ex: `/srv/www/example.com/shared/.env`) 38 | 6. Run the normal deploy command: `bundle exec cap deploy` 39 | 7. Enjoy one-command deploys! 40 | 41 | ## Usage 42 | 43 | * Deploy: `cap production deploy` 44 | * Rollback: `cap production deploy:rollback` 45 | 46 | Composer support is built-in so when you run a deploy, `composer install` is automatically run. Capistrano has a great [deploy flow](http://www.capistranorb.com/documentation/getting-started/flow/) that you can hook into and extend it. 47 | 48 | ## Contributing 49 | 50 | Contributions are welcome from everyone. We have [contributing guidelines](CONTRIBUTING.md) to help you get started. 51 | 52 | ## Support 53 | 54 | Use the [Roots Discourse](https://discourse.roots.io/) forum to ask questions and get support. 55 | -------------------------------------------------------------------------------- /config/deploy.rb: -------------------------------------------------------------------------------- 1 | set :application, 'my_app_name' 2 | set :repo_url, 'git@example.com:me/my_repo.git' 3 | 4 | # Branch options 5 | # Prompts for the branch name (defaults to current branch) 6 | #ask :branch, -> { `git rev-parse --abbrev-ref HEAD`.chomp } 7 | 8 | # Hardcodes branch to always be master 9 | # This could be overridden in a stage config file 10 | set :branch, :master 11 | 12 | set :deploy_to, -> { "/srv/www/#{fetch(:application)}" } 13 | 14 | # Use :debug for more verbose output when troubleshooting 15 | set :log_level, :info 16 | 17 | # Apache users with .htaccess files: 18 | # it needs to be added to linked_files so it persists across deploys: 19 | # set :linked_files, fetch(:linked_files, []).push('.env', 'web/.htaccess') 20 | set :linked_files, fetch(:linked_files, []).push('.env') 21 | set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads') 22 | 23 | namespace :deploy do 24 | desc 'Restart application' 25 | task :restart do 26 | on roles(:app), in: :sequence, wait: 5 do 27 | # Your restart mechanism here, for example: 28 | # execute :service, :nginx, :reload 29 | end 30 | end 31 | end 32 | 33 | # The above restart task is not run by default 34 | # Uncomment the following line to run it on deploys if needed 35 | # after 'deploy:publishing', 'deploy:restart' 36 | 37 | namespace :deploy do 38 | desc 'Update WordPress template root paths to point to the new release' 39 | task :update_option_paths do 40 | on roles(:app) do 41 | within fetch(:release_path) do 42 | if test :wp, :core, 'is-installed' 43 | [:stylesheet_root, :template_root].each do |option| 44 | # Only change the value if it's an absolute path 45 | # i.e. The relative path "/themes" must remain unchanged 46 | # Also, the option might not be set, in which case we leave it like that 47 | value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false 48 | if value != '' && value != '/themes' 49 | execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes') 50 | end 51 | end 52 | end 53 | end 54 | end 55 | end 56 | end 57 | 58 | # The above update_option_paths task is not run by default 59 | # Note that you need to have WP-CLI installed on your server 60 | # Uncomment the following line to run it on deploys if needed 61 | # after 'deploy:publishing', 'deploy:update_option_paths' 62 | -------------------------------------------------------------------------------- /config/deploy/production.rb: -------------------------------------------------------------------------------- 1 | set :stage, :production 2 | 3 | # Simple Role Syntax 4 | # ================== 5 | #role :app, %w{deploy@example.com} 6 | #role :web, %w{deploy@example.com} 7 | #role :db, %w{deploy@example.com} 8 | 9 | # Extended Server Syntax 10 | # ====================== 11 | server 'example.com', user: 'deploy', roles: %w{web app db} 12 | 13 | # you can set custom ssh options 14 | # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options 15 | # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) 16 | # set it globally 17 | # set :ssh_options, { 18 | # keys: %w(~/.ssh/id_rsa), 19 | # forward_agent: false, 20 | # auth_methods: %w(password) 21 | # } 22 | 23 | fetch(:default_env).merge!(wp_env: :production) 24 | -------------------------------------------------------------------------------- /config/deploy/staging.rb: -------------------------------------------------------------------------------- 1 | set :stage, :staging 2 | 3 | # Simple Role Syntax 4 | # ================== 5 | #role :app, %w{deploy@example.com} 6 | #role :web, %w{deploy@example.com} 7 | #role :db, %w{deploy@example.com} 8 | 9 | # Extended Server Syntax 10 | # ====================== 11 | server 'example.com', user: 'deploy', roles: %w{web app db} 12 | 13 | # you can set custom ssh options 14 | # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options 15 | # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) 16 | # set it globally 17 | # set :ssh_options, { 18 | # keys: %w(~/.ssh/id_rsa), 19 | # forward_agent: false, 20 | # auth_methods: %w(password) 21 | # } 22 | 23 | fetch(:default_env).merge!(wp_env: :staging) 24 | --------------------------------------------------------------------------------