Skip to Content
Technical Articles

Deploying Applications into SAP BTP CloudFoundry: Part 1

Tutorial Overview:

This blog provides an overview on how to deploy an application into SAP Cloud Platform CF environment (now known as BTP).

At the end of this blog you will learn about:

  • Know what an approuter is.
  • Understand the basics of application deployment into SAP BTP.

What is an application router?

A application router also know as approuter is a nodejs application which serves as a single point of entry for all the other applications running in cloud foundry environment in SCP(now know as BTP i.e. Business Technology Platform).

Why do we need Application Router?

A  application running in cloud foundry environment can consist of several different microservices. Thus a central point of access is required which will not only authenticate but also forward(route) the incoming request to the respective microservices.

Hmm,too many technical terms used in the definition. Let us address them one by one.

Cloud Foundry:

Cloud Foundry is an open source platform (PAAS*) for developing ,deploying, running and scaling applications on the cloud.

MicroServices:

Microservices is an architectural style wherein an application is structured as a collection of independent services.

 

Steps to deploy a simple nodejs application into Cloud Foundry:

1. Create a new directory and initialise a Node.js Project via command:

npm init​

Note: It will create a package.json file in the root directory.

Example package.json looks like:

{
  "name": "<app-name>",
  "version": "1.0.0",
  "description": "<app-description>",
  "author": "<author-name>",
  "license": "ISC"
}

 

2. Install approuter and configure its dependency:

npm install @sap/approuter --save​

 

3. Make approuter as the starting point of this Node.js application .
It is done by adding the following script in package.json file:

"scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
}

Example package.json looks like:

{
  "name": "<app-name>",
  "version": "1.0.0",
  "description": "<app-description>",
  "scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
  },
  "author": "<author-name>",
  "license": "ISC",
  "dependencies": {
    "@sap/approuter": "^10.0.0"
  }
}

 

4. Create a file called xs-app.json with the following contents:

{
    "welcomeFile" : "index.html",
    "authenticationMethod" : "none"
}

Note: xs-app.json is the application router configuration file.
Thus as the name suggests all the routes of the application are defined is the application descriptor file.

 

5. Create a file called index.html inside folder resources with the following content:

Hello World

 

6. Create a file called manifest.yml with the following contents:

---
applications:
  - name: <app-name>
    buildpack: nodejs_buildpack
    memory: 512M

Note:

Manifest.yml also know as deployment descriptor file contains information needed to deploy the application on cloud foundry.

Example: name, memory, instances, path, env, and timeout.

Manifest file follows general YAML conventions like:

  • The manifest begins with three dashes
  • The applications block begins with a heading followed by a colon
  • The app nameis preceded by a single dash and one space
  • Subsequent lines in the block are indented two spaces to align with name

 

7. Deploying the applications into SAP BTP
The applications can be deployed into Cloud Foundry Environment via 2 ways :

7.a   via CF command line:
Login into SAP CF : cf login -a https://api.cf.eu10.hana.ondemand.com/
Enter your userid and password . Select the SubAccount and Space
Push the app via command: cf push

 

 

7.b.  via SAP BTP GUI:
Login to SAP BTP
Navigate to subaccount and space where you want to deploy the application.
Select Application -> Click on “Deploy Applications”

 

Deployed Application:

Click on the url : mynode-app.cfapps.eu10.hana.ondemand.com to launch the application.

 

File Structure :

 

package.json:

{
  "name": "mynode-app",
  "version": "1.0.0",
  "description": "simple nodejs application",
  "main": "index.js",
  "scripts": {
    "start": "node node_modules/@sap/approuter/approuter.js"
  },
  "author": "arjun.toshniwal@gmail.com",
  "license": "ISC",
  "dependencies": {
    "@sap/approuter": "^10.1.0"
  }
}

 

xs-app.json file:

{
    "welcomeFile" : "index.html",
    "authenticationMethod" : "none"
}

 

manifest.yml file:

---
applications:
  - name: mynode-app
    buildpack: nodejs_buildpack
    memory: 512M

 

index.html file:

Hello World

 

Summary:

In this blog you might have learned about approuter and how to deploy a simple nodejs application into SAP Cloud Platform (BTP) . In the next blog we will learn how to apply authentication to the applications deployed in Cloud Foundry.

All of your feedbacks will be highly appreciated!!!

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.