Overview

Skill Level: Intermediate

The purpose of this article is explain how to configure a DevOps Pipeline in Bluemix, that allows to build an application based on Wordpress, deploy it automatically to a development environment and promote it to test and production.

Ingredients

The recipe assumes a knowledge of IBM Bluemix concepts, Pipeline configuration, basic knowledge of PHP and Wordpress

Step-by-step

  1. Prepare your production environment

    This recipe will show you a basic example of how to build an automated pipeline for three different environments hosting a WordPress application. The main purpose is demonstrate how to solve some technical concerns related to the product and the automation, in this context we’re going to use a single space and share one database between all the environments (development, testing and production).

    In this first step you need to complete the Deploy and configure WordPress in Bluemix recipe, after do it you’ll have one environment with WordPress that will be used for Production.

    ProductionCreation

     

    Note: Based on your experience and needs you can take different strategies to implement it like separate the environments in different spaces to handle resources and access, use different databases to isolate the data of each environment, etc.

  2. Create the testing environment stub

    In this step we’ll create a PHP CloudFoundry application that will be used for the testing environment. To accomplish it, you must open the catalog (https://console.bluemix.net/catalog/) and create a CloudFoundry application using the PHP Buildpack.

    CatalogPHP-1

    Fill the applicatoin name field, in this step we’re going to use ‘WordpressSampleTest‘ as application name

    CreateTestApp-2

    This application will be located under the space called ‘dev‘ used in the previous step, this is to keep all the environments under the same space for this recipe, but remmeber that you can use a different strategy using different spaces for each one. Push the ‘Create‘ button to finish the procedure.

    BindDatabaseTest-3

    Go to the Connections area and press the Connect existing button to look for our Compose for MySQL instance, then click on this element and push the Connect button at the right-bottom of the screen.

    BindDatabaseServiceInstance-4

    At this point you’ll receive a dialog asking for a restage, to proceed you must press the Restage button.

    RestageTest-5

    After this action we can go to the Dashboard and check that the new application is available

    DashBoardWithTest-6

  3. Create the development environment stub

    In this step we need to create a new PHP Cloudfoundry application bound to the existing Compose for MySQL instance. We need to apply the same actions described in the step 2 of this recipe but using a different application name, for this case i’ll use WordPressSampleDev.

    The following screenshot shows the dashboard after complete the creation.

    DashBoardWithTestDev-7

     

  4. Configure the pipeline

    Go to the dashboard and look for the Production application (Because this one has got a Toolchain created), in this recipe’s case is WordPressSample.

    DashBoardWithTestDev-7

    Click on the application line to see the application settings, then scroll down looking for the Continuous delivery section, and press the View toolchain button.

    continuousDelivery-8

    Then, click on the Delivery Pipeline box

    DeliveryPipelineBox-9

    You’ll see the default pipeline, it looks like this picture

    InitialPipeline-10

    We’ll reconfigure the Deploy Stage, to make an automatic deployment to the Development environment, changing the WordPress configuration to use a special table prefix for this environment, in this way we’ll be sharing the database but not the tables and data between the different environments. To do it, we need to follow these actions

    1. Click the gear icon of the Deploy Stage box
    2. Select Configure stage option
    3. Click over the top title text and change the name from Deploy Stage to Deploy Development Stage
    4. Scroll down and change the Application name field from WordPressSample to WordPressSampleDev
    5. Go to Deploy script text area, and change the script to: #!/bin/bash
      sed -i “/\$table_prefix/c \$table_prefix = ‘wpdev_’;” wordpress/wp-config.php
      cf push “${CF_APP}”
    6. Push the Save button at the end of the form

    This is the result

    Pipeline-11

    We need to create a new stage for the test environment that will configure a different tablespace for WordPress to avoid mix data. But in this case we’ll not make it automated, so the team can use the play icon to trigger it manually and promote the code to the test environment. These are the steps to do it

    1. Click on the Add Stage button
    2. Set the name as Deploy Test Stage
    3. Scroll down to change the Stage trigger option to Run jobs only when this stage is run manually
    4. Click on the Jobs tab at the form’s top
    5. Click Add Job, then select Deploy type
    6. Scroll down and change the Application name field from WordPressSample to WordPressSampleTest
    7. Go to Deploy script text area, and change the script to:
      #!/bin/bash
      sed -i “/\$table_prefix/c \$table_prefix = ‘wptest_’;” wordpress/wp-config.php
      cf push “${CF_APP}”
    8. Push the Save button at the end of the form

    This is the result

    Pipeline-12

    Finally, we need to create a stage with a manual trigger to deploy the Production application using the default WordPress table prefix. These are the steps to accomplish it

    1. Click on the Add Stage button
    2. Set the name as Deploy Production Stage
    3. Scroll down to change the Stage trigger option to Run jobs only when this stage is run manually
    4. Click on the Jobs tab at the form’s top
    5. Click Add Job, then select Deploy type
    6. Push the Save button at the end of the form

    This is the final pipeline configuration

    Pipeline-13

  5. Prepare Git

    To start using the pipeline we need to deliver our application code to the git repository, during this initial action the master branch will be created. To accomplish this we need to follow these actions:

    1. Access to Orion Web IDE (Check the Deploy and configure WordPress in Bluemix recipe for details)
    2. Click on the Git icon located in the left bar of the IDE
    3. Fill the comment for the git commit
    4. Press the Commit button located at the right side of the screenGit-Commit-14
    5. Then we need to deliver the change to the remote git server, to do it we just press the Push button.Git-push-15
    6. Back to the pipeline (Open the WordPresssample application -> View toolchain -> Pipeline) and verify the result, the Build stage was triggered and the Deploy Development Stage executed. Note: The pipeline execution can take some minutes.Pipeline-FirstCommit
    7. Press the Play icon of the Deploy Test Stage to promote the content to this environment. Wait some minutes and verify the result, it should look like this screenshot:Pipeline-14

     

     

     

     

  6. Initialize WordPress in all the environments

    At this point we enabled the Development and Test environments but WordPress installation was not completed in them, we need to reproduce the Step 5 actions of the Deploy and configure WordPress in Bluemix . This is a summary of the process:

    1. Access to http://wordpresssampledev.mybluemix.net/wordpress/wp-admin/install.php to complete the installation.
    2. Select the installation language and press the Continue button.
    3. Fill the form (Set title, username, password, email) and press Install WordPress button.
    4. Press Login button and complete your login into http://wordpresssampledev.mybluemix.net/wordpress/wp-login.php with the purpose of verify the result.
    5. Access to http://wordpresssampletest.mybluemix.net/wordpress/wp-admin/install.php to complete the installation.
    6. Select the installation language and press the Continue button.
    7. Fill the form (Set title, username, password, email) and press Install WordPress button.
    8. Press Login button and complete your login into http://wordpresssampletest.mybluemix.net/wordpress/wp-login.php with the purpose of verify the result.

    The production instance is available and it was initialized during its creation in the Deploy and configure WordPress in Bluemix recipe, but we’ll deploy it again from the pipeline to follow the formal process that we’re setting. To do it you need to return to the pipeline (Open the WordPresssample application -> View toolchain -> Pipeline) and press the Play icon of the Deploy Production Stage, it should be the status after the job completion.

    Pipeline-final-16

    Finally we’ve got an automated pipeline integrated with git and manual triggers for test and production only. This screenshot shows the result of our recipe, three operative WordPress environments with different contents:

    FinalApplications

  7. Conclusion

    This recipe demonstrate that is possible to configure Bluemix to create an automated pipeline integrated with Git that can detect changes in the WordPress code, promote them automatically to a development environment and allow the project’s members to manually trigger the deployment to test or production instances keeping the data of these environments separated in different tables inside a same database.

     

    Next steps

    • Add monitoring and/or auto-scaling services.
    • Consider other strategies to isolate the data in different databases or use different spaces for a better access and resources controls.

Join The Discussion