Automating WordPress deployment to Strattic hosting with Buddy

Last updated March 8, 2021

Automating WordPress deployment to Strattic hosting with Buddy

Strattic is a platform that allows you to turn your WordPress project into a static site in a couple of clicks.

In this guide, we will show you how to automate deploying code from a git repository to Strattic. Version control and delivery automation both give a serious edge when developing WordPress:

  • No need to use 3rd-party FTP clients
  • Thanks to Git, all of your code is hosted in one place enabling seamless collaboration
  • All changes are stored in the repository allowing for a quick roll-back if required
  • With tools like Buddy you can configure additional actions in your delivery pipeline, such as creating a CSS file from SCSS

Prerequisites

Here's what you need to follow this guide:

  • An account on Strattic
  • An account on Buddy
  • A WordPress project hosted in a Git repository

Let's start with putting your project under version control.

WordPress and Git

The first thing to take care of is hosting your source code in Git—the minimum requirement towards embracing CI/CD. While it's not exactly rocket science, there isn't a single right way to do it. If you're not familiar with Git, check out these articles to decide which approach is the best for you:

Creating a project in Buddy

With the code hosted safely in the repository, we can now configure (and automate) its deployment to Strattic.

  1. Sign in to your Buddy account and create a new project:

Creating a new projectCreating a new project

  1. Select Buddy as the code provider and enter the name of your project:

Buddy Git hosting – project detailsBuddy Git hosting – project details

You can also select any external Git provider like GitHub or Bitbucket.

  1. Follow the instructions on the screen to push the repository to the remote on Buddy.

Pipeline

Pipelines are set of tasks performed in the context of a selected repository. The pipeline we're about to configure will perform these operations:

  1. Deploy all modified files to the Strattic server.
  2. Send out a post-deployment message to Slack.

Creating the pipeline

  1. Click the button to add a new pipeline:

Creating a new pipelineCreating a new pipeline

  1. Define the name of the pipeline, choose the trigger mode – manual, on push (automatic), or recurrent (on a time interval) – and the branch watched by the pipeline.

Pipeline configurationPipeline configuration

  1. With the pipeline created, we can add the actions (tasks). Since we are going to deploy to Strattic, we shall choose the SFTP action as this is the protocol used by the service.

Configure the details according to the data found in the Strattic user panel. Make sure to choose Pipeline Filesystem as the upload source:

SFTP action configurationSFTP action configuration

Remember that the Source path and Remote path configuration change depending on the repository contents.

If you want to exclude any directories or files from the process, add them to the Ignore paths tab.

  1. Now it's time to define the notification. In this case we will use Slack, simply because it's the most popular messaging service among Buddy users. You can add the action in two places in the pipeline depending on what you want to achieve:

    • place it in the Primary Actions to get a notification once the files have been successfully uploaded
    • or move it down to Actions Run on Failure to get an instant message in case the upload has failed

Adding a 3-rd party service to the pipeline for the first time will open an integration window in which you need to authenticate Buddy. Once configured, select the channel to which you want to receive the notifications and define the contents of your message:

Slack action configurationSlack action configuration

Here's what the pipeline should look like after adding all actions:

Pipeline overviewPipeline overview

Click the Run pipeline button to deploy the files to the server — et voila! You just created a pipeline that makes deploying files from Git to a server so much easier! 🍾

Generating the static site

Once the deployment has finished, the last thing to do is to sign to your WordPress on Strattic and hit the publish the website to live by clicking that big red button:

Strattic publishingStrattic publishing

That's it – the website is live and published. 📰

Extending the pipeline

This pipeline already looks great, but Buddy lets you do much more than just deploying files to a server. Here's a couple things you can add to streamline the delivery.

Composer

Let's say that we've used Composer in our theme to download the required libraries. Following the good practices we shouldn't host the vendor files in our repo, but instead run composer install before each deployment. This guarantees that the right version of every library is installed every time.

With Buddy, you can automatically run the command on every deployment. Add the PHP action before the file transfer action:

Pipeline with PHP actionPipeline with PHP action

Use this configuration:

PHP action configurationPHP action configuration

npm

In WordPress themes, we're often harnessing the power of SCSS of JS transcompilation. When that's the case, npm is the go-to solution for managing your libraries.

If you want to generate new CSS and JS files with every deployment, simply add the Node action at the beginning of the pipeline:

Pipeline with npmPipeline with npm

Configure the action as follows:

Node action configurationNode action configuration

Make sure to use the command that you normally use to build the assets in place of npm run build.

More things you can do with Buddy

Deploying files to SFTP isn't the only thing you can do with WordPress in a Buddy pipeline. There are countless ways to customize and extend it with a number of actions. For example, you can:

Share

About the Author
Maciej Palmowski

Maciej Palmowski

WordPress & PHP Developer

Maciej is a WordPress developer working at WPMU DEV. Co-creator of Timber WP and active participant in the Open Source world, he spends most of his free time trying to find interesting news for WP Owls newsletter or cycling.

Buddy Makes Developers Happier

You use lots of tools to get web & app development done. Buddy creates more time in your day by helping you automate those tools.

Sign up for free with