Search

Deploying to Cloud

Towards SAP Cloud Platform

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).

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. See the SAP HANA section for how to do this.

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

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

Now, build and deploy the project for a production environment:

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

This creates the SAP HANA table and view definitions along with manifest.yml files in both in gen/db and gen/srv folders. Look at gen/db/manifest.yml and see that it binds to the bookshop-db service that you created above.
If you don’t see a gen folder, check .cdsrc.json file if it contains a "target" entry. If yes, 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.

In the deploy log, find the application URL in the routes line at the 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:
      npm install -g mbt
    

    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
    

    For deployment to trial landscapes, replace the service type hana by hanatrial for the com.sap.xs.hdi-container resource in mta.yaml.

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

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

    If you omit the -t ./ from the mbt build command, the archive is located in the default folder, see the Cloud MTA Build Tool documentation. This deviation is not part of the following steps.

  5. Log in 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 Cloud Foundry space using cf apps. You could also 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: