Skip to Content

Deploy a CAP Business Application to SAP Cloud Platform

test
0 %
Deploy a CAP Business Application to SAP Cloud Platform
Details

Deploy a CAP Business Application to SAP Cloud Platform

2020-03-25
This tutorial shows you how to deploy your SAP Cloud Application Programming Model (CAP) application into the Cloud Foundry environment of SAP Cloud Platform.

You will learn

  • How to deploy your business service on SAP Cloud Platform using the SAP Cloud Application Programming Model (CAP) and binding appropriate service instances (see the Developer Guide for Cloud Foundry).

Prerequisites


Step 1: Enhance project configuration for SAP HANA

It’s now time to switch to SAP HANA as a database.

  1. Add the following configuration in the package.json file of your my-bookshop project (overwrite any existing cds configuration):

    "cds":{
      "requires": {
          "db": {
          "kind": "hana",
          "model": ["db","srv"]
          }
      }
    }
    
  2. Add the SAP HANA driver as a dependency to your project:

    npm add @sap/hana-client
    

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

Log on to answer question
Step 2: 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.

  1. 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 hanatrial hdi-shared my-bookshop-db-hdi-container
    

    This process takes some minutes.

    Check the status of your service using cf service my-bookshop-db-hdi-container.

    If service creation fails, see the Troubleshooting guide for CAP.

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

    This process takes some minutes.

    The first command creates the SAP HANA table and view definitions along with manifest.yaml files in both in gen/db and gen/srv folders. Look at gen/db/manifest.yaml and see that it binds to the my-bookshop-db-hdi-container service that you’ve created in the previous step.

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

    name:              my-bookshop-srv
    requested state:   started
    routes:            my-bookshop-srv-....cfapps.sap.hana.ondemand.com
    
  4. Open this URL in the browser and try out the provided links, for example, .../catalog/Books. Application data is fetched from SAP HANA.

  1. 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 hanatrial hdi-shared my-bookshop-db-hdi-container
    

    This process takes some minutes.

    Check the status of your service using cf service my-bookshop-db-hdi-container.

    If service creation fails, see the Troubleshooting guide for CAP.

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

    This process takes some minutes.

    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. Look at gen/db/manifest.yaml and see that it binds to the my-bookshop-db-hdi-container service that you’ve created in step 2.

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

    ```
    name:              my-bookshop-srv
    requested state:   started
    routes:            my-bookshop-srv-....cfapps.sap.hana.ondemand.com
    ```
    
  4. Open this URL in the browser and try out the provided links, for example, .../browse/catalog/Books. Application data is fetched from SAP HANA.

Which categories can you see in your browser?
×

Give us 55 seconds of your time to help us improve

Next Steps

Back to top