Introduction
In CI/CD process, it is very common to use Mule Maven plugin to build and deploy application to the Cloudhub, on-premise private cloud like AWS, AZure, Google Cloud, etc. Since Mule 4, a lot of changes related to the deployment has changed, in particular, related to the Mule Runtime Fabric (RTF). Actually, RTF is a completely new infrastructure for Mule application deployment. I will cover more on that topic later. In this article, I am going to cover the following topics related to the deployment to Anypoint Runtime Fabric (RTF):- Prepare pom.xml setup to deploy mule project to Anypoint RTF
- Encrypt password
- Troubleshooting
If everything works, at the end, we should be able to achieve the following goals:
- deploy mule projects (assets) to Anypoint Exchange
- deploy mule projects to Anypoint Runtime Fabric
In order for mule maven plugin to work, we need change the following two files:
- pom.xml
- ./m2/settings.xml
The complete project for this article can be find at my github repository
Settings.xml
In order to deploy mule applications using mule maven plugin, we need to set the Anypoint credentials, which are the ones we use to login to anypoint portal (http://anypoint.mulesoft.com). The best way to do this is to add server information in the .m2/settings.xml as the following:1 2 3 4 5 6 7 | < servers > < server > < id >ExchangeRepository</ id > < username >gary_liu_client</ username > < password >{5XLgXNDBGBIHa99xNAyJ6gL+ZxyUiyIJNHWu0H7Ctew=}</ password > </ server > </ servers > |
1 2 3 | < settingssecurity > < master >{Vq5Aso1ZkO4HdJrUscJTZEii4BcFy+khGiGxDNVNgc4=}</ master > </ settingssecurity > |
1 2 | $ mvn --encrypt-master-password MasterPassword {+4nnH6EW9HcHAHYBGnloFCAZZHSC4W3Xp9Zls0LvBqk=} |
1 | mvn --encrypt-password AnypointPortalPassword |
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | <!--xml version="1.0" encoding="UTF-8" standalone="no"?--> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > < modelversion >4.0.0</ modelversion > < groupid >fea874ca-11d9-4779-b1ce-90d49f738259</ groupid > < artifactid >mule-maven-plugin</ artifactid > < version >1.0.2</ version > < packaging >mule-application</ packaging > < name >mule-maven-plugin</ name > < properties > < project.build.sourceencoding >UTF-8</ project.build.sourceencoding > < project.reporting.outputencoding >UTF-8</ project.reporting.outputencoding > < mule.maven.plugin.version >3.2.3</ mule.maven.plugin.version > < anypoint.provider >MC</ anypoint.provider > < deployment.environment >QA</ deployment.environment > <!-- <deployment.target>qa-azure-rtf</deployment.target> --> < app.runtime >4.1.4</ app.runtime > < app.name >gary-deployment</ app.name > < app.cores >100m</ app.cores > < app.memory >500Mi</ app.memory > </ properties > < build > < plugins > < plugin > < groupid >org.mule.tools.maven</ groupid > < artifactid >mule-maven-plugin</ artifactid > < version >${mule.maven.plugin.version}</ version > < extensions >true</ extensions > < configuration > < runtimefabricdeployment > < uri >${anypoint.uri}</ uri > < provider >${anypoint.provider}</ provider > < environment >${deployment.environment}</ environment > < target >${deployment.target}</ target > < muleversion >${app.runtime}</ muleversion > < server >ExchangeRepository</ server > < applicationname >${app.name}</ applicationname > < deploymentsettings > < replicationfactor >${deployment.replica}</ replicationfactor > < cpureserved >${app.cores}</ cpureserved > < memoryreserved >${app.memory}</ memoryreserved > </ deploymentsettings > </ runtimefabricdeployment > < classifier >mule-application</ classifier > </ configuration > </ plugin > < plugin > < groupid >org.codehaus.mojo</ groupid > < artifactid >properties-maven-plugin</ artifactid > < version >1.0.0</ version > < executions > < execution > < phase >initialize</ phase > < goals > < goal >read-project-properties</ goal > </ goals > < configuration > < files > < file >${maven.properties}</ file > </ files > </ configuration > </ execution > </ executions > </ plugin > </ plugins > </ build > < distributionmanagement > < repository > < id >ExchangeRepository</ id > < name >Corporate Repository</ name > < layout >default</ layout > </ repository > </ distributionmanagement > < dependencies > ...... </ dependencies > ...... </ project > |
Explanations
The configuration in both pom.xml and settings.xml are pretty straightforward. Few items worths to explain. First, what is the latest version of mule maven plugin? This can be found at: https://docs.mulesoft.com/release-notes/mule-maven-plugin/mule-maven-plugin-release-notes. Currently, the latest verson is 3.2.3.
Secondly, I use another plugin in addition to the mule maven plugin, namely, properties-maven-plugin. This plugin allow us to pass a property file to the pom.xml.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < plugin > < groupid >org.codehaus.mojo</ groupid > < artifactid >properties-maven-plugin</ artifactid > < version >1.0.0</ version > < executions > < execution > < phase >initialize</ phase > < goals > < goal >read-project-properties</ goal > </ goals > < configuration > < files > < file >${maven.properties}</ file > </ files > </ configuration > </ execution > </ executions > </ plugin > |
1 | mvn clean deploy -DmuleDeploy -Dmaven.properties=src /main/resources/mule .rtf.deploy.properties |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < configuration > < runtimefabricdeployment > < provider >MC</ provider > < environment >QA</ environment > < target >qa-azure-rtf</ target > < muleversion >4.1.4</ muleversion > < server >ExchangeRepository</ server > < applicationname >${app.name}</ applicationname > < deploymentsettings > < replicationfactor >1</ replicationfactor > < cpureserved >100m</ cpureserved > < memoryreserved >500Mi</ memoryreserved > </ deploymentsettings > </ runtimefabricdeployment > < classifier >mule-application</ classifier > </ configuration > |
Publish Assets To Exchange
In order to deploy mule application to RTF using Mule Maven Plugin, we must publish the application (asset to Anypoint Exchange). To me this is extra step unnecessary. To publish an artifact (asset) to the Anypoint Exchange, we run the following command:1 | mvn clean package deploy -Dmaven.properties=src /main/resources/mule .rtf.deploy.properties |
https://anypoint.mulesoft.com/exchange/{groupId}/{artifactId}
Here is an my example:
https://anypoint.mulesoft.com/exchange/fea874ca-11d9-4779-b1ce-90d49f738259/mule-maven-plugin/
Deploy Application To RTF
Deployment to RTF could be slow and sometimes could take very long time if it failed. I think the plugin should be improved on this by using asynchronous deployment instead of waiting and constantly checking with the runtime manager. Any way the deployment to RTF can be done using the following command:1 | mvn clean package deploy -DmuleDeploy -Dmaven.properties=src /main/resources/mule .rtf.deploy.properties |
Take Aways
The commands used in the process:1 2 3 4 | mvn --encrypt-master-password GaryLiu1234 mvn --encrypt-password GaryLiu1234 mvn clean package deploy-Dmaven.properties=src /main/resources/mule .rtf.deploy.properties mvn clean package deploy -DmuleDeploy -Dmaven.properties=src /main/resources/mule .rtf.deploy.properties |
https://anypoint.mulesoft.com/exchange/{groupId}/{artifactId} Key Considerations using the Mule Maven Plugin in the CI/CD:
- Make sure don't wait for the deployment to finish as it can take very long time
- There are rest API you can check the deployment process. You should use the APIs to check the deploy
- At the moment, anypoint-cli is not working for RTF
Hello Gary, did you try deploying using the Mule RTF API? https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/amc-application-manager/
ReplyDeleteThanks for sharing this useful information with us.
ReplyDeleteMulesoft Online Training
Mulesoft Training in Hyderabad
Very informative post for mulesoft developers.You can also visit goformule.com for mulesoft stuff.
ReplyDeleteThanks for your blog very well explained. Keep posting.
ReplyDeletemulesoft course
mule training
ReplyDeleteIt is amazing to visit your site. Thanks for sharing this information, this is useful to me...
Mulesoft Training in Bangalore
Mulesoft Training Hyderabad
Best Mulesoft Online Training
Best Mulesoft Training
Mulesoft Course Online
Mulesoft Training and Certification
Mulesoft Architecture Certification
Mulesoft Course
Mulesoft Developer Certification
Mulesoft Self Learning
Mulesoft Online Training in India
Mule 4 Online Training
Mulesoft Online Training india
Mulesoft Online Training in Hyderabad
nice blog.thanks
ReplyDeletemulesoft training
mulesoft online training
Thanks For the Great Content.
ReplyDeleteMulesoft Online Training in India
Best Mulesoft Training