Skip to content

Commit 8cce33c

Browse files
authored
Merge pull request #240 from nmfs-opensci/test
rm jupyter-ai, set ubuntu to jammy not nobel, upgrade to 4.4.2, gh-scoped-creds in RStudio terminal
2 parents fede1fd + c802570 commit 8cce33c

5 files changed

Lines changed: 68 additions & 20 deletions

File tree

Dockerfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ FROM ghcr.io/nmfs-opensci/py-rocket-base/base-image:latest
33
LABEL org.opencontainers.image.maintainers="eli.holmes@noaa.gov"
44
LABEL org.opencontainers.image.author="eli.holmes@noaa.gov"
55
LABEL org.opencontainers.image.source=https://github.com/nmfs-opensci/py-rocket-base
6-
LABEL org.opencontainers.image.description="Python (3.12), R (4.4.1), Desktop and Publishing tools"
6+
LABEL org.opencontainers.image.description="Python (3.12), R (4.4.2), Desktop and Publishing tools"
77
LABEL org.opencontainers.image.licenses=Apache2.0
8-
LABEL org.opencontainers.image.version=2025.02.19
8+
LABEL org.opencontainers.image.version=2025.03.03
99

1010
USER root
1111

1212
# Define environment variables
1313
# DISPLAY Tell applications where to open desktop apps - this allows notebooks to pop open GUIs
14+
# Set QUARTO_VERSION due to Jupyter Lab bug with version 1.6 that won't all qmd to open
1415
ENV REPO_DIR="/srv/repo" \
1516
DISPLAY=":1.0" \
16-
R_VERSION="4.4.1" \
17-
QUARTO_VERSION="1.5.57"
18-
# The latest rocker will set CRAN to 'latest' but we need a date stamped version for reproducibility
19-
# So pull the latest and use one earlier
20-
ARG R_VERSION_PULL="4.4.2"
17+
R_VERSION="4.4.2" \
18+
QUARTO_VERSION="1.5.57" \
19+
UBUNTU_VERSION="jammy"
2120
ENV LANG=en_US.UTF-8
2221
ENV LC_ALL=en_US.UTF-8
2322

@@ -47,7 +46,10 @@ RUN mkdir -p /pyrocket_scripts && \
4746
RUN /pyrocket_scripts/install-conda-packages.sh ${REPO_DIR}/environment.yml
4847

4948
# Install R, RStudio via Rocker scripts. Requires the prefix for a rocker Dockerfile
50-
RUN R_VERSION_PULL=$R_VERSION_PULL /pyrocket_scripts/install-rocker.sh "verse_${R_VERSION}"
49+
# Set the R_VERSION_PULL variable to specify what branch or release. If need to use a release use
50+
# R_VERSION_PULL="R4.3.3" for example; R_VERSION_PULL="master" is getting the current master branch
51+
# Be aware that if R_VERSION_PULL is set to the latest release, CRAN repo will use "latest" and date will not be pinned.
52+
RUN R_VERSION_PULL="master" /pyrocket_scripts/install-rocker.sh "verse_${R_VERSION}"
5153

5254
# Install Zotero; must be run before apt since zotero apt install requires this is run first
5355
RUN wget -qO- https://raw.githubusercontent.com/retorquere/zotero-deb/master/install.sh | bash
@@ -83,8 +85,9 @@ RUN mkdir -p ${XDG_CONFIG_HOME} && \
8385
# Fix home permissions. Not needed in JupyterHub with persistent memory but needed if not used in that context
8486
RUN /pyrocket_scripts/fix-home-permissions.sh
8587

86-
# Create a symlink for python to python3 for all users
88+
# Create a symlink for python to python3 and gh-scoped-creds for all users; need for RStudio sinc conda not on path
8789
RUN ln -s /usr/bin/python3 /usr/local/bin/python
90+
RUN ln -s /srv/conda/envs/notebook/bin/gh-scoped-creds /usr/local/bin/gh-scoped-creds
8891

8992
# Set up the start command
9093
USER ${NB_USER}

book/r-packages.qmd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ There are a few ways to get around this.
3131

3232
### Default CRAN repository
3333

34-
The default CRAN repository is set in ${R_HOME}/etc/Rprofile.site and the CRAN environmental variable to
34+
The default CRAN repository is set in `${R_HOME}/etc/Rprofile.site` and the CRAN environmental variable is set to the date pinned version associated with the R version in the image. For example, `https://p3m.dev/cran/__linux__/jammy/2024-10-30`.
35+
36+
To set a different repo, edit `${R_HOME}/etc/Rprofile.site` if you are changing an image or `~/.Rprofile` if setting user defaults:
3537
```markdown
36-
https://p3m.dev/cran/__linux__/jammy/latest
38+
options(repos = c(CRAN = 'https://p3m.dev/cran/__linux__/jammy/latest'), download.file.method = 'libcurl')
3739
```
38-
39-
To set a different repo, edit ${R_HOME}/etc/Rprofile.site or specify the repo to use in `install.packages()` like so
40+
You can also specify the repo to use in `install.packages()` like so
4041
```markdown
41-
repo <- "https://p3m.dev/cran/__linux__/jammy/2024-05-13"
42+
repo <- "https://p3m.dev/cran/__linux__/jammy/latest"
4243
list.of.packages <- c("maps", "mapdata", "RColorBrewer")
4344
install.packages(list.of.packages, repos=repo)
4445
```

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies:
2626

2727
# Extra Jupyter tools
2828
- jupyterlab-git
29-
- jupyter-ai
29+
#- jupyter-ai
3030
- jupyter-book
3131
- jupyter-offlinenotebook
3232
- jupyter-sshd-proxy

scripts/install-rocker.sh

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ R_DOCKERFILE="$1"
3434
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
3535

3636
# Copy in the rocker files. Work in ${REPO_DIR} to make sure I don't clobber anything
37-
# R_VERSION_PULL may be different than R_VERSION. Specifically pulling latest but using R_VERSION prior to latest
38-
# So that CRAN repo is pinned to a date.
3937
cd ${REPO_DIR}
4038
ROCKER_DOCKERFILE_NAME="${R_DOCKERFILE}.Dockerfile"
41-
# Pull a tag (release) or pull the latest master (stable)
42-
# TAR_NAME="R${R_VERSION_PULL}"
43-
TAR_NAME="master"
39+
# Pull a tag (release) or pull the latest master (stable); R_VERSION_PULL is defined in Dockerfile when this script is called.
40+
TAR_NAME=${R_VERSION_PULL}
4441
# For degugging use: wget https://github.com/eeholmes/rocker-versioned2/archive/refs/tags/R4.4.1.tar.gz
4542
# wget https://github.com/rocker-org/rocker-versioned2/archive/refs/tags/R${R_VERSION_PULL}.tar.gz
4643
if [[ "$TAR_NAME" == "master" ]]; then
@@ -63,9 +60,15 @@ cmd=""
6360
while IFS= read -r line; do
6461
if [[ "$line" == ENV* ]]; then
6562
var_assignment=$(echo "$line" | sed 's/^ENV //g')
63+
# Special handling for CRAN
64+
if [[ "$var_assignment" =~ ^CRAN=.*__linux__/([^/]+)/(.+)$ ]]; then
65+
var_assignment="CRAN=https://p3m.dev/cran/__linux__/${UBUNTU_VERSION}/${BASH_REMATCH[2]//\"/}"
66+
fi
67+
# Special handling for DEFAULT_USER
6668
if [[ "$var_assignment" == DEFAULT_USER* ]]; then
6769
var_assignment="DEFAULT_USER=${NB_USER}"
6870
fi
71+
echo "Processed ENV variable: $var_assignment"
6972
eval "export $var_assignment"
7073
echo "export $var_assignment" >> "${REPO_DIR}/env.txt"
7174

@@ -100,3 +103,35 @@ if command -v tlmgr &> /dev/null; then
100103
tlmgr install collection-latexrecommended
101104
tlmgr install pdfcol tcolorbox eurosym upquote adjustbox titling enumitem ulem soul rsfs
102105
fi
106+
107+
# Make sure the env vars set in the rocker Dockerfile are in Renviron.site
108+
ENV_FILE="${REPO_DIR}/env.txt"
109+
RENVIRO_SITE="${R_HOME}/etc/Renviron.site"
110+
111+
# Ensure the file exists before processing
112+
if [[ -f "$ENV_FILE" ]]; then
113+
echo "Appending environment variables from $ENV_FILE to $RENVIRO_SITE..."
114+
115+
awk -F '=' '
116+
/^export / {
117+
gsub(/"/, "", $2); # Remove double quotes around values
118+
if ($1 ~ /PATH/) {
119+
print substr($1, 8) "=\"" ENVIRON["PATH"] ":" $2 "\""
120+
} else {
121+
print substr($1, 8) "=\"" $2 "\""
122+
}
123+
}' "$ENV_FILE" > "$RENVIRO_SITE"
124+
125+
echo "Done."
126+
else
127+
echo "Warning: $ENV_FILE not found. No changes made."
128+
fi
129+
130+
# Ensure jovyan can modify Rprofile.site and Renviron.site because start will need to this
131+
# to set the gh-scoped-cred variables if they are present
132+
chown ${NB_USER}:staff ${R_HOME}/etc/Rprofile.site
133+
chmod g+w ${R_HOME}/etc/Rprofile.site
134+
chown ${NB_USER}:staff ${R_HOME}/etc/Renviron.site
135+
chmod g+w ${R_HOME}/etc/Renviron.site
136+
137+
echo "Updated permissions for Rprofile.site and Renviron.site"

start

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ if [ -f "${REPO_DIR}/env.txt" ]; then
1111
fi
1212
# End - Set any environment variables here
1313

14+
# check for gh-scoped-creds needed variables so that can use this in RStudio
15+
# These are based on Jupyter Hub config so will not know before server starts what these are.
16+
for var in GH_SCOPED_CREDS_CLIENT_ID GH_SCOPED_CREDS_APP_URL; do
17+
if [[ -n "${!var:-}" ]]; then
18+
echo "${var}=\"${!var}\"" >> "${R_HOME}/etc/Renviron.site"
19+
echo "Added ${var} to Renviron.site"
20+
fi
21+
done
22+
1423
# Run child start scripts in a subshell to contain its environment
1524
# ${REPO_DIR}/childstart/ is created by setup-start.sh
1625
if [ -d "${REPO_DIR}/childstart/" ]; then

0 commit comments

Comments
 (0)