Categories
Automation CI/CD DevOps

Go Docker CI in GitLab

Today, I’ll demo a sample Go Docker CI pipeline in GitLab. The pipeline will run on a sample Go containerized app. Hence the name Go Docker. If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
Best Practices

Add Redis Cache to WordPress

Using Redis cache may significantly speed up your web apps. Today we’ll see how to add Redis cache to WordPress. To achieve that I’ll deploy Redis, install PHP Redis client extension and install Redis Object Cache WordPress plugin.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Why do you need Redis for WordPress

After upgrade to WordPress 6.1 you may get a warning in Site Health tool: “You should use a persistent object cache”. Why do you need it?

Using Persistent Object Cache will speed up page load times by saving on trips to the database from your web server.

WordPress optimization docs

Remember that database queries are one of the most expensive ones. Some queries are performed for each page view. So why to not cache them in RAM? That’s where Redis comes to the rescue. It keeps most frequently used db queries results in RAM. Yet, what will read those queries’ results from Redis and from db if they are not available? Right, we need some backend between the webserver (e.g. Apache) and Redis along with the database. That’s where Redis Object Cache plugin comes into play and provides that backend.

Deploy Redis

You can install and deploy Redis in multiple ways. For example, install and run it as an OS package or using docker and Kubernetes. I’ll deploy containerized Redis, because it’s rather easy and doesn’t conflict with existing OS packages. The only OS packages you need are either docker or podman and their dependencies. I’ll use podman which is a deamonless alternative to docker. podman CLI is the same as docker’s, so you can use the same docker commands. Just replace the word docker with podman:

podman run --name redis -p 6379:6379 -d docker.io/redis

This method assumes you run WordPress not in a container, but rather as apache web app directly on your VPS (e.g. on Linode). For instance, if you deployed WordPress as a marketplace app. If you run WordPress in a container refer to the below way for deploying Redis.

To check your Redis is running and healthy enter its container and ping it:

podman exec -it redis bash
# redis-cli
127.0.0.1:6379> ping
PONG

If you rather prefer using a managed Redis solution, consider using Linode’s Redis marketplace app. Linode is a cloud provider recently purchased by Akamai. With this purchase, Akamai became a competitor in the cloud providers market.

Install Redis client php extension

Installing Redis client php extension might be optional. You may skip it and do that only if you discover that Redis Object Cache plugin is not working.

If you still need to install the client you can install
phpredis
or other supported extensions like predis.

Install Redis Object Cache plugin

You need Redis Object Cache plugin because it checks first whether the required data from WordPress DB is present in Redis cache. If it does, it reads it from Redis, otherwise queries the database. The plugin is basically a persistent object cache backend for WordPress. I’ll use composer and wp-cli for installation of the plugin and inspecting its status.

Configure WordPress to use Redis

If you use Bedrock WordPress setup, add to your application.php 2 below commands:

Config::define( 'WP_REDIS_HOST', '127.0.0.1');
Config::define( 'WP_REDIS_PORT', 6379 );

Add Redis cache to WordPress in Docker

If your WordPress setup is containerized e.g. in docker-compose stack, you can add Redis in as an additional service:

  redis:
    image: redis
    container_name: '${COMPOSE_PROJECT_NAME}-redis'
    restart: 'always'
    expose:
      - 6379

and raise it using docker-compose up -d redis.

In that case Config::define( 'WP_REDIS_HOST', '127.0.0.1'); will have to change to Config::define( 'WP_REDIS_HOST', '${COMPOSE_PROJECT_NAME}-redis');. In addition you’ll have to add COMPOSE_PROJECT_NAME variable to .env file. Of course, the above steps assume you use the Bedrock WordPress setup.

Summary

That’s it about adding Redis cache to WordPress. Feel free to share this article.

If you found this article useful, take a look at the disclaimer for information on how to thank me.

You may find interesting below articles I wrote:

Find out recommended Redis books on Amazon.

Categories
Automation DevOps

Kafka Producer and Consumer in Python

Today, I’ll demo Kafka producer and consumer written in Python. We’ll see a fully working demo of producer and consumer running against Kafka in a docker-compose stack.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
Automation CI/CD DevOps

