Deploying a Mule Application to CloudHub Via AWS, Azure, and Jenkins
Learn how to deploy a Mule application to CloudHub via AWS, Azure, and Jenkins using mule-maven-plugin.
Join the DZone community and get the full member experience.
Join For FreeWhat are we trying to accomplish:
- Create a release pipeline that automates your software delivery process using AWS CodePipeLine, Azure DevOps and Jenkins.
- Automate code deployments by connecting your pipeline to Source Repo -> code changes committed to your source code repository and trigger Maven commands on different phases to perform further action with respect to application deployment.
- Use Mule Maven Plugin to automate deployment on CloudHub by extracting information from POM. AWS CodeBuild, Azure DevOps, and Jenkins will initiate the corresponding Maven command to trigger the deployment on CloudHub after application packing is completed.
For the purpose of this article, we created a simple Mule 4 project and configured mule-maven-plugin 3.1.6 for deploying to CloudHub.
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.1.6</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>${mule.version}</muleVersion>
<username>${cloud.user}</username>
<password>${cloud.password}</password>
<applicationName>${cloudhubAppName}</applicationName>
<environment>${cloud.env}</environment>
<businessGroup>${anypoint.businessGroup}</businessGroup>
<workerType>${cloudhub.workerType}</workerType>
<properties>
<key>value</key>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
Now we just need to run following maven command to deploy to CloudHub.
mvn package deploy -DmuleDeploy -Dcloud.env=Sandbox -Danypoint.businessGroup=<BusinessGroup> -Dcloudhub.workerType=Small -DcloudhubAppName=ramlapikitmule4 -Dmule.version=4.1.5 -Dcloud.user=<username> -Dcloud.password=<****>
Now we just need to run the above command via AWS, Azure, and Jenkins.
AWS Pipeline
AWS CodePipeline is an Amazon Web Services product that automates the software deployment process, allowing a developer to quickly model, visualize and deliver code for new features and updates. This method is called continuous delivery.
High-Level Architecture:
Login to your AWS console and choose the region in which code build service has to be used.
Now you will be prompted for Project Name and Description.
Then you will be asked for the source of the project.
Then we need to configure environment details on which the project will be built i.e. mvn commands will be executed.
No service role is required for deploying to CloudHub.
Build spec file is expected here, this will have pre/post build specifications.
Sample buildspec.yml required for building and deploying Mule 4 project.
version: 0.2
phases:
pre_build:
commands:
- echo Mule build-deployment phase initiated...
- mvn test
build:
commands:
- echo Build started on `date`
- mvn package
post_build:
commands:
- echo Build completed on `date`
- mvn deploy -DmuleDeploy -Dcloud.env=Sandbox -Danypoint.businessGroup=<BusinessGroup> -Dcloudhub.workerType=Small -DcloudhubAppName=ramlapikitmule4 -Dmule.version=4.1.5 -Dcloud.user=<username> -Dcloud.password=<****>
We didn't configure artifacts and logs for this code build configuration.
After completing the build phase, we ran our pipeline and it was successful.
You can now log in to CloudHub and your project will be successfully deployed there.
Azure DevOps
Azure DevOps is everything you need to build your software product from beginning to end. Learn how Azure DevOps helps you plan your project with Agile tools, manages your code using Git, and deploys your code through the best CI/CD system on the planet.
The overall architecture for Azure:
For deploying our project using Azure DevOps, we create a Repo on Azure cloud. Then, you need to go to pipelines and create a new pipeline:
When you click on create new pipeline, you will be asked to select the source of the project:
Then you will be asked to select an agent on which you want to build the project. We selected Ubuntu 1604 as we have a maven project.
You will then need to configure the maven phase and publish the artifact.
mvn compile test (goals have to be added here).
In publish artifact, we upload the artifact that we need during the deployment stage.
In the triggers tab, you can select the checkbox, "Enable Continuos Integration" to make sure Azure builds your project if the developer pushed the code in Repo.
Click on releases tab beneath build -> New release pipeline.
Now you will be required to add a stage and few deployment tasks inside that stage.
Now you will have to configure deployment tasks.
In download artifacts, we download the artifacts that we uploaded after the build.
package mule:deploy (goals have to be added here) in Maven task.
Now when you will run, you should get a success message.
Jenkins
For deploying to CloudHub via Jenkins, just follow the attached link.
https://github.com/manishkumarsah/BuildAndDeployThroughJenkinsPipeline
Conclusion
In this article, we have demonstrated how easy it is to configure an AWS Pipeline, Azure DevOps using Mule 4 Maven plugin.
Opinions expressed by DZone contributors are their own.
Comments