Skip to content

Commit

Permalink
Source additional env vars from Renviron.site.
Browse files Browse the repository at this point in the history
This should enable R and RStudio to read dynamically created files. Part of berkeley-dsep-infra#5551.
  • Loading branch information
ryanlovett committed Feb 20, 2024
1 parent f6ef7d5 commit f40f261
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deployments/datahub/images/default/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ RUN curl --silent --location --fail ${SHINY_SERVER_URL} > /tmp/shiny-server.deb
COPY Rprofile.site /usr/lib/R/etc/Rprofile.site
# RStudio needs its own config
COPY rsession.conf /etc/rstudio/rsession.conf
# Enable customizations to Renviron.site
COPY Renviron.site.append /tmp/Renviron.site.append
RUN cat /tmp/Renviron.site.append >> /etc/R/Renviron.site && \
mkdir /etc/R/Renviron.site.d/ && \
rm /tmp/Renviron.site.append

# R_LIBS_USER is set by default in /etc/R/Renviron, which RStudio loads.
# We uncomment the default, and set what we wanna - so it picks up
Expand Down
20 changes: 20 additions & 0 deletions deployments/datahub/images/default/Renviron.site.append
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

## Source any extra Renviron files.
#
# Since there is an existing /etc/R/Renviron.site file, we append this. It lets
# us easily add new code via extraFiles (or other z2jh-related magic)
# without having to rebuild the image each time.


# Get a list of files in the directory
env_dir <- "/etc/R/Renviron.site.d/"
env_files <- list.files(env_dir, full.names = TRUE)

# Iterate over each file
for (env_file in env_files) {
cat("Loading environment variables from:", env_file, "\n")

# Read and parse the environment file
readRenviron(env_file)
}

0 comments on commit f40f261

Please sign in to comment.