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."
- Select the "Atomic SFTP" deployment option
- Enter a name for your server
- Enter your SFTP host name or IP address and port number
- Enter the path to your
uploads
folder, followed bytheme-deploys
(e.g.,/var/www/mysite/wp-content/uploads/theme-deploys
) - Enter your SFTP username and password
- In the Compile, compress, or minimize your code section:
- Select the container your created
- Enter
yarn build:production
in the code field.
- In the Run commands after new version is uploaded section, enter
composer install --no-dev
in the code field. - 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
- 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 yourthemes
folder followed by the name of your theme - In the Advanced options section, enter
yarn
in the "Cached build commands" code field - 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.
Join the discussion on Roots Discourse