Search

Deploying to Cloud

CAP applications can be deployed into the Cloud Foundry Environment of SAP Cloud Platform. At the end, it’s about deploying regular Node.js and/or Java applications, and about creating and binding appropriate service instances (see the CF Developer Guide).

Note: The following sections are a continuation of the Getting Started in a Nutshell tutorial.

Prerequisites

Enhance project configuration for SAP HANA

When continuing the Getting Started in a Nutshell tutorial, it’s now time to switch to SAP HANA as a database.

Add the following configuration to package.json (overwrite any existing cds configuration):

"cds": {
  "requires": {
      "db": {
        "kind": "hana",
        "model": ["db","srv"]
      }
  }
}

Add the SAP HANA driver as a dependency to your project:

  npm add hdb

If your .cdsrc.json file contains a "target" entry, remove it or set it to: "target": "gen". This will cause deployment files to be written to this folder. Otherwise the deployment files would be written to the source folders.

Deploy using cf push

Cloud Foundry Environment of SAP Cloud Platform has a built-in cf push command to deploy applications. It needs the application files plus an optional manifest.yml file to push the application code and to bind the relevant services to the application.

As cf push can only bind but not create services, you need to create the SAP HANA service manually (along with an HDI container and a database schema):

cf create-service hana hdi-shared bookshop-db-hdi-container

On trial landscapes, replace the service type hana by hanatrial. If service creation fails, see the troubleshooting guide.

Now, build and deploy both the database part and the actual application:

cds build/all
cf push -f gen/db
cf push -f gen/srv --random-route

The first part of the command creates the SAP HANA table and view definitions along with manifest.yaml files in both in gen/db and gen/srv folders. Take a look at gen/db/manifest.yaml and see that it binds to the bookshop-db-hdi-container service that you created above.

In the deploy log, find the application URL in the routes line at the very end:

name:              bookshop-srv
requested state:   started
routes:            bookshop-srv-....cfapps.sap.hana.ondemand.com

Open this URL in the browser and try out the provided links, for example, .../browse/Books. Application data is fetched from SAP HANA.

Deploy using MTA

For clean, production-like (pipeline) builds and deployments, we enhance our application to become a Multitarget Application (MTA). The MTA build tool creates a self-contained MTA archive, packaging the different parts of the application (DB, service, and UI).

CAP provides a tool to generate an MTA descriptor mta.yaml out of your CAP project. You can extend generated descriptors with your own MTA extension descriptors if required.

  1. Download and install the MTA plugin for the CF CLI.

  2. Install the MTA Build Tool by
      npm install -g mbt
    

    Note that you might need to install more things (for example, GNU Make on Windows), to let the MBT run. Consider the installation section of the MTA Build Tool guide.

  3. To have the MTA development descriptor mta.yaml created in the project root folder, execute
      cds add mta
    

    Make sure you have at least @sap/cds-dk version 1.4 installed. Check with cds --version.

  4. Run the MTA Build Tool through
      mbt build -t ./
    

    An archive with extension .mtar is created in project root.

  5. Login to your Cloud Foundry space
  6. Deploy to Cloud Foundry with
      cf deploy <.mtar file>  # for example, bookshop_1.0.0.mtar
    

    This can take some minutes.

  7. Identify the URL of the application, for example bookshop-srv, in the CF space. Either watch the cf deploy log output, or use the SAP Cloud Platform Cockpit. Open this URL in your browser.

Got errors? See the troubleshooting guide.

How to Continue

You might now