WordPress deployment with configuration as a code with Configu open source project

Introduction

Configuration-as-Code(CaC) is a common and powerful buzzword in DevOps and Cloud Native. Rather than manually creating configurations from Graphical User Interface(GUI), It allows managing your system’s configuration settings by presenting a set of instructions to them in the form of text or code scripts. CaC is generally used to perform tasks such as server setup, application configurations, and network settings.

Let’s simplify this! Imagine you have a mechanical robot at home and want to tell it what to do. What are the best ways to inform them? Instead of using spoken words or buttons, you can write down the set of instructions on a sheet of paper. Standard instructions are as follows: “Turn Right, Turn Left, Move forward ten steps.”

Similarly, Configuration as code is like giving instructions to your robot. But instead of a robot, we’re writing them for our systems as programs and code. The best thing is they’re reusable, automated, tested, and consistent. Furthermore, version control allows you to switch from the current set of instructions to the previous or next one.

Why do I love Configuration as Code?

  1. Version Control: I’m guessing you’re familiar with version control tools like Git and SCM; you can store your configuration settings as code in their repositories. This will allow you to track the changes, collaborate with teams, and roll back to previous versions if something goes wrong, just like you manage code changes with Git.

  2. Automation: CaC saves a lot of time and reduces the chance of misconfiguration by automation simply by automating the providing and Configuration of servers, containers, or cloud resources by running your configuration scripts;

  3. Testing: I hope you have written some unit tests for your code. Similarly, you can write tests for your configuration code to ensure that it meets requirements that help to catch issues early in the deployment process.

  4. Reusability: The “Write once, deploy anywhere” approach allows you to reuse your configuration code for different environments, simplifying your deployments.

  5. Scalability: Your company deals with new projects; manually managing configurations becomes hectic as infrastructure grows. CaC allows you to quickly scale by applying the same code to new instances, making it efficient to manage many resources.

Introducing Configu Orchestrator and Configu Platform

Configu Orchestrator is an Open source software for streamlining, testing, and automating application configurations across environments, i.e., Configu Orchestrator is a standalone open-source tool for configuring applications.

  • Configu offers “configuration-as-code”, which is a concept that allows developers to declare configurations as code, making them easier to manage, test, and automate.

  • Configu Orchestrator is an open-source tool designed to help manage application configurations across different environments. It allows developers to declare configurations as code (using .cfgu.json files), making them easier to handle, test, and automate. This is particularly useful in complex, distributed environments where configurations can be scattered across multiple sources.

  • With the emergence of dynamic and distributed microservices architectures, application configurations are becoming more fragmented. Configurations are usually stored as plain text and are scattered across various sources, such as multiple stores, databases, files, git repositories, and third-party tools.

  • It is not uncommon for a company to have multiple stores for configurations. The Configu Orchestrator, which is an open-source software, is a powerful standalone tool designed to address this challenge.

Configu platform allows users to manage configurations from development to production, including testing, security, and tracking.

  • Configu Platform is a comprehensive solution for managing configurations throughout the software development lifecycle, from development to production. It also integrates with various tools and services, making it a one-stop solution for configuration management. The platform aims to enhance productivity, collaboration, security, and configuration control.

  • It also offers integration with various tools and services such as CI/CD, runtime environments, PaaS, and cloud service providers, making it a one-stop shop for all configuration needs.

  • Additionally, the platform promises to boost productivity, increase collaboration, remove bottlenecks, gain better visibility, advance security and compliance, ensure high reliability, and better control over access and permissions.

  • Configu is a useful tool for managing and collaborating on software configurations. It provides a flexible and adaptable process that’s important in today’s ever-changing tech landscape. It’s great to see a solution that can simplify things across different environments and systems.

  • Configu is a versatile system streamlines the integration process with existing workflows and systems. It can be tailored to meet the unique requirements of different teams and projects.

  • The system boasts a robust abstraction layer that enhances teams’ capacity to execute secure and error-free configuration operations during the software development lifecycle.

Challenges with WordPress Deployment

It’s important to understand that WordPress is a web application that requires a database to store its contents, user data, and other settings. Additionally, WordPress relies on PHP as a programming language to handle requests and generate HTML pages. Therefore, when setting up WordPress using Docker Compose, we must consider these dependencies and configure them properly.

Let’s say we have two different environments: staging and production, each with its own set of configuration files and services. The staging environment might have a simpler configuration file that allows us to easily test changes before deploying them to production. In contrast, the production environment may require stricter security measures and additional services like load balancing and firewall rules.

Furthermore, let’s assume that our WordPress installation has several plugins and themes, each with its own unique requirements for PHP versions, error reporting levels, and caching mechanisms. We may also have some legacy code that needs to run alongside modern frameworks like Laravel or Symfony. To simplify matters, our team comprises developers who prefer different IDEs, debugging tools, and workflows.

