diff --git a/README.md b/README.md index cf0196e39..729a503da 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,16 @@ Selection based on name `hana` and tags `["hana", "database", "relational"]`. ], ``` +#### SAP HANA JDBC Client JAR + +To include the SAP HANA JDBC client JAR (`ngdbc.jar`) in your app's classpath at staging time, set the following environment variable: + +```shell +cf set-env MXRUNTIME_IncludeSAPHanaClient true +``` + +When enabled, the buildpack fetches the latest `ngdbc.jar` from the Mendix CDN and places it in `model/lib/userlib/`, making it available to the Mendix runtime. If the download fails, staging continues without the JAR and a warning is logged. + ### Connect an External File Store The Mendix Runtime supports multiple external file stores: AWS S3, Azure Storage and Swift (Bluemix Object Storage). diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index c6e047f83..e17a1f2e7 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -57,6 +57,44 @@ def is_version_maintained(version): return False +_SAP_HANA_CLIENT_CDN_PREFIX = util.BLOBSTORE_BUILDPACK_DEFAULT_PREFIX + "sap-hana-client" + + +def _is_sap_hana_client_enabled(): + return os.environ.get("MXRUNTIME_IncludeSAPHanaClient", "").strip().lower() == "true" + + +def _get_hana_jar_version(): + import requests as req + + version_url = util.get_blobstore_url(f"{_SAP_HANA_CLIENT_CDN_PREFIX}/version.txt") + resp = req.get(version_url, timeout=10) + resp.raise_for_status() + return resp.text.strip() + + +def _stage_hana_client(build_dir): + if not _is_sap_hana_client_enabled(): + return + + try: + dest = os.path.join(build_dir, "model", "lib", "userlib") + util.mkdir_p(dest) + jar_name = f"ngdbc-{_get_hana_jar_version()}.jar" + jar_url = util.get_blobstore_url(f"{_SAP_HANA_CLIENT_CDN_PREFIX}/{jar_name}") + util.download(jar_url, os.path.join(dest, jar_name)) + logging.info( + "SAP HANA client JAR [%s] staged to [%s]", + jar_name, + dest, + ) + except Exception: + logging.warning( + "Failed to stage SAP HANA client JAR, continuing deployment...", + exc_info=True, + ) + + def stage(buildpack_dir, build_path, cache_path): logging.debug("Creating directory structure for Mendix runtime...") for name in ["runtimes", "log", "database", "data", "bin"]: @@ -85,6 +123,7 @@ def stage(buildpack_dir, build_path, cache_path): util.set_executable(file_path) resolve_runtime_dependency(buildpack_dir, build_path, cache_path) + _stage_hana_client(build_path) FORCED_MXRUNTIME_URL_KEY = "FORCED_MXRUNTIME_URL"