fix: carry conda activate.d env hooks into conda/micromamba:v2 images - #1118
fix: carry conda activate.d env hooks into conda/micromamba:v2 images#1118pinin4fjords wants to merge 3 commits into
Conversation
The v2 prod stage never runs `micromamba activate`, so a package that configures itself via an 'activate.d' hook (conda-forge's cmdstan sets CMDSTAN this way, compiler packages set CXX/CC the same way) silently lost that environment variable once the multi-stage build stopped inheriting the mamba image's activation entrypoint. Concatenate the installed activate.d scripts into one file during the build stage and source it via BASH_ENV in the prod stage/%environment, guarding nounset so scripts that reference not-yet-set vars like CONDA_PREFIX don't abort tasks run with `bash -ue`. BASH_ENV is a static image property, so it's honored under both `docker run` and `singularity exec`/`apptainer exec`, unlike ENTRYPOINT, which Singularity's exec mode never runs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…en nounset marker Address review feedback on #1118: - add a Spock test that extracts the actual generated shell fragment from the rendered v2 template and runs it under real bash, confirming exported vars survive a `bash -ue` task and that `set -u` is only restored when it was originally active - assert the Singularity `%environment` output sets BASH_ENV too, not just the Docker templates - defensively unset the __wave_nounset marker before detecting nounset state, so a stray inherited variable of the same name can't flip nounset on at the end of sourcing Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The leading `unset __wave_nounset` in the generated activate.d combiner script was a no-op: the variable is never exported, so it can't leak into the fresh bash process that sources the file via BASH_ENV. Also assert the regex match in the new real-bash-execution test instead of discarding it, and correct the test comment to note it only exercises the Dockerfile-file variant. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Thanks for the really thorough investigation here @pinin4fjords — the diagnosis is spot on, and On the framing — it's more a long-standing quirk than a v2 regression. I'd lean towards not changing the v2 default for this.
The combiner + Fair warning that this last option only helps the Docker path — Really appreciate the work — just want to make sure we land it in the right place. 🙏 |
|
Thanks @pditommaso. I don't think this should be relegated to a legacy build version, it's a current and valid feature of conda environments as far as I know, so I think Wave and Seqera Containers should support it properly with a current version. I chose this slightly hacky version specifically for the functionality across docker and singularity, having considered something along the lines of the tidier version you allude to. I don't think a solution that works only for Docker is the right call, but it's your call. V3 works for me as long as we can get that deployed to Seqera containers soonish! |
Summary
Switching the default Conda build template to
conda/micromamba:v2exposed a compatibility issue with Conda packages that rely onactivate.dscripts.The v2 template builds the Conda environment in one stage and copies it into a clean final image. Unlike the previous template, the final image does not run
micromamba activate, so the environment variables configured byactivate.dscripts are not loaded.This affects packages such as
cmdstan, which uses an activation script to setCMDSTAN, as well as compiler packages that set variables such asCCandCXX.Fix
The v2 Docker and Singularity templates now:
activate.dscripts into a single script during the build.BASH_ENVin the final image so Bash loads those settings automatically.nounsetwhile loading the scripts, since some activation scripts reference variables that may not yet be defined.This restores the activation-script behavior for both Docker and Singularity images generated from the v2 templates.
Validation
bash -ueto confirm exported variables survive andnounsetis restored correctly, rather than only asserting on the rendered template text.cmdstanand compiler environment variables are available in generated images.Fixes #1119