Skip to content

A new workspace from docker template does not source .bashrc #10209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matifali opened this issue Oct 11, 2023 · 7 comments · Fixed by #12913
Closed

A new workspace from docker template does not source .bashrc #10209

matifali opened this issue Oct 11, 2023 · 7 comments · Fixed by #12913
Labels
s3 Bugs that confuse, annoy, or are purely cosmetic

Comments

@matifali
Copy link
Member

matifali commented Oct 11, 2023

A new workspace created from the docker template does not source .bashrc

This prevents setting env variables or paths defined in .bashrc

Coder version : v2.2.1-devel+fafecbd9b

@matifali matifali added s1 Bugs that break core workflows. Only humans may set this. bug labels Oct 11, 2023
@mafredri
Copy link
Member

Could you share more about the setup? ~/.bashrc should definitely be sourced, assuming bash is the default shell for the user.

@matifali
Copy link
Member Author

Yes. If I do echo $SHELL I see /bin/bash
And if I manually do source .bashrc my environment variables are set.

@johnstcn johnstcn added s3 Bugs that confuse, annoy, or are purely cosmetic and removed s1 Bugs that break core workflows. Only humans may set this. labels Oct 11, 2023
@johnstcn
Copy link
Member

Bash runs as a login shell by default, which means you need to have a .profile or .bash_profile. Normally you'd source .bashrc in those files.

@matifali
Copy link
Member Author

As per internal discussion, we can fix this by populating a new workspace $HOME with files from /etc/skel/ if not present already by using the startup_script

@matifali matifali changed the title web terminal does not source .bashrc A new workspace from docker template does not source .bashrc Oct 11, 2023
@github-actions github-actions bot added the stale This issue is like stale bread. label Apr 9, 2024
@MrPeacockNLB
Copy link
Contributor

We are making heavely use of scripts in our template and has to source each and everywhere the .bashrc or adding ~/bin to the path again as this wont work out of the box. It would be nice to get rid of this.

@johnstcn johnstcn removed the stale This issue is like stale bread. label Apr 9, 2024
@mafredri
Copy link
Member

mafredri commented Apr 9, 2024

@MrPeacockNLB I'd like to understand in better detail what the issue you're facing is, could you share a bit more about what you're trying to do and how you're currently achieving it?

Typically .bashrc isn't sourced for non-interactive shells (i.e. scripts). For these types of things it's better to use .profile or /etc/profile.

Alternatively, you could utilize the shebang (#!... at the top of the script) to modify how the script is being run.

Here's an example of me forcing the script to run in interactive mode (!!) and explicitly stating which rcfile to use:

resource "coder_script" "bash_test" {
  agent_id           = coder_agent.main.id
  display_name       = "Bash Test Script"
  run_on_start       = true
  script             = <<-EOS
    #!/usr/bin/env bash --rcfile ~/bashrc -i
    
    echo hello world: $ENV_FROM_BASHRC
  EOS
}

(!!) Be careful with using interactive mode as this may allow programs to prompt for input and block execution, however -i is required for the rcfile to be sourced.

Alternatively, you can use --init-file in which case -i is not required. Do keep in mind that when explicitly setting these flags, it may lead to files from /etc not being sourced (I have not verified what the behavior is).

PS. The shebang works for shells, but it's not fully featured until #10194 is merged.

@mafredri
Copy link
Member

mafredri commented Apr 9, 2024

@MrPeacockNLB alternatively, you can take a look at #12913 for how I'd solve this specific issue (#10209).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s3 Bugs that confuse, annoy, or are purely cosmetic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants