Publishing to Anypoint Exchange and deploying to CloudHub 2.0 using Maven
- April 20, 2023
This technical article is a guide on how to publish your application to Exchange and deploy the same application to CloudHub 2.0 using Maven.
CloudHub 2.0
APIs and integrations can be deployed as small, lightweight containers in the cloud using CloudHub 2.0, a fully managed, containerized Integration Platform As a Service (iPaaS).
Why CloudHub 2.0?
- It enables deployment throughout 12 regions worldwide.
- Infrastructure and built-in services are scaled up or down dynamically to handle elastic transaction volumes.
- It includes integrated security rules that include firewall restrictions, restricted shell access and encrypted secrets that we don’t need to specify in artifact.json, to safeguard your services and sensitive data.
- It encrypts important configuration data in transit and at rest within the Anypoint Platform, including certificates, passwords and other data.
- By running each Mule instance and service as a different container, it offers a uniform isolation boundary.
Prerequisites
- The Mule Maven plugin required to deploy to CloudHub 2.0 should be greater than 3.7.X in your pom.xml.
- The application should be published to Exchange first.
CloudHub 2.0 is tightly coupled with the Exchange. Before deploying, CloudHub 2.0 will look for the same asset in Exchange if the asset is not present deployment will fail. Furthermore, after every change in code, the app version in POM should be updated and then deployed. The packaging type is referred from pom.xml which is:
<packaging>mule-application</packaging>
Steps to publish to Exchange using Maven:
- Add groupId as your organization ID in your pom.xml. You can get the organization Id by Logging into Anypoint Platform and navigating to Access Management. Look for the name of the top-level organization or the required business group, and view your organization ID in the organization information screen.
- To publish to exchange, we need to add the tag distributionManagement and specify the repository, the same repository ID should be specified in settings.xml
<distributionManagement>
<repository>
<id>Exchange2</id>
<name>Exchange2 Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v2/organizations/${project.groupId}/maven
</url>
<layout>default</layout>
</repository>
</distributionManagement>
- In the repository section
<repository>
<id>Exchange2</id>
<name>Exchange2 Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v2/organizations/${project.groupId}/maven
</url>
<layout>default</layout>
</repository>
- Update the settings.xml file in the .m2 directory with the correct username and password.
- ‘Settings.xml‘ file is a configuration file used by Maven to customize the behavior and settings. It is located in the ‘.m2’ directory. We need to specify the authentication credentials for accessing remote repositories that require authentication. Using the settings file, we will be able to deploy our assets to the Anypoint platform.
- Connected app: it is an application that has been registered and authorized to access resources and APIs within the Anypoint platform. With the help of OAuth 2.0 and OpenID Connect APIs, the Connected Apps feature offers a framework that enables an external application to interface with the Anypoint Platform. Connected Apps help users delegate their access without sharing sensitive credentials or giving full control of their applications to third parties. Actions taken by connected apps are audited, and users can revoke access at any time. The Connected Apps feature enables you to use secure authentication protocols and control an app’s access to user data. All things considered, employing Connected App credentials rather than account credentials in the Anypoint Platform offers a more secure and controlled way to authenticate and authorization for external applications or custom integrations, ensuring better security and compliance with organizational regulations.
Example of settings.xml file using the connected app:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<settings>
<servers>
<server>
<id>Exchange2</id>
<username>~~~Client~~~</username>
<password>${clientID}~?~{clientSecret}</password>
</server>
</servers>
<profiles>
<profile>
<id>Exchange2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>Exchange2</id>
<name>Anypoint Platform Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v2/organizations/${groupId}/maven</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-release</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Replace the ${clientId} and ${clientSecret} with correct values from your connected app and replace the groupId as well.
Publish the asset to Exchange using this Maven command:
mvn deploy
Below is the command used to publish to exchange -s command is used to specify the settings file location:
After deploying you will get build success:
To view the asset in exchange, add type=app.
https://anypoint.mulesoft.com/exchange/?type=app
After all these prerequisites are successfully completed we can deploy the app to CloudHub 2.0 below are the steps:
- Add the CloudHub 2.0 configuration in the pom.xml.
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudhub2Deployment>
<uri>https://anypoint.mulesoft.com</uri>
<provider>MC</provider>
<environment>Sandbox</environment>
<target>Cloudhub-US-East-2</target>
<muleVersion>4.4.0</muleVersion>
<server>Exchange2</server>
<applicationName>${project.name}</applicationName>
<replicas>1</replicas>
<vCores>0.1</vCores>
<secureProperties>
<secret.key>${secret.key}</secret.key>
</secureProperties>
<properties>
<https.port.value>8081</https.port.value>
</properties>
<deploymentSettings>
<generateDefaultPublicUrl>true</generateDefaultPublicUrl>
<http>
<inbound>
<lastMileSecurity>true</lastMileSecurity>
</inbound>
</http>
</deploymentSettings>
</cloudhub2Deployment>
</configuration>
</plugin>
- provider: Set to MC, for CloudHub 2.0.
- server: this should be the same as set in settings.xml. This is not the Mule server name.
- target: Specify either a shared space or a private space available in your Deployment Target values in CloudHub 2.0.
- secureProperties: this is used to encrypt values, so we don’t need to specify in artifact.json.
- Properties: if you are using HTTPS in CloudHub 2.0 the port for HTTPS is also 8081, and you need to enable the lastMileSecurity property in deploymentSettings. This will enable HTTPS traffic.
- To deploy your application to CloudHub 2.0 use the command:
MVN clean deploy -DmuleDeploy
Below is the command used -s command is used to specify the settings file location.
After successfully deploying:
After a successful deployment of the app, the status of the application will be Running in Runtime Manager.
This should be the last step toward your deployment. You should be able to access your application via Postman or any other REST client.
— By Sayli Shrungare