diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-06-17 16:24:22 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-06-17 16:24:22 -0400 |
| commit | b9cac8cfa9a0ef9138b860c2fa72c6fe51331adf (patch) | |
| tree | 7ce0503558ede6daf97bc8f6372b638a3a930d50 | |
| parent | 252b9646c1cb0538123d51ced4a733f3dcfc266b (diff) | |
| download | stasis-b9cac8cfa9a0ef9138b860c2fa72c6fe51331adf.tar.gz | |
Update micromamba installation logic
* Split installation from micromamba() into micromamba_install()
* Return -1 when micromamba cannot be installed
* Add stasis.ini option "indexer.micromamba_download_url"
* Add global variable micromamba_download_url
* The installation function attempts two known-good URLs by default
*
| -rw-r--r-- | src/cli/stasis_indexer/helpers.c | 5 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer_main.c | 17 | ||||
| -rw-r--r-- | src/lib/core/conda.c | 69 | ||||
| -rw-r--r-- | src/lib/core/globals.c | 1 | ||||
| -rw-r--r-- | src/lib/core/include/conda.h | 9 | ||||
| -rw-r--r-- | src/lib/core/include/core.h | 1 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_populate.c | 5 | ||||
| -rw-r--r-- | stasis.ini | 9 |
8 files changed, 104 insertions, 12 deletions
diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index 3ef96e4..bdb538d 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -172,6 +172,11 @@ int micromamba_configure(const struct Delivery *ctx, struct MicromambaInfo *m) { setenv("PATH", pathvar, 1); guard_free(pathvar); + if (micromamba_install(m)) { + SYSERROR("Micromamba installation failed"); + return -1; + } + status += micromamba(m, "config prepend --env channels conda-forge"); if (!globals.verbose) { status += micromamba(m, "config set --env quiet true"); diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c index 45bbb6c..c13d175 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -309,6 +309,23 @@ int main(const int argc, char *argv[]) { printf(BANNER, version, AUTHOR); guard_free(version); + char *cfg_path = NULL; + if (asprintf(&cfg_path, "%s/stasis.ini", globals.sysconfdir) < 0) { + SYSERROR("Unable to allocate memory for cfg path"); + exit(1); + } + ctx._stasis_ini_fp.cfg_path = cfg_path; + ctx._stasis_ini_fp.cfg = ini_open(ctx._stasis_ini_fp.cfg_path); + if (ctx._stasis_ini_fp.cfg) { + if (populate_delivery_cfg(&ctx, INI_READ_RENDER)) { + SYSERROR("Unable to apply stasis configuration"); + exit(1); + } + } + else { + SYSWARN("Unable to open stasis configuration file: %s", cfg_path); + } + indexer_init_dirs(&ctx, workdir); msg(STASIS_MSG_L1, "%s delivery root %s\n", diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index c9eb750..444cfaa 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -5,7 +5,11 @@ #include "conda.h" #include "version_compare.h" -int micromamba(const struct MicromambaInfo *info, char *command, ...) { +int micromamba_install(const struct MicromambaInfo *info) { + if (access(info->micromamba_prefix, F_OK) == 0) { + SYSINFO("micromamba already installed: %s", info->micromamba_prefix); + return 0; + } struct utsname sys; uname(&sys); @@ -28,23 +32,54 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { return -1; } - char url[PATH_MAX] = {0}; - snprintf(url, sizeof(url), "https://micro.mamba.pm/api/micromamba/%s-%s/latest", sys.sysname, sys.machine); + // If we ever want an exact version instead of "latest", we need to use this format instead: + // https://github.com/mamba-org/micromamba-releases/releases/download/${version}/micromamba-${arch} - const char installer_name[] = "mm_latest"; + // Micromamba hosts binaries on github and on their own website. Prefer github. + const char *url_fmts[] = { + info->download_url, + "https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-%s-%s", + "https://micro.mamba.pm/api/micromamba/%s-%s/latest", + }; + const size_t url_fmts_max = sizeof(url_fmts) / sizeof(url_fmts[0]); + + char url[PATH_MAX] = {0}; char installer_path[PATH_MAX] = {0}; - snprintf(installer_path, sizeof(installer_path), "%s/%s", info->download_dir, installer_name); + const char *installer_name = "mm_latest"; + + size_t fail_count = 0; + for (size_t url_i = 0; url_i < url_fmts_max; url_i++) { + if (url_i == 0 && info->download_url) { + // If the caller supplies a download_url, use it + snprintf(url, sizeof(url), "%s", info->download_url); + } else if (url_i == 0 && isempty(info->download_url)) { + // No download_url has been defined, or is an empty string + continue; + } else { + snprintf(url, sizeof(url), url_fmts[url_i], sys.sysname, sys.machine); + } - if (access(installer_path, F_OK)) { - char *errmsg = NULL; - const long http_code = download(url, installer_path, &errmsg); - if (HTTP_ERROR(http_code)) { - SYSERROR("download failed: %ld: %s", http_code, errmsg); - guard_free(errmsg); - return -1; + snprintf(installer_path, sizeof(installer_path), "%s/%s", info->download_dir, installer_name); + + if (access(installer_path, F_OK)) { + char *errmsg = NULL; + const long http_code = download(url, installer_path, &errmsg); + if (HTTP_ERROR(http_code)) { + SYSERROR("download failed: %ld: %s", http_code, errmsg); + guard_free(errmsg); + remove(installer_path); + fail_count++; + continue; + } + break; } } + if (fail_count >= url_fmts_max) { + SYSERROR("all download attempts failed"); + return -1; + } + char mmbin[PATH_MAX]; snprintf(mmbin, sizeof(mmbin), "%s/micromamba", info->micromamba_prefix); @@ -59,6 +94,16 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { return -1; } } + return 0; +} + +int micromamba(const struct MicromambaInfo *info, char *command, ...) { + char mmbin[PATH_MAX] = {0}; + snprintf(mmbin, sizeof(mmbin), "%s/micromamba", info->micromamba_prefix); + if (access(mmbin, F_OK) < 0) { + SYSERROR("Unable to run micromamba. Not installed?"); + return -1; + } char cmd[STASIS_BUFSIZ] = {0}; va_list args; diff --git a/src/lib/core/globals.c b/src/lib/core/globals.c index b84213e..7eb1beb 100644 --- a/src/lib/core/globals.c +++ b/src/lib/core/globals.c @@ -29,6 +29,7 @@ struct STASIS_GLOBAL globals = { .verbose = false, ///< Toggle verbose mode .continue_on_error = false, ///< Do not stop program on error .always_update_base_environment = false, ///< Run "conda update --all" after installing Conda + .micromamba_download_url = NULL, .conda_fresh_start = true, ///< Remove/reinstall Conda at startup .conda_install_prefix = NULL, ///< Path to install Conda .conda_packages = NULL, ///< Conda packages to install diff --git a/src/lib/core/include/conda.h b/src/lib/core/include/conda.h index cc9426d..a7108ec 100644 --- a/src/lib/core/include/conda.h +++ b/src/lib/core/include/conda.h @@ -30,9 +30,18 @@ struct MicromambaInfo { char *micromamba_prefix; //!< Path to write micromamba binary char *conda_prefix; //!< Path to install conda base tree char *download_dir; //!< Path to store micromamba installer + char *download_url; //!< Raw URL to a remotely hosted micromamba-platform-arch file }; /** + * Download and install Micromamba + * + * @param info MicromambaInfo data structure (must be populated before use) + * @return 0 on successful installation + */ +int micromamba_install(const struct MicromambaInfo *info); + +/** * Execute micromamba * @param info MicromambaInfo data structure (must be populated before use) * @param command printf-style formatter string diff --git a/src/lib/core/include/core.h b/src/lib/core/include/core.h index 9a2007c..ed523be 100644 --- a/src/lib/core/include/core.h +++ b/src/lib/core/include/core.h @@ -35,6 +35,7 @@ struct STASIS_GLOBAL { bool verbose; //!< Enable verbose output bool always_update_base_environment; //!< Update base environment immediately after activation bool continue_on_error; //!< Do not stop on test failures + char *micromamba_download_url; //!< Override download URL for micromamba bool conda_fresh_start; //!< Always install a new copy of Conda bool enable_docker; //!< Enable docker image builds bool enable_artifactory; //!< Enable artifactory uploads diff --git a/src/lib/delivery/delivery_populate.c b/src/lib/delivery/delivery_populate.c index cfa3da2..5ce11d7 100644 --- a/src/lib/delivery/delivery_populate.c +++ b/src/lib/delivery/delivery_populate.c @@ -99,6 +99,11 @@ int populate_delivery_cfg(struct Delivery *ctx, int render_mode) { } err = 0; + if (!globals.micromamba_download_url) { + globals.micromamba_download_url = ini_getval_str(cfg, "indexer", "micromamba_download_url", render_mode, &err); + } + + err = 0; if (!globals.wheel_builder_manylinux_image) { globals.wheel_builder_manylinux_image = ini_getval_str(cfg, "default", "wheel_builder_manylinux_image", render_mode, &err); } @@ -35,6 +35,15 @@ wheel_builder = manylinux ; When wheel_builder is set to "manylinux", use the following image wheel_builder_manylinux_image = quay.io/pypa/manylinux2014 + +;[indexer] +; (string) Micromamba download URL +; DEFAULT: GitHub or Micromamba's primary website URLs are used +; NOTE: +; - The platform and architecture combination must be handled by the user +;micromamba_download_url = https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-PLAT-ARCH + + [jfrog_cli_download] url = https://releases.jfrog.io/artifactory product = jfrog-cli |
