Skip to content

Test conda env activation in container-canary tests#859

Merged
rapids-bot[bot] merged 11 commits intorapidsai:mainfrom
jakirkham:use_interactive_login_bash
Mar 11, 2026
Merged

Test conda env activation in container-canary tests#859
rapids-bot[bot] merged 11 commits intorapidsai:mainfrom
jakirkham:use_interactive_login_bash

Conversation

@jakirkham
Copy link
Member

Fixes #857

For scripts like profile.sh to run (needed for Conda activation) we need to use a login shell. Hence the addition of -l (L) here.

Also interactive shells tend to behave a bit better from a user experience perspective. So have added -i too.

For scripts like `profile.sh` to run (needed for Conda activation) we
need to use a login shell. Hence the addition of `-l` (L) here.

Also interactive shells tend to behave a bit better from a user
experience perspective. So have added `-i` too.
@jakirkham jakirkham requested a review from a team as a code owner March 5, 2026 23:04
@jakirkham jakirkham requested a review from msarahan March 5, 2026 23:04
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash -il
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shellcheck doesn't like this

In context/entrypoint.sh line 1:
#!/usr/bin/env bash -il
^---------------------^ SC2096 (error): On most OS, shebangs can only specify a single parameter.

However in this instance shellcheck is wrong. We make use of this regularly in conda-forge

Will silence this shellcheck error

Copy link
Member

@jacobtomlinson jacobtomlinson Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? When I try and do this on my Ubuntu 24.04 desktop I get an error

#!/usr/bin/env bash -il
echo "Hello world"
$ chmod +x script.sh
$ ./script.sh
/usr/bin/env: ‘bash -il’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

I also see the same when doing this with a container entrypoint.

$ ls
Dockerfile  entrypoint.sh

entrypoint.sh

#!/usr/bin/env bash -il
exec $@

Dockerfile

FROM ubuntu

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT /entrypoint.sh

CMD "echo 'hello hello'"
$ docker build -t jacobtomlinson/foocont:latest .
[+] Building 0.1s (7/7) FINISHED
$ docker run jacobtomlinson/foocont:latest
/usr/bin/env: 'bash -il': No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

Copy link
Contributor

@gforsyth gforsyth Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to an underspecified portion of the POSIX spec! There are no answers! (There are some answers)

Everything after the first word (space delimited) of the shebang gets parsed as a single argument and that handling can be kernel-dependent (yayyyy!!!!)

I think the more reliable but slightly less portable solution is to ensure that you are using a sufficiently new coreutils (can't remember the version) and then env supports the -S flag to explicitly allow multiple arguments and then you can do

#!/usr/bin/env -S bash -il

More references and examples here: https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#g_t_002dS_002f_002d_002dsplit_002dstring-usage-in-scripts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add -S does shellcheck still complain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Gil! 🙏

Looks like coreutils version 8.30 added env -S

It quick run with shellcheck looks promising. Will see what CI says

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done in PR: #860

Passing `-il` works fine with `bash` in the shebang.

Disable shellcheck warning related to this.
@jakirkham jakirkham added bug Something isn't working non-breaking labels Mar 5, 2026
Copy link
Member

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for starting this, it's an interesting approach to the environment-activation problem. I'm leaving a blocking review because I have some concerns.

# Shellcheck doesn't like multiple options to the shell in the shebang.
# However this works fine in practice. So disable this shellcheck error.
#
# shellcheck disable=SC2096
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just picking a different point here to not complicate the thread above the spelling of the arguments.... I don't think we want an interactive shell.

The rapidsai/base images are intended to also be useful for non-interactive processes, like model inference in this example: https://docs.rapids.ai/deployment/stable/examples/rapids-sagemaker-higgs/notebook/#testing-your-amazon-sagemaker-compatible-rapids-container-locally

Unless we can clearly state how adding -i resolves a specific issue, I think that part should be reverted out of this.

Making the entrypoint run these commands via a login shell is fine, but I think we should add some kind of tests in https://github.com/rapidsai/docker/tree/main/tests/container-canary confirming some observable properties of this so we don't accidentally introduce a regression in the future. For example, if the goal of the login shell is to activate the base conda environment, let's add a container canary test that that environment is activated by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks James! 🙏

I don't have strong feelings about -i interactive. So have dropped it. Happy to pursue independently

Have added a test below. Would be interested in your feedback on that

Comment on lines +32 to +39
- name: tst-conda-active
description: test the conda environment is active
probe:
exec:
command:
- /bin/bash
- -c
- '[ "${CONDA_EXE+x}" ];'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameslamb is this what you had in mind for a test?

Basically CONDA_EXE is only set if the Conda environment is active. If the shell we are running here is run under a login shell (so we went through the entrypoint script), then CONDA_EXE will be set and inherited by this shell

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep perfect! Exactly the type of thing I was looking for.

@jayavenkatesh19 is adding similar tests in #860 too, I'm fine with all of them existing. More validation that the image looks like we expect to it good.

Copy link
Member

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, I'm good with this as a way to help with the startup environment for interactive uses.

I think we will want both this AND #860 (which fixes the problem generally for non-interactive use too).

@jakirkham jakirkham changed the title Use an interactive login shell for entrypoint Use a login shell for entrypoint Mar 6, 2026
@jakirkham jakirkham changed the title Use a login shell for entrypoint Use a login shell for the entrypoint Mar 6, 2026
@jakirkham jakirkham changed the title Use a login shell for the entrypoint Use a login shell for the entrypoint script Mar 6, 2026
@jameslamb jameslamb changed the title Use a login shell for the entrypoint script Test conda env activation in container-canary tests Mar 10, 2026
@jameslamb
Copy link
Member

#860 (now merged) pulled in the login-shell changes, so this now only contains an additional test on activation. I've updated the description accordingly.

@jameslamb
Copy link
Member

/merge

@rapids-bot rapids-bot bot merged commit b1f3e18 into rapidsai:main Mar 11, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] nightly CI failing: conda prefix not found

4 participants