In this tutorial, I would like to show case you, how to create a CAP Project and then deploy this project to an SAP BTP Cloud Foundry environment without an SAP HANA Cloud as a database. Instead, we use a simple in-memory SQLite database to store the data.
There are many solutions and possibilities which you can find on the internet to deploy a such application, but certainly, none of them quiet worked for my case. I just wanted to create a simple CAP Project with one entity and then deploy this CAP project to a productive environment to ensure, that the developed project can run later a such environment.
I mostly see as part of SAP just tutorials, which describe how to setup a project via the mta.yml file and how to setup it correctly with manifest.json file. But all of them just seems not to work perfect.
Prerequisites
In order how to create a setup to ensure, we have the same configurations of an SAP BTP account, please read first this tutorial.
After we have setup the Cloud Foundry environment, we need the following prerequisites to build then our app:
- SAP Business Application Studio
To code and build our application, we need a development environment. This can be fulfilled with the SAP BAS. - SAP Cloud Foundry with space
To deploy your application later, we need a space inside your organization of your Cloud Foundry environment.
Setup
To create the deployment for your CAP project, you can follow this guidelines to add the necessary features. To sum up what features we really need, I have documented these here:
cds add xsuaa --for production # For authentication services
cds add mta # To create the multi target application configuration (mta.yml)
Check out now the mta.yml file and comment out the unnecessary parts of it:
_schema-version: '3.1'
ID: test_overview
version: 1.0.1
description: "A project to showcase side-by-side."
parameters:
enable-parallel-deployments: true
build-parameters:
before-all:
- builder: custom
commands:
- npx cds build --production
modules:
- name: test_overview-srv
type: nodejs
path: gen/srv
parameters:
buildpack: nodejs_buildpack
build-parameters:
builder: npm
ignore:
- "node_modules/"
provides:
- name: srv-api # required by consumers of CAP services (e.g. approuter)
properties:
srv-url: ${default-url}
requires:
# - name: test_overview-db
- name: test_overview-destination
- name: test_overview-auth
# - name: test_overview-db-deployer
# type: hdb
# path: gen/db
# parameters:
# buildpack: nodejs_buildpack
# requires:
# - name: test_overview-db
resources:
# - name: test_overview-db
# type: com.sap.xs.hdi-container
# parameters:
# service: hana
# service-plan: hdi-shared
- name: test_overview-destination
type: org.cloudfoundry.managed-service
parameters:
service: destination
service-plan: lite
- name: test_overview-auth
type: org.cloudfoundry.managed-service
parameters:
service: xsuaa
service-plan: application
path: ./xs-security.json
config:
xsappname: test_overview-${org}-${space}
tenant-mode: dedicated
Then, we build our application by using the command:
cds build --production # Build the CAP service for production
mbt build -t gen --mtar mta.tar # Build the MTA archive
Now we are ready to deploy our application to the Cloud Foundry (CF) instance.
Deploy
To deploy the service, we first need to sign in into our CF instance.
cf login
# or
cf login --sso
How to use the second command is described in this article.
After successfully signed in into CF, we start our hopefully final command.
cf deploy gen/mta.tar
In our BTP, we see now our instance as follows:
Test your code for production
You may experience some problems while deploying your application to your space. To checkout, what really happens when the app crashes within the deployment space, we can simulate that by using one of the following commands:
cds serve --production
# or
cds watch --profile production
Potential error messages
This is a list of possible error messages which you may face. Some of them can be fixed quickly by adding more definitions in the package.json file.
Error: Neither “hdb” nor “@sap/hana-client” could be found. Please make sure one of them is installed.
Solution: Make sure that you have declared in your package.json the following:
//...
"cds": {
"requires": {
"db": {
"kind": "sqlite",
"credentials": {
"database": ":memory:"
}
},
// ...
Error: Authentication kind “jwt” configured, but no XSUAA instance bound to application. Either bind an IAS instance, or switch to an authentication kind that does not require a binding.
We have to define here the JWT strategy or a XSUAA security file. To simply use the same configuration in production, we have to use the mocked definition:
"cds": {
"requires": {
//...
"[production]": {
"auth": "mocked"
}
}
}
For more information regarding authentication in SAP CAP, refer to this documentation: https://cap.cloud.sap/docs/node.js/authentication#strategies
Leave a Reply