This issue arises from the discussion in issue #23009.
Problem
There is an inconsistency in the environment variables, specifically the $PATH, when commands are executed during the postStart event in a Devfile. The commands do not share the same environment variables as they would if launched normally inside the workspace. This is particularly problematic when dealing with images that offer multiple shell environments, such as bash and zsh.
The postStart events are executed with /bin/sh/ by default, which does not load shell-specific configuration files like .bashrc or .zshrc, leading to missing environment variables and configurations.
Comments Summary
@AObuchow suggested that the issue might be due to the use of /bin/sh/, which does not load shell-specific configuration files. A workaround is to add a postStart event that sources the appropriate configuration file (e.g., ~/.bashrc or ~/.zshrc) to initialize the environment variables.
@eye0fra acknowledged the workaround but highlighted the challenge (parent-devfile) of managing multiple shell environments. Restoring the SHELL environment variable to ensure the correct shell is used, which is crucial for avoiding terminal issues and ensuring consistency in the workspace terminal.
Proposed Solution
Implement a mechanism to allow configuration of the shell used for postStart events, enabling users to specify whether to use bash, zsh, or another shell.
Automatically source the appropriate shell configuration file (e.g., .bashrc, .zshrc) if the specified shell supports it, ensuring that all necessary environment variables and configurations are loaded.
Provide a way to restore the SHELL environment variable to its intended value, ensuring that subsequent commands and terminal sessions use the correct shell.
Che version
7.94@latest
Steps to reproduce
Create a devfile with the following command and event:
Describe the bug
This issue arises from the discussion in issue #23009.
Problem
There is an inconsistency in the environment variables, specifically the $PATH, when commands are executed during the postStart event in a Devfile. The commands do not share the same environment variables as they would if launched normally inside the workspace. This is particularly problematic when dealing with images that offer multiple shell environments, such as bash and zsh. The postStart events are executed with /bin/sh/ by default, which does not load shell-specific configuration files like .bashrc or .zshrc, leading to missing environment variables and configurations.
Comments Summary
Proposed Solution
Che version
7.94@latest
Steps to reproduce
Create a devfile with the following command and event:
Expected behavior
PATH on the event must have the same value as the PATH env defined inside command and image component.
Runtime
OpenShift
Screenshots
Installation method
OperatorHub
Environment
other (please specify in additional context)
Eclipse Che Logs
No response
Additional context
OpenShift DevSpaces 3.16.1