-
Notifications
You must be signed in to change notification settings - Fork 87
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
Propogate environment variables into RStudio #145
Comments
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗 |
It makes sense to try to get RStudio to be aware of those environment variables. It is also logical for the rocker images to modify one of the Renviron files because the docker images are in full control of the environment. However I worry about this extension making changes to those files because it could be run outside of docker. For example it could be run on a shared HPC node. If we change a file, it'd need to be per-user and we'd have to unset the changes somehow afterwards. Using environment variables would normally be the right choice to influence app behavior and being forced to use config files is, yes, annoying. I'll look into how RStudio prepares the environment a bit more. In this case, it might be best to alter the files for the |
Thanks, makes sense, I think I followed most of this.
I was wondering if it would be possible for juypter-ression-proxy to echo-append the env vars into the user's home dir, and yeah, it's quite annoying RStudio makes us do this. |
With an image based on the Jupyter Docker Stacks, this could be done with a Startup Hook. E.g. a echo "LANG=$LANG" >>"$(R RHOME)/etc/Renviron.site"
echo "TZ=$TZ" >>"$(R RHOME)/etc/Renviron.site"
... This would also require a change of ownership and permission of chown :"$NB_GID" "$(R RHOME)/etc" "$(R RHOME)/etc/"*.site
chmod g+w "$(R RHOME)/etc" "$(R RHOME)/etc/"*.site |
@ryanlovett Is there something like Startup Hooks for binder, too? |
I think RStudio does this primarily to protect itself from weird env vars in people's desktops, and that causes issues when running serverside.
I think the primary thing to be determined is which file to modify. Ideally, this should be:
@cboettig putting anything under |
Another important use case for this is with AWS credentials (or GCP credentials). These are dynamically set at runtime on the pod, and need to be propagated for automatic detection of credentials when accessing APIs to work. So while we can set gh-scoped-creds at image build time, we can't do that for these. |
Side note: Compute Canada / Digital Research Alliance of Canada solution for this problem was to patch RStudio. Patch is available here: https://github.com/ComputeCanada/easybuild-easyconfigs-installed-avx2/blob/main/2023/RStudio-Server/rstudio-1.2.1335.patch. It is quite simple, but I have never tried to have it merged upstream. |
@yuvipanda What we ended up doing was modifying Rprofile to support sourcing files in an Rprofile.d directory, and then using |
@ryanlovett oooh, that's interesting. Is there a per-user Rprofile? If there is, perhaps we can dynamically modify that in rsession-proxy?
Alternatively, we could start with putting this kinda code in Rprofile for just the rocker/binder image, where it can simply read from |
Yes, ~/.Rprofile (and also ~/.Renviron). The modification process would have to be idempotent. Would you also want to leave the vars behind? Or assume whatever file is included gets overwritten each session? |
@ryanlovett yes, we'd have the code to be idempotent - reasonably doable I'd think ( The vars should be put on something like |
I think having something like: tmp <- tempfile()
writeLines(readBin("/proc/1/environ", "character", n = 500), tmp)
readRenviron(tmp) in |
Why not use a Startup Hook? e.g. exclude_vars="HOME LD_LIBRARY_PATH OLDPWD PATH PWD RSTUDIO_VERSION SHLVL"
for var in $(compgen -e); do
[[ ! $exclude_vars =~ $var ]] && echo "$var=${!var}" \
>> "$(R RHOME)/etc/Renviron.site"
done |
@benz0li that is specific to jupyter/docker-stacks. I'd like a more general solution here. my ideal solution is to get #145 (comment) upstreamed so rstudio will also act like most other applications :D But I don't think that's going to happen. |
@cboettig I think this Codespace devcontainer PWD behavior is related to this. The following devcontainer.json spins up a devcontainer with JupyterLab and RStudio.
In the codespace from a terminal: In JupyterLab from a terminal: In RStudio from the terminal tab In RStudio in the file panel If we change the workspaceFolder to something different than HOME
In the codespace from a terminal: In JupyterLab from a terminal: In RStudio from the terminal tab In RStudio in the file panel |
Sadly,
seems to be ignored. Setting other envs works fine but PWD is ignored. I restarted R and restarted the terminal tab. Even setting Also
didn't help (unless I typed |
@eeholmes Set Cross reference: https://github.com/b-data/data-science-devcontainers#usage |
ℹ️ Opening your codespace in JupyterLab according to the GitHub Docs sets the default path to |
@benz0li Sadly that has no effect on the terminal being opened by The devcontainer.json file is working close to what I want now.
in the postCreate command. |
@eeholmes Or simply use my/b-data's [CUDA-enabled] Data Science Dev Containers, which do not have such issues. ℹ️ Basic settings for RStudio: https://github.com/b-data/data-science-devcontainers/tree/8b25e592d7ca97cdcea7acae0c553545e48e5bd0/.devcontainer/r-base/conf/rstudio/etc |
Bug description
Annoyingly, RStudio (though not R itself) decides to ignore global system environmental variables and only recognizes those environmental variables declared in an Renviron file (i.e. either $R_HOME/etc/Renviron.site, for all users, or a .Renviron in the user's home directory). For instance, the client ID required by the awesome
gh-scoped-creds
python module would typically be passed in this way.In the rocker project, we propagate most environmental variables into R_HOME before bringing up the rserver by using the s9 init system, https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/init_set_env.sh , which obviously isn't used in a jupyterhub + jupyter-rsession-proxy setup. Would it be possible to have the jupyter-rsession-proxy do something similiar?
The text was updated successfully, but these errors were encountered: