Quality Management, Testmanagement, Testautomation, Continuous Integration and Delivery, Jenkins, Consulting, Training, Auditing
Docker Composer with Jenkins and Web Platform | Comquent GmbH, Continuous Quality in Software
Blog

Docker Composer with Jenkins and Web Platform

By Monday February 4th, 2019 No Comments
By
Docker Composer with Jenkins and Web Platform

Authors: Dimitrios V. Papadopoulos and Ioannis Gkourtzounis

 

Introduction

As we promised in our previous article, “Jenkins and Docker Integration for Continuous Delivery” (http://bit.ly/2D71OB2), we will now describe you a cycle of CI/CD using Docker, Jenkins, WordPress (as a to-be-tested platform) and a Test Automation project using the BDD Cucumber framework. As it is mentioned in the previous article, the above integration is going to accelerate and automate the CI/CD processes, resulting in more efficient daily routines.

Tools

Jenkins, Docker, Cucumber and Pipelines have been described in the first part. Here we will give you a small introduction about WordPress. WordPress (https://wordpress.com/) is a free open-source Content Management System based on PHP and MySQL. It also incorporates additional functionalities like a plugin architecture and a template system. It can be setup as a blog, a forum, an online store etc.

We have used WordPress to create a web platform as a demo, so that our Test Automation project can test it. Similar to any dynamic website, WordPress consists of its files that reside on a server (usually in the /var/www/html directory) and its database. We will focus on those two later.

At this point we will remind you that we have already created a test project using Java, Maven, Selenium, Junit, Cucumber and Groovy (for the build and test pipelines). The next step is to download all the files of the original WordPress website using FTP, in a zip file. We also need to download a dump of the WordPress database in sql format, this is easily done via phpMyAdmin or via command line.

With a full backup of the original WordPress website in our hands, our aim is to create a custom Docker container that can recreate this website, so that we can access this “copy” of the WordPress website. The purpose of re-creating the website with Docker is to enable us to run one single script and have the following results:

  • A container with an exact copy of the original WordPress website
  • A container with a preconfigured Jenkins instance, containing a test project ready to be built and ready to test the newly created WordPress website

Docker Compose architecture

In the previous article we configured a Dockerfile that is used for describing the settings and plugins of the Jenkins container. This time, there is a need of configuring a Docker compose yaml file to bring both, the copy of the WordPress website and the Jenkins instance, live.

Before this, let’s determine what Docker Compose is. According to the official Docker webpage (https://dockr.ly/2jh9kjV) we have the following definition: Docker Compose is a tool for defining and running a multi-container Docker application. In order to configure the application’s services, we create a yaml file following these steps:

  • Define the application’s services in a file named docker-compose.yml
  • Run the command docker-compose up. After this, Docker Compose will start the containers (copy of WordPress website and the Jenkins instance) and run the whole application

Docker composer enables us to run multiple services simultaneously and automated, providing efficiency and at the same giving us the ability to include all the configuration steps under one subsistence.

Docker Compose in action

Now let’s analyze what the docker-compose.yml file is going to include in its configuration. We implement the following functionalities:

1) create a MySQL container, which is needed by WordPress, and import a sql script that contains the original WordPress website database,

2) create a WordPress container and map the /var/www/html directory of the container to a host directory that contains the archive files of the original WordPress website,

3) create a Jenkins container with the procedure described in our previous post.

By executing the following command,

docker-compose up -d

,our services (Jenkins, WordPress and Database) are going to be live. We can access them by typing the host IP followed by the corresponding port number in the composer file (yml). For example, WordPress can exist under HOST_IP:6060 while Jenkins in HOST_IP:8090 and so on. As we can see, with just one configuration script and the use of Docker Composer, we created a container with an exact copy of the original WordPress website and a container with a preconfigured Jenkins instance, containing the test project. We can now build it, test the newly created WordPress website and get the test results in Cucumber Reports.

Conclusion

Having in our days a vast amount of projects and subprojects running at the same time, we need to use tools to make our processes run faster, automated and easier. Docker itself is an amazing tool and Jenkins is a state-of-the-art tool for CI/CD. The combination of these tools can provide us the optimum results that we seek for our operations giving us also the opportunity to customize our configuration in multiple ways. For example, we can create and build environments dynamically, with the use of containers and even test them with a dynamically created Jenkins instance.

We hope you enjoyed both articles (first part: http://bit.ly/2D71OB2). In case you need to ask something, do not hesitate to contact us, it will be our pleasure to help you.