Imagine we want to deploy this entire stack across multiple clouds, such as Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure. Each cloud provider offers its own set of services and toolsets for configuring and managing resources. This means we must consider factors like instance types, network topology, storage solutions, and access control mechanisms specific to each cloud platform.

To tackle this level of complexity, we will utilize an open-source configu project and its capabilities to set environment variables to define the various services and their associated configurations.

Give them a star(⭐️) or even contribute. (Hacktoberfest is a great time to start your OSS journey.)

Tutorial Demo — WordPress Deployment

Let’s get our hands dirty by trying out configu with real-world use cases. One popular use-case around Individual developers and companies is deployment for WordPress Applications. WordPress was launched as a blog hosting and creation platform, but today, It’s widely adopted as a home of websites and blogs.

We will use the power of the Configu open-source project for configuration as a code to define secrets, variables, and necessary configurations, along with docker-compose deploying WordPress faster than ever. Before diving into the hands-on part, checking out the official Getting Started documentation provided by Configu is highly recommended.

💡 Note: We’re using MacOS for this demo; if you have any other system, install the necessary dependencies.

Pre-requisites

Setting Up the Configu CLI on your local system

  • Install the Configu CLI (OSS)
curl <https://cli.configu.com/install.sh> | sh

💡 You can use the configu orchestrator open-source with any config store you need. We’ll use the Configu Platform in this example because I love it.

Login to Configu Platform

configu login

Expected Output:

You must accept the authentication from your browser; for that, you must log in using your Github, Google, or any feasible platform. Once you receive the below output, you’re good to go.

💡 Configu has an interactive login if needed (for CI/CD processes or other non-interactive users, you can also log in using a token if required)

WordPress Installation using Docker Compose

  • Verify if you have already installed docker-compose on your system. If yes, then run the below command to make it executable for better use.
% docker-compose --version
Docker Compose version v2.19.1
% sudo chmod +x /usr/local/bin/docker-compose

  • Set up a project directory to organize your WordPress installation and related files. Navigate to your desired project location in the terminal. Create a new directory with the command:
% mkdir wordpress-project
% cd wordpress-project
  • We will now create a docker-compose.yaml file for the WordPress Installation using Docker Compose. This file will contain the necessary service and configuration required for WordPress Installation; hence, define them using your favorite code editor.

  • You can use the below file for this demo. This file contains WordPress image and MySQL image as a database and environment variables that we will define using the configu open source project.

Without Configu:

version: '3'
services:
  db:
    image: mysql:8
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 8000:80
    restart: always
    environment:
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
volumes:
  db_data: {}

With Configu:

version: '3'
services:
  db:
    image: mysql:8
    volumes:
      - db_data:/var/lib/mysql
    restart: always
~/Configu helps you remove this environment variables in file
  environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
/~
wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 8000:80
    restart: always
~/Configu helps you remove this environment variables in file
    environment:
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}~~
/~
volumes:
  db_data: {}
  • As you must have noticed, we’re using variables like ${WORDPRESS_DB_HOST} in the environment, So we need to define their values. Hence, We’re going to create a cfgu.json file to define them.

  • I have created a file.cfgu.json file i.e. shared below, for our WordPress installation. This will describe our software and will serve as our configuration declaration.

{
    "MYSQL_ROOT_PASSWORD": {
      "type": "RegEx",
      "pattern": "/^(?=.*[\\!\\@\\#\\$\\%\\^\\&\\*])[A-Za-z0-9\\!\\@\\#\\$\\%\\^\\&\\*]+$/",
      "required": "true",
      "description": "Password for the MySQL Database"
    },
    "MYSQL_DATABASE": {
      "type": "String",
      "default": "wordpress"
    },
    "MYSQL_USER": {
      "type": "String",
      "default": "wordpress"
    },
    "MYSQL_PASSWORD": {
      "type": "RegEx",
      "pattern": "/^(?=.*[\\!\\@\\#\\$\\%\\^\\&\\*])[A-Za-z0-9\\!\\@\\#\\$\\%\\^\\&\\*]+$/",
      "required": "true",
      "description": "Password for the MySQL Database"
      },
    "WORDPRESS_DB_HOST": {
      "type": "String",
      "default": "db:3306"
    },
    "WORDPRESS_DB_USER": {
      "type": "String",
      "default": "wordpress"
    },
    "WORDPRESS_DB_PASSWORD": {
      "type": "String",
      "default": "password"
    }
  }
  • Once you’re done creating the JSON file, Run the below command to verify and export the values.
Rohit@Rohits-MacBook-Pro wordpress-project % configu eval \\
 --schema './file.cfgu.json' \\
