Skip to content

Commit

Permalink
Don't hardcode ubuntu codename when getting r packages
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Jun 22, 2022
1 parent 32a3525 commit b5d5342
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions repo2docker/buildpacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def get_base_packages(self):
# Utils!
"less",
"unzip",
# Gives us envsubst
"gettext-base",
}

def get_build_env(self):
Expand Down
18 changes: 13 additions & 5 deletions repo2docker/buildpacks/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ def get_rspm_snapshot_url(self, snapshot_date, max_days_prior=7):
# Construct a snapshot URL that will give us binary packages for Ubuntu Bionic (18.04)
if "upsi" in snapshots:
return (
"https://packagemanager.rstudio.com/all/__linux__/focal/"
# Env variables here are expanded by envsubst in the Dockerfile, after sourcing
# /etc/os-release. This allows us to use distro specific variables here to get
# appropriate binary packages without having to hard code version names here.
"https://packagemanager.rstudio.com/all/__linux__/${VERSION_CODENAME}/"
+ snapshots["upsi"]
)
raise ValueError(
Expand Down Expand Up @@ -243,7 +246,10 @@ def get_devtools_snapshot_url(self):
# Hardcoded rather than dynamically determined from a date to avoid extra API calls
# Plus, we can always use packagemanager.rstudio.com here as we always install the
# necessary apt packages.
return "https://packagemanager.rstudio.com/all/__linux__/focal/2022-06-03+Y3JhbiwyOjQ1MjYyMTU7RkM5ODcwN0M"
# Env variables here are expanded by envsubst in the Dockerfile, after sourcing
# /etc/os-release. This allows us to use distro specific variables here to get
# appropriate binary packages without having to hard code version names here.
return "https://packagemanager.rstudio.com/all/__linux__/${VERSION_CODENAME}/2022-06-03+Y3JhbiwyOjQ1MjYyMTU7RkM5ODcwN0M"

def get_build_scripts(self):
"""
Expand Down Expand Up @@ -319,15 +325,17 @@ def get_build_scripts(self):
rf"""
R RHOME && \
mkdir -p /etc/rstudio && \
echo 'options(repos = c(CRAN = "{cran_mirror_url}"))' > /opt/R/{self.r_version}/lib/R/etc/Rprofile.site && \
echo 'r-cran-repos={cran_mirror_url}' > /etc/rstudio/rsession.conf
EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {cran_mirror_url} | envsubst)" && \
echo "options(repos = c(CRAN = \"${{EXPANDED_CRAN_MIRROR_URL}}\"))" > /opt/R/{self.r_version}/lib/R/etc/Rprofile.site && \
echo "r-cran-repos=${{EXPANDED_CRAN_MIRROR_URL}}" > /etc/rstudio/rsession.conf
""",
),
(
"${NB_USER}",
# Install a pinned version of devtools, IRKernel and shiny
r"""
R --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos='{devtools_cran_mirror_url}')" && \
EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {devtools_cran_mirror_url} | envsubst)" && \
R --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos='${{EXPANDED_CRAN_MIRROR_URL}}')" && \
R --quiet -e "IRkernel::installspec(prefix='$NB_PYTHON_PREFIX')"
""".format(
devtools_cran_mirror_url=self.get_devtools_snapshot_url()
Expand Down

0 comments on commit b5d5342

Please sign in to comment.