diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index c6e047f83..edb8d2148 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 = "/mx-buildpack/sap-hana-client" + + +def _is_sap_hana_client_enabled(): + return os.environ.get("INCLUDE_SAP_HANA_CLIENT", "").strip().lower() == "true" + + +def _get_hana_jar_name(): + 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 f"ngdbc-{resp.text.strip()}.jar" + + +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 = _get_hana_jar_name() + 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"]: diff --git a/buildpack/stage.py b/buildpack/stage.py index 2f37be179..776b4dc6e 100755 --- a/buildpack/stage.py +++ b/buildpack/stage.py @@ -217,6 +217,7 @@ def cleanup_dependency_cache(cached_dir, dependency_list): metering.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) database.stage(BUILDPACK_DIR, BUILD_DIR) runtime.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) + runtime.stage_hana_client(BUILD_DIR) logs.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) nginx.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) logging.info("Mendix Cloud Foundry Buildpack staging completed")