From 6ab41efd4d483aa944eb2140f65d3f246c47208b Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Tue, 25 Jan 2022 21:26:16 +0530 Subject: [PATCH] Delete /tmp/downloaded_packages after running install.R This can often leave ~100-200MB in /tmp that isn't re-used after the image is set up. --- repo2docker/buildpacks/r.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index 096ebb47..8420481f 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -387,7 +387,10 @@ class RBuildPack(PythonBuildPack): scripts += [ ( "${NB_USER}", - "Rscript %s && touch /tmp/.preassembled || true" % installR_path, + # Delete /tmp/downloaded_packages only if install.R fails, as the second + # invocation of install.R might be able to reuse them + "Rscript %s && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages" + % installR_path, ) ] @@ -403,7 +406,8 @@ class RBuildPack(PythonBuildPack): ( "${NB_USER}", # only run install.R if the pre-assembly failed - "if [ ! -f /tmp/.preassembled ]; then Rscript {}; fi".format( + # Delete any downloaded packages in /tmp, as they aren't reused by R + """if [ ! -f /tmp/.preassembled ]; then Rscript {}; rm -rf /tmp/downloaded_packages; fi""".format( installR_path ), )