SAP-samples / cloud-cap-risk-management

The SAP Risk Management example applications show how to deploy a CAP (SAP Cloud Application Programming model) application to Cloud Foundry and Kyma.
Apache License 2.0
67 stars 94 forks source link

How to deploy and run in CF? #1

Closed js1972 closed 4 years ago

js1972 commented 4 years ago

I have cloned this repo and used npm install then npm start to run it locally however I'm unable to get it to deploy to CF.

I have used cds add mta. The mbt build and cf deploy <archive> and the deployment fails with these errors:

Uploading 1 files...
  /Users/i540401/dev/cloud-cap-risk-management/mta_archives/cpapp_1.0.0.mtar
OK
Operation ID: a4968401-06a5-11eb-ab22-eeee0a852866
Deploying in org "SAP CP CustomerSuccessTeam_hanatest" and space "hana_cloud_demo"
Detected MTA schema version: "3"
No deployed MTA detected - this is initial deployment
Detected new MTA version: "1.0.0"
Processing service "cpapp-db"...
Creating service "cpapp-db" from MTA resource "cpapp-db"...
0 of 1 done, (1 creating)
0 of 1 done, (1 creating)
0 of 1 done, (1 creating)
0 of 1 done, (1 creating)
0 of 1 done, (1 creating)
0 of 1 done, (1 creating)
1 of 1 done
Creating application "cpapp-db-deployer" from MTA module "cpapp-db-deployer"...
Creating application "cpapp-srv" from MTA module "cpapp-srv"...
Uploading application "cpapp-db-deployer"...
Uploading application "cpapp-srv"...
Started async upload of application "cpapp-db-deployer"
Started async upload of application "cpapp-srv"
Scaling application "cpapp-db-deployer" to "1" instances...
Scaling application "cpapp-srv" to "1" instances...
Staging application "cpapp-srv"...
Staging application "cpapp-db-deployer"...
Application "cpapp-db-deployer" staged
Executing task "deploy" on application "cpapp-db-deployer"...
Application "cpapp-srv" staged
Starting application "cpapp-srv"...
Error starting application "cpapp-srv": Some instances have crashed. Check the logs of your application for more information.
Download the application logs via the dmol command and check them for more information.
A step of the process has failed. Retrying it may solve the issue.
Proceeding with automatic retry... (3 of 3 attempts left)
Stopping application "cpapp-srv"...
Starting application "cpapp-srv"...
Error starting application "cpapp-srv": Some instances have crashed. Check the logs of your application for more information.
Download the application logs via the dmol command and check them for more information.
A step of the process has failed. Retrying it may solve the issue.
Proceeding with automatic retry... (2 of 3 attempts left)
Stopping application "cpapp-srv"...
Starting application "cpapp-srv"...
Error starting application "cpapp-srv": Some instances have crashed. Check the logs of your application for more information.
Download the application logs via the dmol command and check them for more information.
A step of the process has failed. Retrying it may solve the issue.
Proceeding with automatic retry... (1 of 3 attempts left)
Stopping application "cpapp-srv"...
Starting application "cpapp-srv"...
Error starting application "cpapp-srv": Some instances have crashed. Check the logs of your application for more information.
Download the application logs via the dmol command and check them for more information.
A step of the process has failed. Retrying it may solve the issue.
Process failed.
Use "cf deploy -i a4968401-06a5-11eb-ab22-eeee0a852866 -a abort" to abort the process.
Use "cf deploy -i a4968401-06a5-11eb-ab22-eeee0a852866 -a retry" to retry the process.
Use "cf dmol -i a4968401-06a5-11eb-ab22-eeee0a852866" to download the logs of the process.
 ~/dev/cloud-cap-risk-management  on cap/freestyle-ui5-app !1 ?2 

I have since found that it seems to be missing this dependency in the package.json: "@sap/hana-client": "^2.5.111",. however after adding this I get all sorts of integrity issues on that package when doing npm install.

I have tried to add this to the mta.yaml:

build-parameters:
     ignore: ["node_modules/"]

And this does allow npm install locally. However when running a CF deploy on the mta it fails every time with INTEGRITY issues.

Is this sample project simply not setup for use on CF and only for local testing.

gregorwolf commented 4 years ago

Hi @js1972,

I've tried a deployment to CF and found that when you first run cds add hana and then cds add mta followed by mbt build and cf deploy mta_archives/cpapp_1.0.0.mtar you get a working deployment.

Best regards Gregor

js1972 commented 4 years ago

Thanks @gregorwolf let me try it again in that precise order... In general I'm having a tough time getting any fiori app to deploy and launch for a cap project on CF.

js1972 commented 4 years ago

ok. If I simply run cds add hana (I need to use "hana": { "deploy-format": "hdbtable" }as my db is HANA Cloud) then cds add mta, then mbt build and finally cf deploy mta_archives/cpapp_1.0.0.mtar... Without running npm install first - then it deploys succssfully.

However I am unable to run the fiori apps inside the /app folder. i.e. this url: https://sap-cp-blahblah-hana-cloud-demo-cpapp-srv.cfapps.eu10.hana.ondemand.com/launchpage.html just gives the error:

Cannot GET /launchpage.html

If I leave the launchpage.html off I get the standard cds service visualisation: image

My understanding was that anything in the /app folder should be served?

This is the missing link in all of SAP's tutorials. We have great tutorials and tooling for working in CAP and deploying to CF. We also have great tutorials with working on fiori apps and deploying them to CF in the html runtime and the new sap cloud managed html5 apps. However we don't have anything that links the two.... If you can point me in the right direction that would be awesome?

gregorwolf commented 4 years ago

Unfortunately the CAP team does currently not include anything regarding the app folder when you run cds add mta. So you have to help yourself and add the module. Check out my example mta.yaml.

js1972 commented 4 years ago

Thanks again @gregorwolf - that example is very handy. I actually just had a realisation...

  1. What is in the /app folder is only served by CAP with the "fiori preview". So this is really no good for productive use.
  2. I can use the ui5-tooling or even fiori-tools to build a fiori elements app and just place it inside my cap project and inside the /app folder. As you said I then need to manually (and very painfully) adjust the mta.yaml file to add in sections for a UI module which uses the provided CAP service. Add an xs-app.json file for the approuter. It seems I do not need a specific approuter section in the mta.yaml (CAP must provide one already?!?). I then had to tear half my hair out fiddling with the file paths in the xs-app.json before it would work. Plus add another package.json in the /app folder to for the approuter.

But now I have a working CAP project with an embedded fiori elements app working in CF. Yay. It all without ay authentication of course so that's the next hurdle to get over. ;-)

Closing this issue. But would love to chat more about this...

E.g. What is the point of the following in the mta.yaml:

build-parameters:
      ignore: ["node_modules/"]

I also use the service.js OData V2 proxy and it seems to work fine with my fiori elements app but I notice you have an explicit section in your mta.yaml for this proxy - why? What benefit?

gregorwolf commented 4 years ago

Hi @js1972 , don't get to confused about my bookshop-demo. I try a lot of additional things. The separate proxy is an example to help when you're running CAP Java and need V2.

A good example how you can use the ui5-tooling is given in the project: SAP4Kids.

The ignore: ["node_modules/"] makes your mtar file significantly smaller. And as SAP CP Cloud Foundry doesn't use the SAP NPM registry anymore (since last Thursday) the build result will be the same when the package-lock.json is included in your mtar.

Best regards Gregor