Skip to Content

Deploy a CAP Business Service to SAP Business Technology Platform

This tutorial shows you how to deploy your SAP Cloud Application Programming Model (CAP) application to SAP Business Technology Platform (BTP), Cloud Foundry environment using SAP HANA Cloud service.
You will learn
renejeglinskyRené JeglinskySeptember 26, 2022

Prerequisites

It’s now time to switch to SAP HANA as a database and prepare your project for an MTA deployment to SAP BTP Cloud Foundry. To continue with this tutorial you need to Use an existing SAP HANA Cloud service instance or set up a new SAP HANA Cloud service instance to deploy your CAP application.

Your SAP HANA Cloud service instance will be automatically stopped overnight, according to the server region time zone. That means you need to restart your instance every day, before you start working with your trial.

  • Step 1
    1. If cds watch is still running in VS Code, choose Ctrl + C in the command line to stop the service.

    2. To prepare the project, execute in the root level of your project in VS Code:

      Shell/Bash
      Copy
      cds add hana,mta,xsuaa,approuter --for production
      

      --for production adds all configuration added by this command in the package.json file into a cds.requires.[production] block.

      hana configures deployment for SAP HANA to use the hdbtable and hdbview formats. The default format of hdbcds is not available on SAP HANA Cloud. In addition, the hdb driver for SAP HANA is added as a dependency. A data source of type hana-cloud is added in the cds.requires.[production].db block. See section Node.js configuration in the CAP documentation for more details.

      mta adds the mta.yaml file. This file reflects your project configuration.

      xsuaa creates an xs-security.json and also the needed configuration in the mta.yaml file. An authentication of kind xsuaa is added in the cds.requires.[production].auth block.

      approuter adds the configuration and needed files for a standalone AppRouter so that the authentication flow works after deployment.

      Learn more about those steps in the Deploy to Cloud Foundry guide in the CAP documentation.

    3. (Optional) To enable SAP Fiori preview add the following configuration in the package.json of your my-bookshop project in VS Code:

      JSON
      Copy
      "cds": {
        "features": {
          "fiori_preview": true
        },
      }
      
      

      fiori_preview:true enables SAP Fiori preview also in production mode as you saw it in your local application in the previous tutorial in step 4 when using cds watch. This feature is meant to help you during development and should not be used in productive applications.

      Don’t edit the gen/db/package.json file.

  • Step 2

    The Cloud Foundry API endpoint is required so that you can log on to your SAP BTP Cloud Foundry space through Cloud Foundry CLI.

    1. Go to the SAP BTP Trial Cockpit and choose Go To Your Trial Account.

      business technology platform cockpit view
    2. From the Account Explorer overview navigate to your subaccount.

      subaccount tile
    3. From your subaccount copy the Cloud Foundry Environment API Endpoint value.

      CF API endpoint value
    4. Go back to VS Code to the command line. Authenticate with your login credentials using the following command:

      Shell/Bash
      Copy
      cf login
      

      For this you need the cf command line client, see the prerequisites.

      This will ask you to select Cloud Foundry API, org, and space.

      The API Endpoint is taken by default. If you want to change the API Endpoint use cf api <CF_API_ENDPOINT> to change the API. Replace <CF_API_ENDPOINT> with the actual value you obtained in the previous step.

      If you don’t know whether you’re logged on to Cloud Foundry or if you’re wondering to which Cloud Foundry org and space are you logged on, you can always use cf target in a terminal to find out.

  • Step 3

    SAP provides an application format that respects the single modules and their technologies and keeps those modules in the same lifecycle: Multitarget Application

    The MBT Build tool uses the mta.yaml file that has been created using cds add mta before, to build the deployable archive. The MultiApps CF CLI plugin adds the deploy command and orchestrates the deployment steps.

    1. In VS Code, in the root of your project, execute the following command to build the archive.

      Shell/Bash
      Copy
      mbt build -t gen --mtar mta.tar
      

      For this you need the MBT Build Tool, see the prerequisites.

      The -t option defines the target folder of the build result as the gen folder of your project. As part of this build implicitly cds build --production is executed. This implicit build uses then all the configuration you’ve added in the step 1.2 when using --for production.

    2. Deploy the archive using cf deploy.

      Shell/Bash
      Copy
      cf deploy gen/mta.tar
      

      For this you need the MultiApps CF CLI plugin, see the prerequisites.

      During deployment all needed service instances are created and the applications as well as database artifacts are deployed.

      This process takes some minutes. In this one step the archive is uploaded to Cloud Foundry, service instances are created, the applications are staged, and then deployed to their target runtimes.

    3. In the deploy log, find the application URL of my-bookshop:

      Shell/Bash
      Copy
      Application "my-bookshop" started and available at "[org]-[space]-my-bookshop.cfapps.[region].hana.ondemand.com"
      

      This is the URL of the AppRouter, which enforces the authentication flow.

    4. Open this URL in the browser and try out the provided links, for example, .../catalog/Books. Application data is fetched from SAP HANA. If enabled in step 1.3 you can also try the Fiori preview.

      application preview

    What you achieved

    You’ve deployed your CAP application as multitarget application including deployment to SAP HANA Cloud, using the standalone AppRouter, and using authentication (XSUAA). Congratulations!

    Which entities are served by the catalog service?

Back to top