×


Automate WordPress Deployments using Buddy

Are you trying to Automate WordPress Deployments using Buddy?

This guide is for you.

Buddy allows creating delivery pipelines with drag-and-drop actions in a visual GUI. Compared to many other CI/CD tools, Buddy requires less DevOps experience.
This GUI leverages pre-configured actions like builds, test, deployments, etc
BuddyPress is basically a “social network in a box” which helps you build any type of community website using WordPress, with member profiles, activity streams, user groups, messaging, and more.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to Automate WordPress Deployments using Buddy.
In this context, we shall look into how to Automate WordPress Deployments.

Steps to Automate WordPress Deployments using Buddy ?

Before going into the steps we will see the prerequisites for Automating using Buddy.
1. Docker and Docker Compose installed on the local machine.
2. Git installed on the local machine.
3. Composer installed on the local machine.
4. The Yarn package manager installed on the local machine.
5. PHP version 7.2+ installed on the local machine.
6. Node.js version 14+ installed on the local machine. This article was tested on Node.js version 14.13.0, npm version 6.14.8, and PHP version 7.4.10.
7. A WordPress installation on a DigitalOcean droplet. This is where you will deploy your customized theme after building it locally.
8. A fully-qualified domain name with an A record pointed to your WordPress Droplet’s IP.
9. A DigitalOcean Personal Access Token for the API.

How to install WordPress with Docker ?

i. First, verify that Docker is running with the following command:

$ docker info

ii. Then we can use the following command to download the latest version of the WordPress image:

$ docker pull wordpress
$ mkdir docker-wordpress-theme
$ cd docker-wordpress-theme
$ nano docker-compose.yml

iii. Add the following definitions to the file.

version: "3.1"

services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
- ./sage:/var/www/html/wp-content/themes/sage/
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: "1"
volumes:
- db:/var/lib/mysql

volumes:
wordpress:
db:


How to create a Custom WordPress Theme ?

We can use the following commands:

$ cd docker-wordpress-theme
$ composer create-project roots/sage

Press 1 to select the Bootstrap framework.

How to build and launch a Custom WordPress Theme ?

Here, we will install all your build dependencies, create a production build, and launch WordPress in a local Docker container.
We can use the following command:

$ cd ./sage
$ yarn add node-sass -D
$ yarn build:production

Once the build generates, exit the theme folder and launch your WordPress instance using Docker Compose:

$ cd ..
$ docker-compose up -d


How to upload a WordPress Project to a Remote Repository ?

i. Here we will upload our project to a remote Git repository that the Buddy platform can access.
We can use the following commands:

$ git init
$ git add remote https://github.com/user-name/your-repo-name.git
$ nano .gitignore

ii. Add the following filenames:

.cache-loader
composer.phar
dist
node_modules
vendor

iii. Save and close the file.

iv. And then add the project under version control and commit the files to the repository on GitHub:

$ git add .
$ git commit -m 'my sage project'
$ git push


How to automate with Buddy ?

We will start by synchronizing Buddy with the repository.
i. In the Buddy UI, click Create a new project, select the Git provider, and choose the repository that we created earlier.
The key settings to configure are:
a.  Branch from which Buddy will deploy the code.
b.  Pipeline trigger mode.

ii. Once we add the pipeline, we will need to create the following four actions:
a. PHP action that will install the required PHP packages.
b. A Node action that will download the dependencies and prepare a build for deployment.
c. Droplet action that will upload the build code directly to the DO Droplet.
d. An SSH action with a script that will activate your theme.

Based on the contents of the repository, Buddy will automatically suggest the actions to perform.
iii. Select PHP from the list.
Clicking the action will open its configuration panel.
iv. Enter the following commands in the terminal section:
# navigate to theme directory

$ cd sage

# install php packages

$ composer validate
$ composer install

v. Save and run the pipeline to ensure it works.

vi. Next, we will set Environment to node latest.

The following commands will install the necessary dependencies and perform the build.

vii. Add them to the terminal box just like before:
# navigate to theme directory

$ cd sage

# install packages

$ yarn install

# Create production build

$ yarn build:production

viii. Once again, save and run the action to ensure it works.
ix. Next, add the Droplet action right after the Node.js build.
a. Set the Source path to sage.
b. And choose Buddy’s SSH key authentication mode as that is the easiest one to set up.

After that go back to the browser and click the Remote path browse button.
The default path will be /var/www/html/wp-content/themes/sage.

x. Then we need to visit the Ignore paths section and provide the following to prevent uploading of Node.js dependencies:

.cache-loader/
node_modules/

xi. Finally, we will add one more action to activate the theme on the WordPress Droplet with a WP-CLI command.
On your pipeline page, add the SSH action and input the following command in the commands section:

$ sudo -u www-data -- wp theme activate sage/resources


[Need urgent assistance with WordPress Deployments? We are happy to help you. ]


Conclusion

This article covers how to automate #WordPress #deployments using Buddy. Buddy has become the foundation of every WordPress project you need to create. With Buddy you can run really complicated deployments with just one click. It also helps me to update plugins and monitor the uptime.
You can automate anything including sales, marketing, administrative tasks, learning and any other kind of processes you want letting you save time and get focused on your most important work.
BackupBuddy is one of the most reliable WordPress backup plugins that can help you back up your whole WordPress website installation.

Features of #Buddy:
1. Composer - Automatically install dependencies on server on every commit.
2. Zero-downtime deployments - Ensure 100% uptime of your websites with preconfigured atomic deployment templates.
3. Test-ready - Easily introduce unit and browser tests to improve the quality of your websites.
4. Docker support - Standarize your development environment and fast-track release times with Docker.
5. Real-time monitoring - Monitor websites for performance, SEO, and accessibility. Receive warnings when things go wrong.
6. WP-CLI - Run WordPress scripts to perform backups, update WP core, and migrate DB's.