Dockerized Mulesoft & deploy with Harness – Canary Deployment

Overview and Scope

This demo post is about containerising Mulesoft Enterprise Edition “mule-ee-distribution”, standalone and using CentOS as base image, adding multiple layers including required java binaries using dockerfile. 30 days trail is used for this demo implementation. The focus will be on containerising and using that image in Harness CI/CD workflow and pipeline using Docker hub for storing image/container.

Harness CI/CD is used to build infrastructure, and configure Application, Services, and Environments, using workflows, pipelines. This post uses, Canary Deployment model, a pattern for rolling out releases to a subset of users or servers. The idea is to first deploy the change to a small subset of servers, test it, and then roll the change out to the rest of the servers.

Prerequisites :-

  1. Docker desktop for Mac
  2. Kubernetes – kubectl – https://kubernetes.io/docs/tasks/tools/
  3. Harness trial account – for building Infrastructure using workflows and pipelines.
  4. Mulesoft Enterprise edition – Standalone trials from http://www.mulesoft.org
  5. Java Binaries – AdoptOpenJDK [openjdk8-binaries]
  6. IDE – VSCode for building dockerfile
  7. Homebrew – Package Manager for macOS

Dockerize the Mulesoft – Create dockerfile with multiple layers

In order to containerise Mulesoft, we need to have below dependencies in the dockerfile files.

  • java binaries are prerequisites,
  • CentOs is used as base image,
  • Ports are exposed for communication and below are the requirements for this demo post.
Ports Required Description
PORT 8081-8082, 8091-8092Required by the Mule Apps
PORT 1098Mule JMX port (must match config file)
PORT 5000Configuration directory
PORT 7777Required for mule agent
  • Required volume – Mount Points are defined as below
Mount pointDescription
/opt/mule/appsRequired for Application deployment directory
/opt/mule/domainsRequired for Domains deployment directory
/opt/mule/confRequired for Configuration directory
/opt/mule/logsRequired for Logs directory

Docker Image packaging for MuleESB http://www.mulesoft.org

Create a dockerfile that will contain the Mulesoft standalone

FROM         centos:latest

# Define docker build ARGS
ARG JAVA_BINARIES=https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u265-b01/OpenJDK8U-jdk_x64_linux_hotspot_8u265b01.tar.gz
ARG RUNTIME_VERSION=4.3.0

# Define environment variables
ENV   JAVA_BINARIES $JAVA_BINARIES
ENV   TMP_DIR /tmp/
ENV   JAVA_HOME /opt/jdk
ENV   PATH $JAVA_HOME/bin:${PATH}
ENV   MULE_ARGS "${MULE_ARGS:-start}"
ENV     RUNTIME_VERSION $RUNTIME_VERSION
ENV     MULE_HOME /opt/mule

WORKDIR     /opt

# Install required binaries
RUN curl -L ${JAVA_BINARIES} -o jdk.tar.gz && \
  mkdir jdk && \
  tar xf jdk.tar.gz -C jdk --strip-components 1 && \
  rm -rf jdk.tar.gz && \
  curl -L http://s3.amazonaws.com/new-mule-artifacts/mule-ee-distribution-standalone-${RUNTIME_VERSION}.tar.gz -O && \
  tar xvf mule-ee-distribution-standalone-${RUNTIME_VERSION}.tar.gz && \
  rm -rf mule-ee-distribution-standalone-${RUNTIME_VERSION}.tar.gz && \
  ln -s /opt/mule-enterprise-standalone-${RUNTIME_VERSION} mule  && \
  adduser mule && \
  chown -R mule:mule /opt/mule-enterprise-standalone-${RUNTIME_VERSION} 
  
# Define mount points
VOLUME ["/opt/mule/logs", "/opt/mule/conf", "/opt/mule/apps", "/opt/mule/domains","/opt/mule/libs"]

# HTTP Service Port
# Required by the Mule Apps
EXPOSE      8081-8082
EXPOSE      8091-8092

# Mule remote debugger
EXPOSE      5000

# Mule agent 
EXPOSE      7777

# Mule JMX port (match Mule config file)
EXPOSE      1098

# Start Mule runtime
USER mule

#execute the commands
CMD [ "/opt/mule/bin/mule", "$MULE_ARGS" ]

In order to save time, I have pushed this image/container on docker hub, this will be used in the Harness CI/CD pipeline in the below following steps.

Setup and Configure Harness CI/CD

Setup and configure Harness CI/CD –

  1. Install the Harness Delegate
  2. Connect to your Infrastructure
  3. Connect to Artifact Repositories [dockerhub is used for this post]
  4. Configure your Application, Services, and Environments
  5. Build your Workflows and Pipeline then deploy!

Canary Deployment, we are starting with 30% of the instances.

Deploy

Using Harness CI/CD, we create a new deployment, use the latest tag for the service created above.

Canary Deployment Success- After a few minutes of running, we will see the container image is successfully rolled out.

Next Steps

Mulesoft setup and configuration is a separate post altogether, and it would be part of a following demo post.