Move more R config to the build phase
MODIFY
repo2docker/buildpacks/r.py
repo2docker/buildpacks/r.py
@@ -158,6 +158,9 @@ class RBuildPack(PythonBuildPack):
- IRKernel
- nbrsessionproxy (to access RStudio via Jupyter Notebook)
- stencila R package (if Stencila document with R code chunks detected)
+
+ We set the snapshot date used to install R libraries from based on the
+ contents of runtime.txt.
"""
rstudio_url = "https://download2.rstudio.org/rstudio-server-1.1.419-amd64.deb"
# This is MD5, because that is what RStudio download page provides!
@@ -173,6 +176,10 @@ class RBuildPack(PythonBuildPack):
# IRKernel version - specified as a tag in the IRKernel repository
irkernel_version = "0.8.11"
+ mran_url = "https://mran.microsoft.com/snapshot/{}".format(
+ self.checkpoint_date.isoformat()
+ )
+
scripts = [
(
"root",
@@ -241,39 +248,11 @@ class RBuildPack(PythonBuildPack):
"${NB_USER}",
# Install shiny library
r"""
- R --quiet -e "install.packages('shiny', repos='https://mran.microsoft.com/snapshot/{}', method='libcurl')"
+ R --quiet -e "install.packages('shiny', repos='{}', method='libcurl')"
""".format(
- self.checkpoint_date.isoformat()
+ mran_url
),
),
- ]
-
- if "r" in self.stencila_contexts:
- scripts += [
- (
- "${NB_USER}",
- # Install and register stencila library
- r"""
- R --quiet -e "source('https://bioconductor.org/biocLite.R'); biocLite('graph')" && \
- R --quiet -e "devtools::install_github('stencila/r', ref = '361bbf560f3f0561a8612349bca66cd8978f4f24')" && \
- R --quiet -e "stencila::register()"
- """,
- )
- ]
-
- return super().get_build_scripts() + scripts
-
- def get_assemble_scripts(self):
- """
- Return series of build-steps specific to this repository
-
- We set the snapshot date used to install R libraries from based on the
- contents of runtime.txt, and run the `install.R` script if it exists.
- """
- mran_url = "https://mran.microsoft.com/snapshot/{}".format(
- self.checkpoint_date.isoformat()
- )
- assemble_scripts = super().get_assemble_scripts() + [
(
"root",
# We set the default CRAN repo to the MRAN one at given date
@@ -285,7 +264,8 @@ class RBuildPack(PythonBuildPack):
),
),
(
- # Not all of these locations are configurable; log_dir is
+ # Not all of these locations are configurable; so we make sure
+ # they exist and have the correct permissions
"root",
r"""
install -o ${NB_USER} -g ${NB_USER} -d /var/log/shiny-server && \
@@ -296,6 +276,27 @@ class RBuildPack(PythonBuildPack):
),
]
+ if "r" in self.stencila_contexts:
+ scripts += [
+ (
+ "${NB_USER}",
+ # Install and register stencila library
+ r"""
+ R --quiet -e "source('https://bioconductor.org/biocLite.R'); biocLite('graph')" && \
+ R --quiet -e "devtools::install_github('stencila/r', ref = '361bbf560f3f0561a8612349bca66cd8978f4f24')" && \
+ R --quiet -e "stencila::register()"
+ """,
+ )
+ ]
+
+ return super().get_build_scripts() + scripts
+
+ def get_assemble_scripts(self):
+ """
+ Return series of build-steps specific to this repository.
+ """
+ assemble_scripts = super().get_assemble_scripts()
+
installR_path = self.binder_path("install.R")
if os.path.exists(installR_path):
assemble_scripts += [("${NB_USER}", "Rscript %s" % installR_path)]

Move more R config to the build phase