Deploy Your First Multitarget Application
- How to deploy a multitarget application (MTA) in Cloud Foundry environment
Prerequisites
- If you do not have a Cloud Foundry Trial subaccount and dev space on SAP BTP Cockpit yet, create your Cloud Foundry Trial Account and, if necessary Manage Entitlements.
- You have downloaded and installed the cf command line client for Cloud Foundry as described in the tutorial Install the Cloud Foundry Command Line Interface (CLI).
The example MTA demonstrates the creation of a service instance and an application, and the binding between them.
- Step 1
-
Create an
index.htmlfile with the following content:HTMLCopy<h3>Hello World!</h3> -
Archive the
index.htmlfile into acontent.ziparchive and place it to a directory that is calledmy_first_mta.
-
- Step 2
Copy the example below to an
mtad.yamlfile that is located in themy_first_mtadirectory.YAMLCopy_schema-version: "3.1" ID: app version: 1.0.0 modules: - name: my-first-app type: staticfile path: content.zip requires: - name: my-first-app-service parameters: memory: 64m disk-quota: 64m resources: - name: my-first-app-service type: org.cloudfoundry.managed-service parameters: service: application-logs service-plan: liteThe MTA deployment descriptor comprises of an MTA module, which represents a simple static application, and an MTA resource, which represents an
application-logsservice instance with plan lite. - Step 3
Execute the following:
ShellCopycf add-plugin-repo CF-Community https://plugins.cloudfoundry.org cf install-plugin multiapps - Step 4
Execute the following:
ShellCopycd <path to my_first_mta> cf deploy ./The result should be as follows:
OutputCopyDeploying multi-target app archive app.mtar in org <ORG> / space <SPACE> as <USER>... Uploading 1 files... <PATH_TO_MTAR> OK Operation ID: <MTA_OPERATION_ID> Deploying in org "deploy-service" and space "<SPACE>" Detected MTA schema version: "3" No deployed MTA detected - this is initial deployment of MTA with ID "app" Detected new MTA version: "1.0.0" Processing service "my-first-app-service"... Creating service "my-first-app-service" from MTA resource "my-first-app-service"... 1 of 1 done Creating application "my-first-app" from MTA module "my-first-app"... Binding service instance "my-first-app-service" to application "my-first-app"... Uploading application "my-first-app"... Started async upload of application "my-first-app" Scaling application "my-first-app" to "1" instances... Staging application "my-first-app"... Application "my-first-app" staged Starting application "my-first-app"... Application "my-first-app" started and available at "<ORG>-<SPACE>-my-first-app.<DEFAULT_DOMAIN>" Skipping deletion of services, because the command line option "--delete-services" is not specified. Process finished. Use "cf dmol -i <MTA_OPERATION_ID>" to download the logs of the process.is a unique identifier for each MTA operation. It can be later used for troubleshooting. In the output example above, the
application my-first-appis deployed and started. A service calledmy-first-app-serviceis also created and is bound to the application. Credentials are provisioned for the service instance and delivered to the application runtime in theVCAP_SERVICESenvironment variable.The example above shows the deployment from a directory where the MTA deployment descriptor is available.
If you want to deploy a ready MTA archive, with a file extension.mtar, execute the following command:Console commandCopycf deploy <PATH_TO_MTAR>When triggering a deployment from a directory, the MTAR is built under the hood and it can be verified by checking the new file
app.mtarin the current folder. - Step 5
To check the application, execute:
ShellCopycf appsThe result should be as follows:
OutputCopycf apps Getting apps in org <ORG> / space <SPACE> as <USER>... OK name requested state processes routes my-first-app started web:1/1 <ORG>-<SPACE>-my-first-app.<DEFAULT_DOMAIN>To check the service, execute:
Console commandCopycf servicesThe result should be as follows:
OutputCopycf services Getting services in org <ORG> / space <SPACE> as <USER>... name service plan bound apps last operation my-first-app-service application-logs lite my-first-app create succeededAll CF entities above compose the MTA with ID “app”. It can be displayed with the command:
Console CommandCopycf mta app Showing health and status for multi-target app app in org <ORG> / space <SPACE> as <USER>... OK Version: 1.0.0 Namespace: Apps: name requested state instances memory disk urls my-first-app STARTED 1/1 10.9M 5.2M <ORG>-<SPACE>-my-first-app.<DEFAULT_DOMAIN> Services: name service plan bound apps last operation my-first-app-service application-logs lite my-first-app create succeeded - Step 6
Extension descriptors are files complementary to the main deployment descriptor that provide additional data. They have a file extension
.mtaextand are external to the MTA archive.mtar. They are used to provide deployment specific information, for example, credentials to external services.-
Copy the example below to an
app-2-instances.mtaextfile:YAMLCopy_schema-version: "3.1" ID: app-instances-2 extends: app modules: - name: my-first-app parameters: instances: 2 -
Place the file to the directory
my_first_mta.
The extension descriptor is used to extend the MTA deployment descriptor (
mtad.yaml), so thatmy-first-appwill be scaled to two instances. -
- Step 7
Execute the following command:
ShellCopycf deploy ./ -e app-2-instances.mtaextThe result should be as follows:
OutputCopyOK Uploading 1 files... <PATH_TO_MTAR> OK Uploading 1 files... <PATH_TO_EXTENSION_DESCRIPTOR> OK Operation ID: <MTA_OPERATION_ID_2> Deploying in org "<ORG>" and space "<SPACE>" Detected MTA schema version: "3" Detected deployed MTA with namespace "null", ID "app" and version "1.0.0" Detected new MTA version: "1.0.0" Deployed MTA version: "1.0.0" Processing service "my-first-app-service"... Updating application "my-first-app"... Application "my-first-app" attributes are not modified and will not be updated Unbinding service instance "my-first-app-service" from application "my-first-app"... Binding service instance "my-first-app-service" to application "my-first-app"... Uploading application "my-first-app"... Content of application "my-first-app" is not changed - upload will be skipped. Scaling application "my-first-app" to "2" instances... Stopping application "my-first-app"... Starting application "my-first-app"... Application "my-first-app" started and available at "<ORG>-<SPACE>-my-first-app.<DEFAULT_DOMAIN>" Skipping deletion of services, because the command line option "--delete-services" is not specified. Process finished. Use "cf dmol -i <MTA_OPERATION_ID_2>" to download the logs of the process. - Step 8
To verify that the application is scaled to two instances, execute:
ShellCopycf appsThe result should be as follows :
OutputCopycf apps Getting apps in org <ORG> / space <SPACE> as <USER>... OK name requested state processes routes my-first-app started web:2/2 <ORG>-<SPACE>-my-first-app.<DEFAULT_DOMAIN> - Step 9
What does the MTA deployment descriptor consist of?