| configu export \\
--format 'JSON' \\

Upsert values

  • If you want to make any changes to the configuration in the .cfgu.json file, use configu upsert and set a path to assign configuration values to those variables.

  • In our case, I want to add WORDPRESS_2FA_SECRET and WORDPRESS_2FA_PROVIDER variables. This will allow us to authenticate WordPress using two-factor authentication by generating and validating 2FA tokens.

For Example:

configu upsert --store "configu" --set "prod" --schema "./file.cfgu.json" \\
    -c "WORDPRESS_2FA_SECRET=ROHITHELLO" \\ -c "WORDPRESS_2FA_PROVIDER=None" \\

Run the below command to verify and export the values to the newly created configu store.

Rohit@Rohits-MacBook-Pro wordpress-project % configu eval \\
--store 'configu' --schema './file.cfgu.json' \\
| configu export \\
--format 'JSON' \\

Expected Output:

{
  "MYSQL_ROOT_PASSWORD": "admin",
  "MYSQL_DATABASE": "wordpress",
  "MYSQL_USER": "wordpress",
  "MYSQL_PASSWORD": "password",
  "WORDPRESS_DB_HOST": "db:3306",
  "WORDPRESS_DB_USER": "wordpress",
  "WORDPRESS_DB_PASSWORD": "password",
  "WORDPRESS_2FA_SECRET": "ROHITHELLO",
  "WORDPRESS_2FA_PROVIDER": "None"
}
  • If you get the expected output, you have successfully configured Configu Schema. Now, Let’s complete our installation with the last step using configu. Running a local environment was never easier; Run Configu seamlessly with your docker-compose by including default commands.

  • Run the below command for local deployment:

configu eval --schema "./file.cfgu.json" | configu export --run "docker compose up -d"
  • Run the below command for production(prod) deployment
configu eval —store “configu” —set “prod” --schema "./file.cfgu.json" | configu export --run "docker compose up -d”

You should expect the below output after the downloading and pulling of images are completed:

  • Run “docker ps” to check whether your WordPress and MySQL container is running smoothly!

  • Use WordPress container port[0.0.0.0:8000->80/tcp] to access the WordPress installation from your browser.

  • Input the necessary information to create a website.

  • If you received the below output, Congratulations! your account is ready to log in.

  • Input the account details you created in Log In for your Configu Demo project.

  • Hurray! Your WordPress is Up and Running… Feel free to create a sample blog and publish it.

  • I hope you enjoyed this tutorial and were amazed by the capabilities of configu open source project for configuration as a code. Check the sample blog shared below and create your own.

Video Tutorial

Conclusion

Today’s tutorial was successful as we created WordPress efficiently using Docker Compose. Our step-by-step guide taught us how to install WordPress effortlessly while simultaneously configuring its details using the Configu Open Source project. By following this method, we ensured secure and expedited installations and deployments from the CLI, making it a much simpler process than it used to be. Overall, this tutorial was incredibly informative and gave us invaluable knowledge on effectively using Docker Compose and Configu Open Source for WordPress installations. I enjoyed working with the configu open-source project as it diminished my pain in managing secrets, variables, keys, and configuration files; hence, I can focus more on my workloads and deployments than any unnecessary struggles.

If you also liked it, give them a star(⭐️) or even contribute. (Hacktoberfest is a great time to start your OSS journey.)

Configuration-as-Code with Configu

Configu is a configuration management platform comprised of two main components:

Configu Orchestrator

As applications become more dynamic and distributed in microservices architectures, configurations are getting more fragmented. They are saved as raw text that is spread across multiple stores, databases, files, git repositories, and third-party tools (a typical company will have five to ten different stores). The Configu Orchestrator, an open-source software, is a powerful standalone tool designed to address this challenge by providing a unified interface and the Configuration-as-Code (CaC) approach.

Configu Cloud Platform

Configu Cloud is the most innovative store purpose-built for configurations, including environment variables, secrets, and feature flags. It is built based on the Configu configuration-as-code (CaC) approach and can model configurations and wrap them with unique layers, providing collaboration capabilities, visibility into configuration workflows, and security and compliance standardization. Unlike legacy tools, which treat configurations as unstructured data or key-value pairs, Configu leads the way with a Configuration-as-Code approach. They are treated as first-class citizens in the developers’ code by modeling configurations. This makes our solution more robust and reliable and also enables Configu to provide more capabilities, such as visualization, a testing framework, and security abilities.

Feel free to reach out to me anytime on 👉 Rohit Ghumare

Subscribe to my monthly newsletter here:

❤️ Follow Rohit Ghumare for more such awesome blogs

Did you find this article valuable?

Support DevOps Community by becoming a sponsor. Any amount is appreciated!