• Sage

Atomic Deployment with Sage 9 and DeployBot

In this guide, we’ll cover how to automate seamless, zero-downtime Sage 9 deploys using DeployBot’s Atomic SFTP method.

Why Atomic Deployment?

Previously, we covered how to automate Sage 9 deployment using DeployBot. The method described in that guide is a basic SFTP deployment. Pro: it’s compatible with most hosting setups. Con: it could result in some downtime during the deployment. This is because in the earlier method your theme files are being updated while your site is actively reading from them. It’s trying to use a partially-deployed theme, which may not work.

Atomic deployment is a better method. With atomic deployment, the new version of your theme is deployed to a secondary location your site isn’t looking at. When the deployment has been successfully completed, your site is told to begin using the new release. There’s no in-between stage where your site is using a partially-deployed theme.

Prerequisites

Please note that this method requires shell access on your host.

To get started, follow the instructions in the first three sections of the previous guide. The steps in those sections are the same for both deployment methods.

  • Connect a repository
  • Create a container
  • Create an environment

Configure your server in DeployBot

After you create your environment, you may automatically be prompted to add a server. If not, navigate to Repositories → (your repository) → (your environment) and click "Add a server."

Sage 9 DeployBot server configuration
Server settings

  1. Select the "Atomic SFTP" deployment option
  2. Enter a name for your server
  3. Enter your SFTP host name or IP address and port number
  4. Enter the path to your uploads folder, followed by theme-deploys (e.g., /var/www/mysite/wp-content/uploads/theme-deploys)
  5. Enter your SFTP username and password
  6. In the Compile, compress, or minimize your code section:
    • Select the container your created
    • Enter yarn build:production in the code field.
  7. In the Run commands after new version is uploaded section, enter composer install --no-dev in the code field.
  8. In the Exclude certain paths from being uploaded section, add the following to the text area:
    .cache-loader
    .git
    node_modules
    /resources/assets
    .editorconfig
    .eslintrc.js
    .gitignore
    CHANGELOG.md
    CODE_OF_CONDUCT.md
    LICENSE.md
    package.json
    phpcs.xml
    README.md
    yarn.lock
    
  9. In the Run commands after new version becomes active section, enter ln -sfnr $RELEASE /var/www/mysite/wp-content/themes/my-theme in the code field, replacing /var/www/mysite/wp-content/themes/my-theme with the path to your themes folder followed by the name of your theme
  10. In the Advanced options section, enter yarn in the "Cached build commands" code field
  11. Click "Save"

Configured this way, DeployBot will create the wp-content/uploads/theme-deploys folder and deploy your theme there each time you run the process. Since multiple versions of your theme plus some files used by DeployBot are in this folder, we don’t want it in wp-content/themes.

Once each deployment is successfully completed and ready for use, the ln command creates (or updates) a symlink in your themes folder pointing to the latest release. Once this is done, your site will be using that release.

For further explanation of the other settings, refer back to the previous guide.

You’re done! Test your deployment.

That’s it! You can trigger a deployment manually (go to your repository page in DeployBot and click the "Deploy" button to the right of your environment) or automatically by pushing new commits to the branch you specified.

Start the discussion on Roots Discourse

Join over 5,800 subscribers on our newsletter to get the latest Roots updates, along with occasional tips on building better WordPress sites.

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?

“Easily the best WordPress email I get.” Colin OBrien

Follow us on Twitter @rootswp

Ready to checkout?