Skip to content
38 changes: 38 additions & 0 deletions buildpack/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
1 change: 1 addition & 0 deletions buildpack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down