Skip to content
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

How to use environment variables XDG_CONFIG_HOME, etc. in rocker/rstudio ? #103

Open
eitsupi opened this issue Jan 24, 2021 · 9 comments
Open
Labels
enhancement New feature or request

Comments

@eitsupi
Copy link
Member

eitsupi commented Jan 24, 2021

According to the release notes, the new RStudio v1.4 adds new environment variables XDG_CONFIG_HOME to customize the location of the user data folder (default : /home/rstudio/.config/rstudio) .

https://docs.rstudio.com/ide/server-pro/server-management.html#configure-service

How can I set up these variables in rocker?

@eitsupi eitsupi changed the title How can I use new environment variables (RSTUDIO_DATA_HOME, etc.) in rocker ? How can I use new environment variables for RStudio (RSTUDIO_DATA_HOME, etc.) in rocker ? Jan 24, 2021
@eitsupi eitsupi changed the title How can I use new environment variables for RStudio (RSTUDIO_DATA_HOME, etc.) in rocker ? How can I use new environment variables for RStudio (XDG_CONFIG_HOME, etc.) in rocker ? Jan 31, 2021
@eitsupi
Copy link
Member Author

eitsupi commented Jan 31, 2021

If I set the XDG_CONFIG_HOME to a custom place in .Renviron file, the global settings file rstudio-prefs.json is not moved.

It seems that I need to load XDG_CONFIG_HOME before starting RStudio, but I couldn't figure out how to set the environment variables for the service in the container.
https://community.rstudio.com/t/rstudio-prefs-json-in-a-custom-location/80556

I tried to set up XDG_CONFIG_HOME using the following procedure, but it seems not to work.
https://github.com/just-containers/s6-overlay#container-environment

@Pit-Storm
Copy link
Contributor

Hi @eitsupi,

I reviewed the manual and with the background of your issue, you want to move the user specific rstudio-prefs.json file.

I think your Issue is related to #170 and is better understandable when reading Section 5.2 of the RStudio Server Manual.

The Problem is, that the community Edition of RStudio Server is not inheriting any bash env var from the context it launches from. So in the issue I linked, I am working on a pullrequest for solving this issue with dynamic ENV Vars on container startup.

After the work is done, you would be able to set the ENV-Vars dynamically on container startup. In the meantime you can write the env vars to Rprofile.site with Sys.setenv() on your own Dockerfile.

Hopefully that helps and kind regards.

@eitsupi
Copy link
Member Author

eitsupi commented Jun 26, 2021

Unfortunately, the situation doesn't seem to have changed in the images after #186 and #190.

@cboettig
Copy link
Member

@eitsupi I believe we load env vars from /etc/environment before calling the RStudio run script in S6:

https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_rstudio.sh#L96-L99

I think it might work either to link a file to /etc/environment that has the env var populated, or else we can modify that script to also load the dynamic env vars from /var/run/s6/container_environment/ as well as from /etc/environment?

@eitsupi
Copy link
Member Author

eitsupi commented Jul 18, 2021

@cboettig Thank you.
When I wrote like XDG_CONFIG_HOME=/home/rstudio/changeddir in /etc/environment, it did indeed change the directory, and I was able to use rstudio-prefs.json in the changed directory.
I was also able to get the env with Sys.getenv function in R in RStudio.

My need was to make the RStudio configuration file persistent.
After raising this issue, I thought that the method of bind-mounting /home/rstudio/.config/rstudio folder was sufficient, so I currently have the following setup. (When using docker-compose)

version: "3"
services:
    rstudio:
        image: rocker/rstudio
        environment:
            - PASSWORD=foobar
        ports:
            - "8787:8787"
        volumes:
            - ./.rstudio_config:/home/rstudio/.config/rstudio

It is a little troublesome to add values to /etc/environment, which is owned by root and has values written in from the beginning, and RSTUDIO_CONFIG_DIR, which is supposed to move only RStudio server settings, does not work unlike XDG_CONFIG_HOME (RSTUDIO_CONFIG_DIR only work with RStudio Workbench?).
In the end, bind-mounting /home/rstudio/.config/rstudio seems to suit my needs.

After some testing, I found that not all environment variables in /etc/environment can be used in RStudio, and the implementation of #190 seems to be better for other environment variables. I think the current implementation is fine.

@myoung3 Did the method of writing to /etc/environment solve your problem?

@myoung3
Copy link
Contributor

myoung3 commented Jul 18, 2021

@eitsupi Not quite. I was successfully able to write to /etc/environment. I'm running singularity and don't have root, so this means building a new .sif with a definition file that has a base rocker image. This seems to be the only way since during (remote) build is the only time I get root access to the image. Not ideal but it works well enough. I then bind temporary local directories to the in-image directories specified for XDG_CONFIG_HOME and XDG_DATA_HOME.

binding is definitely working correctly (files created in the bound directory are visible in both the container and locally) and writing to /etc/environment in the image during build is definitely working, but rstudio doesn't seem to be detecting these environment variables.

> Sys.getenv("XDG_CONFIG_HOME")
[1] ""

This is the command I'm using to start rstudio server if it makes any difference:

rserver --auth-none=0 --auth-pam-helper-path=pam-helper --www-port=${RAND_PORT}

@myoung3
Copy link
Contributor

myoung3 commented Jul 18, 2021

wow I just found a much easier solution that doesn't involve writing to /etc/environment

from within the singularity instance, I just need to run:

s6-env XDG_DATA_HOME=<newdir> XDG_CONFIG_HOME=<newdir2> rserver --auth-none=0 --auth-pam-helper-path=pam-helper --www-port=${RAND_PORT}

"s6-env prints the current environment or modifies the environment before running a program."
https://skarnet.org/software/s6-portable-utils/s6-env.html

@eitsupi eitsupi changed the title How can I use new environment variables for RStudio (XDG_CONFIG_HOME, etc.) in rocker ? How to use environment variables XDG_CONFIG_HOME, etc. in rocker/rstudio ? Jul 18, 2021
@cboettig
Copy link
Member

Thanks @myoung3 , that's great.

I still think we should probably modify the script so that we pick up any system env vars instead of adding to /etc/environment (iirc we went with /etc/environment since in the early days of docker passing env vars with -e didn't persist over restarts or something?) I think that would make it easier. thoughts?

@myoung3
Copy link
Contributor

myoung3 commented Jul 19, 2021

Yeah I'm not sure what the right way to modify the rocker source code to make it easier for rocker users to alter environmental variables of rserver, I was mostly documenting my solution to give people options if they stumble across this issue.

With that said, the rstudio server docs do recommend using whatever init system is installed:

If your Linux distribution does not use the systemd init system, consult the documentation for your Linux distribution to learn which init system it uses and the appropriate method for setting environment variables for the rstudio-server service.

-rstudio server docs

I don't really understand init systems, environmental variables, etc well enough to have a good sense of why this is their recommendation (as opposed to making it so rserver picks up all system env variables). I also don't understand why it didn't work when I wrote to /etc/environment, or what the difference is between the rserver and rstudio-server programs. Hah, so I guess I'm saying I don't really have much of an opinion. Mostly just glad that I found a solution that works for my slightly niche singularity setup in the meantime. I'll be happy to test any dev images related to this issue on my setup though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants