After you followed all the steps to setting up Cloud Foundry in your SAP Cloud Platform Cockpit, it’s time to dig into and like all new environment you are testing, you’ll face some problems.
In this article, I’ll quickly overview the activation/installation and talk about a simple NodeJS with a MongoDB scenario. I hope it will help you to be more familiar with the tools, to implement your own needs on the platform.
Quick CF activation/installation
Install CF on your machine and follow instructions detailed here. One it’s installed, you need to test the CF CLI by typing cf in your favorite terminal.
A quota was not automatically assigned for my account because I had several sub accounts. Then, when I deployed an application, I get an error message:
Activate MongoDB / PostgreSQL and other services
Follow the path: Cloud Foundry > Services > Service Marketplace and activate the services you want to use. You can directly map the service with your app if you have already deployed it.
Create and deploy a NodeJS
First, you need to create a skeleton NodeJS project using the Nodeclipse available for free on the Eclipse Market or create your own project from scratch using the framework your like. You can simply download this project from my Github account : js-app-for-sap-cloud-foundry.
If you are not using mongodb in the scenario, you can comment the line require(‘./server/db/mongo-connect.js’)(oAppEnv);. It simplifies the workflow, you can uncomment it later. When your project is ready, be sure it compiles by running the two following commands:
npm install node app.js
If all is OK, your project is ready to be hosted on CF.
// Logon to Could Foundry cf login // Enter your credentials and navigate to the space you want to host the app // Change directory and push it! cd js-app-for-sap-cloud-foundry cf push
The file manifest.yml is very important for your app deployment, to specify the app information: commands, name, buildpack, etc. Below, an example of manifest.yml file
--- applications: - name: js-app memory: 512M host: js-app command: node app.js
Fields you need to know for the manifest.yml file:
|name||The name of the application|
|buildpack||The name of the Node.js buildpack determined before with command cf buildpacks. (by default an auto determination of the buildpack is done if the buildpack information is missing)|
|command||For NodeJS apps, a start command is needed to start the application. Here for example, it’s “node app.js”.|
|memory||RAM available for the application.|
|disk_quota||Disk space available for the application.|
|host||Host information used in the URL which makes the application accessible.|
Connect with a MongoDB
The first step is to create a new MongoDB instance. You have to go to your SAP CP CF sub account > Services > Service Marketplace and select MongoDB. Now in your left panel you can select Instances and create a new one (see below)
Now you are able to map your instance with the app you deployed before. The manifest.yml will change a little bit and the service will be mapped like this:
--- applications: - name: js-app memory: 512M host: js-app command: node app.js services: - mongodb-service
/!\ “mongodb-service” is the name of you instance, you need to adapt /!\
Github | SAP/hcp-cloud-foundry-tutorials
SAP CP | Cloud Foundry Tutorials
Github | Cloud Foundry CLI
Cloud Foundry CLI Reference Guide
Useful CLI commands
cf cf apps cf login cf logout cf push cf buildpacks cf marketplace cf api api.cf.<host information> cf create-service mongodb v3.0-dev mongo-service