Arvbox support for caching and offline install of npm packages. no issue #
[arvados.git] / tools / arvbox / lib / arvbox / docker / common.sh
index 230a189a9a244c79d94380960f82d4ad52ddb6c3..9bf92f4ee85d06acf8272090b6711797cd73b363 100644 (file)
@@ -1,7 +1,13 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 
 export PATH=${PATH}:/usr/local/go/bin:/var/lib/gems/bin
 export GEM_HOME=/var/lib/gems
 export GEM_PATH=/var/lib/gems
+export npm_config_cache=/var/lib/npm
+export npm_config_cache_min=Infinity
 
 if test -s /var/run/localip_override ; then
     localip=$(cat /var/run/localip_override)
@@ -40,7 +46,12 @@ run_bundler() {
         frozen=""
     fi
     if ! test -x bundle ; then
-        gem install --no-document bundler
+        bundlergem=$(ls -r $GEM_HOME/cache/bundler-*.gem 2>/dev/null | head -n1 || true)
+        if test -n "$bundlergem" ; then
+            flock /var/lib/gems/gems.lock gem install --local --no-document $bundlergem
+        else
+            flock /var/lib/gems/gems.lock gem install --no-document bundler
+        fi
     fi
     if ! flock /var/lib/gems/gems.lock bundle install --path $GEM_HOME --local --no-deployment $frozen "$@" ; then
         flock /var/lib/gems/gems.lock bundle install --path $GEM_HOME --no-deployment $frozen "$@"
@@ -49,14 +60,14 @@ run_bundler() {
 
 pip_install() {
     pushd /var/lib/pip
-    for p in $(ls http*.tar.gz) $(ls http*.whl) $(ls http*.zip) ; do
+    for p in $(ls http*.tar.gz) $(ls http*.tar.bz2) $(ls http*.whl) $(ls http*.zip) ; do
         if test -f $p ; then
             ln -sf $p $(echo $p | sed 's/.*%2F\(.*\)/\1/')
         fi
     done
     popd
 
-    if ! pip install --no-index --find-links /var/lib/pip $1 ; then
-        pip install $1
+    if ! pip install --no-index --find-links /var/lib/pip --system $1 ; then
+        pip install --system $1
     fi
 }