XSA Python Buildpack and MTA Example
Update: HANA2 SP03 now ships with a working python buildpack which renders this blog post useless unless you’re looking for an example as a basis for creating buildpacks for other languages.
While the HANA documentation gives some guidance as to how to create your own buildpacks to support custom run-time environments, to date there hasn’t been a stand-alone example that illustrates the concept in action. This post intends to fill the gap for developers wishing to use the python programming language as a component to their HANA XS-A(on-prem) and SAP Cloud Foundry Cloud Platform(SAP CFCP) development scenarios.
This post refers to the HANA XS Advanced on-premise python buildpack that can be found at:
From the repo’s README:
This Buildpack adds support for modules based on Python code to a HANA XS Advanced system. If you want to deploy your Python to a Cloud Foundry based multi-tenant system such as SAP Cloud Foundry Cloud Platform or Pivotal Cloud Foundry, this buildpack WILL NOT WORK! For those Cloud Foundry based deployment environments, use the community Python Buildpack documented at CloudFoundry.org Python Buildpack.
Now that the disclaimer is out of the way, let’s discuss the current gap (as of the writing of this post).
By providing an on-premise python buildpack, both environments have parity in terms of language support and underlying services for cases where these are the main requirements. Applications built using the on-premise MTA tooling can be then deployed also into the SAP CFCP environment without modification….Deploy Nirvana.
The hitch is that the SAP CFCP doesn’t currently include any developer tooling for creating an MTA from scratch while the HANA on-prem solution does. The good news is that a developer version of the HANA on-prem system is freely available as HANA Express and can be downloaded from here.
The rest of this post will focus on the details of the python buildpack itself and leave the exercise of deploying to SAP CFCP for another post.
The first thing to do is to find a HANA on-prem system (HANA Express or otherwise) and log into the WebIDE. This by default is running on port 53075 if your installation is in port mapping mode.
Using the Git->Clone Repository feature, pull this repo into the WebIDE using https(not ssh).
You should follow the repo’s README.md file for detailed steps as it will be more up to date that this post, but the general flow of steps you should follow are these.
- Build the db module so that the hdi-container is created.
- Create a service-instance of the xsuaa for this example app.
- Build and run the js module which provides and example of using ODATA to access the hdi-container and a target for the app-router.
- Build and run the web module to provide an app-router and handle authorizations.
- Test that the application runs and can access the js module features.
- Clone the same repo in a location where you can run the XS CLI program.
- Change into the tools directory and run the create_my_python_buildpack.sh script and follow it’s instructions for installing the python buildpack into your system.
- Change back to the main directory and run the tools/build.sh script to perform the steps needed to build the python module and remap the app-router as the python module’s port may change between builds.
- Test the application again, this time exercising the python module and verifying that the request is validated and that database can be accessed.
From this point you have a functional example using python in a module. In order to deploy your project into SAP CFCP, you will need to build a complete MTAR file and use the “cf deploy” command. The details of this are outside the scope of this post, but it is possible and a good use case for continuous integration.
In the future the WebIDE should be extended such that the build steps for python modules can be triggered from within the WebIDE, but today this isn’t the case.
The same dilemma exists for any other programming language (PHP, Ruby, Swift, Go, Erlang, Modula2, Lisp, etc.). Until there is buildpack support for these languages and the WebIDE can accommodate the build process required for each, there will be a need to handle the assembly and deployment of such scenarios manually.
Please see the buildpack repo for details and understand that this is an experimental buildpack and as such is NOT supported by SAP directly so please post any questions to the SAP Community Network.
If you will be attending TechEd in 2017 in Las Vegas, please join my session on this topic.
HDB100 – SAP HANA Extended Application Services and BYOL (Bring Your Own Language)