Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
UxKjaer
Product and Topic Expert
Product and Topic Expert
407

Welcome, 

I am by nature a bit impatient and find it very frustrating that I have to wait for several minutes for a CAP application to run using MBT and CF deploy. 

This made me look at whether there are other alternatives. MBT is a wrapper custom build by SAP to handle all deployments in one go. This is really great as it also creates services, applications etc when we run the cf deploy command. While there are certain steps we can take to run a more speedy deployments like mbt module-build and adding the ignore node_modules folders to the MTA file, i've never really been happy with it. 

If we look into the broader node community there are other options available. When we have a CAP project with apps, we are more or less dealing with a monorepo. Arguably it's a bit of both as the db and services folders are still treated as one package. But stay with me 😀

I've played around with a monorepo build system called Turborepo. This is an open source project currently mainly maintained by Vercel. This helps speed up the build time and also introduces caching to check if any files are actually changed and the package then needs rebuilding. I also switched back to cf push instead of cf deploy as this is also quicker. Please note that we aren't handling other dependent service updates like xsuaa or destinations with this approach.

I managed to get my delta deployments down to about 1.20 minutes instead of about 3.30 minutes in my sample project. And even faster when we are dealing with only an app deployment for example. Let me show you what I did. I am running this on my MacBook Pro M1.

Start by cloning the cap-sflight project.

 

git clone https://github.com/SAP-samples/cap-sflight.git

 

Go to the folder and install turborepo

 

npm i -D turbo

 

Now there is a bit of plumbing involved, so stay with me. 

Firstly let's look at the package.json file. For Turbo to work, we need to specify a package manager, so add the following line to your package.json file. Version depends on your NPM version, you can find this out by running npm -v

 

  "packageManager": "npm@10.8.1"

 

 Secondly we will add some scripts that will be run to deploy in our new improved way.

 

    "buildCDS": " npx -p /cds-dk cds build --profile production,node",
    "deploy-db": "cf push -f manifest-db.yml ",
    "deploy-app": "npm run deploy --workspace=app-deployer",
    "deploy-srv": "cf push -f manifest-srv.yml",
    "deployTurbo": "turbo run deploy-db deploy-srv app-deployer#deploy",
    "buildApps": "npm run build:cf --workspaces --if-present"

 

Create a new file called turbo.json in the root folder.

Also create two new files called

We will create a new package called app-deployer, add this to the app folder, this was necessary for me as I couldn't figure out how the HTML5 app deployer worked without using MBT 🙈 (If you can show me, i'd be happy to update the blogpost).

So create a new directory called app-deployer with command

 

mkdir app/app-deployer

 

and add the following files:

  • mta.yaml
  • package.json
  • turbo.json

See the content of the files here: https://github.com/uxkjaer/cap-sflight/tree/main/app-deployer 

Now to speed up the app builds and also make sure that the manifest.json version is updated upon deployment (This can otherwise be an issue for SAP Build Work Zone), we need to adjust the two apps in the app folder, the actions are identical though.

Update the package.json file in the UI5 app folders with the following scripts:

 

"versionbump": "npx ui5-bump patch dist/manifest.json",
"copyToGenApp": "mkdir -p ../app-deployer/gen/app/ && cp dist/*.zip ../app-deployer/gen//app/",
"postbuild": "turbo run versionbump && npm run copyToGenApp",

 

NB: Be aware if you are doing this with an existing project, you might need to adjust the scripts to be build:cf.

Also add a turbo.json file to each of the apps.

Lastly Turbo works with caching which is why it's so fast, so add the following to your .gitignore
.turbo

That is it. Job done.

Now if you make a change in the db or srv folder, this will deploy the db and srv, but not apps, if you make a change in one of the apps, it will be the opposite. Turbo will handle the caching and only run deployments, if there is an actual change.

See below gifs for examples. I have changed the playback speed here as well, just to make the videos faster

Deployment for app onlyDeployment for app only

 

Deployment for service and DBDeployment for service and DB