Deploy Mule Applications To CloudHub With Anypoint-CLI-v4

Deploy Mule Applications To CloudHub With Anypoint-CLI-v4

Introduction

The Anypoint Platform CLI (Command-Line Interface) is a powerful tool designed to streamline development, deployment, and management tasks within the Anypoint Platform ecosystem. With its intuitive command structure, developers can seamlessly interact with Anypoint Platform services, including API management, integration and monitoring, directly from the command line.

From deploying applications to managing resources, the Anypoint CLI enhances productivity by providing a convenient and efficient interface for developers to interact with the platform. In this blog we are going to see how to deploy using Anypoint- CLI. 

Installation

  • Anypoint CLI can exclusively be installed from npm. Prior to installing Anypoint CLI, certain prerequisites must be installed. They are 
  • Node.js version 16.0.0 to 18.14.0 
  • npm version 7 or later 
  • Download Node.js from the provided link and proceed with the installation. 

node.js 

Node.js

  

  • Verify the successful installation of Node.js and npm by checking their versions using the following command: 

node --version 

npm --version 

  • Execute the following command to install the core package of Anypoint CLI along with all default plugins. 

npm install -g anypoint-cli-v4  

  • Verify the successful installation of Anypoint-cli by checking its version using the following command: 

anypoint-cli-v4 --version  

Versions
  • Once you've installed the Anypoint CLI 4.x core package, you can proceed to install non-default plugins or update existing plugins using the following command: 

anypoint-cli-v4 plugins:install <plugin-name> 

  • Anypoint CLI allows you to install the following plugins. 
    • anypoint-cli-account-plugin 
    • anypoint-cli-api-mgr-plugin 
    • anypoint-cli-cloudhub-plugin 
    • anypoint-cli-designcenter-plugin 
    • anypoint-cli-exchange-plugin 
    • anypoint-cli-governance-plugin 
    • anypoint-cli-runtime-mgr-plugin 
    • anypoint-cli-datagraph-plugin 
  • To view the list of installed plugins along with their full version information, use the following command: 

anypoint-cli-v4 plugins --core 

Login To Anypoint Platform

  • Create a file named credentials with no extension in .anypoint directory with the data mentioned in the following image.
Data In Credential File
  • Create a connected app on anypoint platform with required scopes.
Connected App
  • Configure the connected app with anypoint-cli using following commands:
    • anypoint-cli-v4 conf client_id <connected app client_id>
    • anypoint-cli-v4 conf client_secret <connected app client_secret>
    • anypoint-cli-v4 conf organization <organization_id>
  •  Copy the connected app client_id, client_secret paste it under default section in the credential file mentioned above.
  • Now run the command mentioned below and connect to the anypoint platform.
anypoint-cli
Connected to Anypoint Platform From Anypoint-CLI
  • Check the list of environments with the command mentioned below. 
account environment list
List Of Environments

Deploy To CloudHub

  • Deploy the mule application into cloudhub using the following command.

runtime-mgr cloudhub-application deploy [appName][filePath]

Deployed to CloudHub
  • If the command is executed successfully, we could see the application in the runtime manager under sandbox environment.
Application in Runtime Manager
  • To stop the application, we use the following command:
runtime-mgr cloudhub-application stop <name> 
  • We can see the application is stopped in the anypoint platform.
Application Stopped
  • To start the application, we use the following command:
runtime-mgr cloudhub-application start <name>
  • We can see the application is started in the anypoint platform. 
Application Restarted

Conclusion

Developers can use Anypoint CLI to deploy applications in Runtime Manager by following these steps. This approach simplifies the management of cloud-based applications, allowing organizations to rapidly scale their infrastructure and respond to changing business needs with agility. As cloud-native architectures continue to gain prominence, mastering tools like Anypoint CLI becomes increasingly valuable for optimizing deployment workflows and accelerating time-to-market for innovative solutions. 

Mulecraft Footer