WordPress in Docker. Part 2: Automation

WordPress in Docker. Part 2: Automation

In the first part of the guide we showed you how to dockerize your WordPress project and run it on the server using Docker Compose. This article we’ll tell you how to streamline the whole process down to a single push to Git repository.

Set up a project with Buddy

First you need to hook up your repository with Buddy:

  1. Sign up to Buddy with your GitHub/Bitbucket account or email

  2. Create a new project, select your Git provider, and choose your WP project:

    For the purpose of this guide we’ll use a Git repository with an existing WP theme: https://github.com/buddy-works/buddy-wp-theme.git

Attaching a repositoryAttaching a repository

Set up a delivery pipeline

Now you need to configure a delivery pipeline so that it automatically executes on every push to branch:

  1. Click Add a new pipeline

  2. Set the trigger mode to On every push

  3. Select the branch that will trigger the execution

  4. Click Add a new pipeline when ready:

Adding a new pipelineAdding a new pipeline

Define the delivery actions

Now it’s time to reproduce your workflow into actions:

You can use environment variables to tag your images in the registry, for example ${execution.to_revision.short_revision}.

  1. (Optional) Add a build action to process your files before the deployment. In this example we’ll use Gulp to test the application:

Build Action Example PipelineBuild Action Example Pipeline

  1. Add the Docker build action and configure the details:

  2. select the Dockerfile from the repository

  3. select the registry to which Buddy will push your image (eg. Docker Hub)

Configuring the detailsConfiguring the details

  1. Add the SFTP transfer action to upload docker-compose to the server:

  2. provide authentication details to your server

  3. select upload from the repository

  4. set the source path to the directory with docker-compose:

Adding the SFTP actionAdding the SFTP action

If you’re using our example repository make sure to edit the docker-compose file and enter the credentials to your Docker registry or Buddy will not be able to connect and pull the image!

Editing Docker ComposeEditing Docker Compose

  1. Add the SSH action to pull and run your Docker image on the server:

  2. provide authentication details to your server

  3. in the SSH commands field enter:

$ docker-compose down
$ docker-compose up -d

Adding the SSH actionAdding the SSH action

Run the pipeline

Congratulations! You have successfully configured the delivery pipeline. Make a push to the repository and watch Buddy automatically dockerize your project and run it on the server:

Awesome, isn’t it?

In the last part of the series we’ll show you how to run your project on a Kubernetes using Docker, which is especially useful if you seek high availability and scale for your apps. Stay tuned!