Podman Jenkins Agent

Today, I’ll show Podman Jenkins agent assuming Jenkins runs on Kubernetes. We’ll see Podman agent’s Dockerfile and CI/CD pipeline using it.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
DevOps quick q&a

Live reload Node.js app inside Docker container during development

You probably found yourself in a situation when building new docker image of Node.js web app (e.g. express) with the new changes takes a long time. All you wanted is to test your changes fast on a live system…

To achieve that, use docker volumes or bind mounts to map your source code on the workspace to source folder inside Node.js web app container. You can verify the changes reach the container by inspecting the source code inside the container after you make a change on docker host.

In order for node process inside the container to pick up the changes, it needs to reload. Use nodemon for that.

I wrote about it here as well.

When I did all of the above, I didn’t know automation for this exits. Use tilt!

You can find below articles useful:

If you found this article useful, take a look at the disclaimer for information on how to thank me.

Categories
DevOps quick q&a

Azure-cli in Dockerfile in Alpine

Today we’ll see how to install Azure-cli in Dockerfile when the base image is Alpine. If you later find this article useful take a look at the disclaimer for information on how to thank me.

As you know azure cli allows you to control azure cloud aspects from command line. This may be useful for provisioning azure resources in ci/cd pipelines or automations, for instance. If the pipelines run inside Jenkins agents (e.g. Docker in Docker Jenkins agent, Podman Jenkins agent) which are containerized, you may need to package azure-cli inside them. Let’s see how to install azure-cli in Dockerfile.

Azure-cli installation in Dockerfile

You probably found it challenging to install Azure-cli as part of Dockerfile where the base image is Alpine.

Use below command sequence to achieve that:

RUN apk add --no-cache --update python3 py3-pip 
RUN apk add --no-cache --update --virtual=build gcc musl-dev python3-dev libffi-dev openssl-dev cargo make && pip3 install --no-cache-dir --prefer-binary azure-cli && apk del build

RUN apk add --no-cache --update python3 py3-pip installed python and pip. They are needed because azure-cli is basically Python package.

Second RUN installs os packages required for successful azure-cli installation. Then, pip installs azure-cli.

See also relevant discussion on GitHub about installation of azure-cli in alpine.

Why apk add –virtual?

Note that these os packages are installed in a virtual package which is removed after azure-cli installation using apk del virtual. This trick reduces the final built image size.

Note also that Azure CLI is a Python package. That’s why it requires Python and Pip to run. Hence these packages are not removed.

See this great answer on stack overflow about apk add --virtual. Note that apk add --no-cache reduces image size as well.

Summary

That’s it about Azure-cli installation in Dockerfile when Alpine is a base image.

Find out recommended Azure books on Amazon.

Find out recommended Azure courses on Pluralsight:

Sign up using this link to get exclusive discounts like 50% off your first month or 15% off an annual subscription)

If you found this article useful, take a look at the disclaimer for information on how to thank me.

Categories
Automation CI/CD DevOps

Running minikube in Docker container

In the last article we saw how to run Jenkins Docker in Docker Agent. In addition to its obvious use case of building and pushing Docker images, I also noted that such an agent allows to run minikube inside. Today, I’ll show how to run minikube in Docker container. Of course, we’ll use docker in docker client and daemon images for that.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
Automation CI/CD DevOps

Jenkins Docker in Docker Agent

So you installed Jenkins helm chart on Kubernetes cluster. Now you want to build Docker images. How would you do that? There are several ways. Today, we’ll focus on creating and using Jenkins Docker in Docker agent for that purpose.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
Best Practices Orchestration

RabbitMQ cluster as a single Docker Swarm service

I once configured RabbitMQ cluster as a single Docker Swarm service. Time has come to share this way with the world.

If you later find this article useful take a look at the disclaimer for information on how to thank me.

Categories
Automation CI/CD DevOps Orchestration

Kubernetes Volumes Introduction

What are Kubernetes volumes, their types and concepts behind them? We’ll cover all of that below. In addition, we’ll see practical demo of using Kubernetes volumes.