Deploy Mule application on Cloudhub using Codefresh CI/CD

Akshay Jain
5 min readJun 28, 2022

--

Introduction:

In this blog we’ll see a brief explanation of CI/CD Pipeline in Codefresh to deploy a simple Mule application to Cloudhub.

What is CI/CD?

CI, short for Continuous Integration, is a software development practice in which all developers merge code changes in a central repository multiple times a day. CD stands for Continuous Delivery, which on top of Continuous Integration adds the practice of automating the entire software release process.

What is Codefresh ?

Codefresh is a Continuous Integration/Delivery solution. It fetches code from your GIT repository andpackages/compiles it. Then it deploys the final artifact to a target environment. This basic concept is implemented with pipelines. Codefresh works with all major Git platforms and Cloud providers.

Codefresh is offered in SAAS, Hybrid and on-premises modes. Before you consider on-premises please look at the hybrid mode first. In this mode Codefresh runs the Web UI while you only maintain the build nodes behind the firewall.

Even though Codefresh has great support for Docker and Kubernetes, you can still use it to deploy plain VMs, JAR files, static websites, Wordpress instances, Database changesets etc.

Here is an example with a traditional VM deployment.

Ref — Frequently Asked Questions · Codefresh | Docs

Prerequisites for Codefresh CI/CD pipeline with Mulesoft:

  • Anypoint Studio to develop your application.
  • Codefresh account.
  • An active Anypoint Platform account.
  • Maven and Git installed on your local system.

Steps to perform -

  1. Create a project in Anypoint studio which you wish to deploy on your cloudhub. For this tutorial we’ll take a simple example which consists of an HTTP Listener and a Logger component.

2. Now configure your project’s pom.xml to enable the deployment of your project on cloudhub via maven. This uses mule-maven-plugin which is already a part of your pom.xml generally, in case it is missing just add the dependency and use the following configuration:

<configuration>

<cloudHubDeployment>

<uri>https://anypoint.mulesoft.com</uri>

<server>Anypoint</server>

<muleVersion>${app.runtime}</muleVersion>

<applicationName>HelloWorld-10062022-prac</applicationName>

<workers>${numberOfWorkers}</workers>

<workerType>${workerType}</workerType>

<environment>${environment}</environment>

<businessGroup>Practice</businessGroup>

<properties>

<env>${env}</env>

<anypoint.platform.config.analytics.agent.enabled>true</anypoint.platform.config.analytics.agent.enabled>

<anypoint.platform.client_id>${anypoint.platform.client_id}</anypoint.platform.client_id>

<anypoint.platform.client_secret>${anypoint.platform.client_secret}</anypoint.platform.client_secret>

</properties>

<region>us-east-2</region>

<objectStoreV2>true</objectStoreV2>

</cloudHubDeployment>

<classifier>mule-application</classifier>

</configuration>

3. These variables can be defined at runtime, or can be directly given in the pom.xml, For further reading on these properties or any additional flags, you can visit the official documentation on https://docs.mulesoft.com/mule-runtime/4.4/deploy-to-cloudhub.

4. Remember to keep your application name unique, otherwise you’ll get an error while pipeline execution.

5. Be sure to check your Maven settings.xml file has all the correct credentials, otherwise your pipeline would fail. This settings.xml file is present at your Maven home in your local system. Or you can keep settings.xml file in your app root folder with credentials as variables.

<settings>

<servers>

<server>

<id>Anypoint</id>

<username>${server.username}</username>

<password>${server.password}</password>

</server>

</servers>

</settings>

6. Put your code to a git repository and add this codefresh.yaml file to root folder .
(https://github.com/Akshayapi/Hello/blob/main/codefresh.yaml).

Put your codefresh org name (you can see it under your username in codefresh) in placeholder <codefresh org name> in yaml file.

— The org name is hidden due to privacy concerns in this article —

7. Now once the yaml file, pom.xml and settings.xml files are done. Let’s create a project in codefresh.

Click “New project”

Name the project.

Create a pipeline.

8. Once the pipeline is created, under workflow tab select use YAML from repository option and copy your github repo url into the search field and select branch and your codefresh.yaml file.

9. Once your yaml file is visible in the editor you can check all the steps/stages and make necessary changes like mvn commands or arguments that you are going to use. Once that is done you can see Variables menu on extreme right of your screen where you can enter all the values for them.

Here serveruser , serverpass are credentials to your Anypoint platform account where you are going to deploy this app.

Once set, we are good to go and run this build manually. You can add a trigger as well using Triggers option.

10. Now run the build and see the progress.

11. Now you may check the Runtime Manager on cloudhub, and if the job was successful and all the parameters were correct you should see the application being deployed.

Conclusion:

We have successfully created CI/CD pipeline using Codefresh and deployed application to CloudHub.

--

--