12298: Allow non-null log when cancelling an unrunnable container.
[arvados.git] / tools / arvbox / lib / arvbox / docker / common.sh
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5
6 export PATH=${PATH}:/usr/local/go/bin:/var/lib/gems/bin
7 export GEM_HOME=/var/lib/gems
8 export GEM_PATH=/var/lib/gems
9 export npm_config_cache=/var/lib/npm
10 export npm_config_cache_min=Infinity
11
12 if test -s /var/run/localip_override ; then
13     localip=$(cat /var/run/localip_override)
14 else
15     defaultdev=$(/sbin/ip route|awk '/default/ { print $5 }')
16     localip=$(ip addr show $defaultdev | grep 'inet ' | sed 's/ *inet \(.*\)\/.*/\1/')
17 fi
18
19 declare -A services
20 services=(
21   [workbench]=80
22   [api]=8000
23   [sso]=8900
24   [arv-git-httpd]=9001
25   [keep-web]=9002
26   [keepproxy]=25100
27   [keepstore0]=25107
28   [keepstore1]=25108
29   [ssh]=22
30   [doc]=8001
31   [websockets]=8002
32 )
33
34 if test "$(id arvbox -u 2>/dev/null)" = 0 ; then
35     PGUSER=postgres
36     PGGROUP=postgres
37 else
38     PGUSER=arvbox
39     PGGROUP=arvbox
40 fi
41
42 run_bundler() {
43     if test -f Gemfile.lock ; then
44         frozen=--frozen
45     else
46         frozen=""
47     fi
48     if ! test -x bundle ; then
49         bundlergem=$(ls -r $GEM_HOME/cache/bundler-*.gem 2>/dev/null | head -n1 || true)
50         if test -n "$bundlergem" ; then
51             flock /var/lib/gems/gems.lock gem install --local --no-document $bundlergem
52         else
53             flock /var/lib/gems/gems.lock gem install --no-document bundler
54         fi
55     fi
56     if ! flock /var/lib/gems/gems.lock bundle install --path $GEM_HOME --local --no-deployment $frozen "$@" ; then
57         flock /var/lib/gems/gems.lock bundle install --path $GEM_HOME --no-deployment $frozen "$@"
58     fi
59 }
60
61 pip_install() {
62     pushd /var/lib/pip
63     for p in $(ls http*.tar.gz) $(ls http*.tar.bz2) $(ls http*.whl) $(ls http*.zip) ; do
64         if test -f $p ; then
65             ln -sf $p $(echo $p | sed 's/.*%2F\(.*\)/\1/')
66         fi
67     done
68     popd
69
70     if ! pip install --no-index --find-links /var/lib/pip --system $1 ; then
71         pip install --system $1
72     fi
73 }