Wondering how to Automate WordPress Deployments using Buddy? We can help 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
Here at Bobcares, we assist our customers to Automate WordPress Deployments using Buddy as a part of Server Management Services.
Today, let’s see how our Support Techs implement this for our customers.
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.
Installing WordPress with Docker
First, verify that Docker is running with the following command:
$ docker info
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
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:
Creating 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.
Building and Launching a Custom WordPress Theme
In this step, 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
Uploading a WordPress Project to a Remote Repository
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
Add the following filenames:
.cache-loader
composer.phar
dist
node_modules
vendor
Save and close the file.
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
Automating with Buddy
We will start by synchronizing Buddy with the repository. 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:
1. Branch from which Buddy will deploy the code.
2. Pipeline trigger mode.
Once we add the pipeline, we will need to create the following four actions:
1. PHP action that will install the required PHP packages.
2. A Node action that will download the dependencies and prepare a build for deployment.
3. Droplet action that will upload the build code directly to the DO Droplet.
4. 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. Select PHP from the list.
Clicking the action will open its configuration panel.
Enter the following commands in the terminal section:
# navigate to theme directory
cd sage
# install php packages
composer validate
composer install
Save and run the pipeline to ensure it works.
Next, we will set Environment to node latest.
The following commands will install the necessary dependencies and perform the build.
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
Once again, save and run the action to ensure it works.
Next, add the Droplet action right after the Node.js build.
1. Set the Source path to sage.
2. 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.
Then we need to visit the Ignore paths section and provide the following to prevent uploading of Node.js dependencies:
.cache-loader/
node_modules/
Last, 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 assistance? We are happy to help you]
Conclusion
To conclude, we saw our Support Techs automate WordPress deployments using Buddy.
0 Comments