diff --git a/README.md b/README.md index cf0196e39..15be897e1 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,16 @@ Selection based on name `hana` and tags `["hana", "database", "relational"]`. ], ``` +#### SAP HANA Client + +To include the SAP HANA 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..a92971849 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -9,6 +9,7 @@ import time import backoff +import requests from buildpack import util from lib.m2ee import M2EE as m2ee_class from lib.m2ee.version import MXVersion @@ -56,6 +57,32 @@ def is_version_maintained(version): return True return False +def _stage_hana_client(build_dir): + enabled = os.environ.get("MXRUNTIME_IncludeSAPHanaClient", "").strip().lower() == "true" + if not enabled: + return + + cdn_prefix = util.BLOBSTORE_BUILDPACK_DEFAULT_PREFIX + "sap-hana-client" + try: + dest = os.path.join(build_dir, "model", "lib", "userlib") + util.mkdir_p(dest) + version_url = util.get_blobstore_url(f"{cdn_prefix}/version.txt") + resp = requests.get(version_url, timeout=10) + resp.raise_for_status() + jar_name = f"ngdbc-{resp.text.strip()}.jar" + jar_url = util.get_blobstore_url(f"{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...") @@ -85,6 +112,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"