a112cb93fe07cadbcfb814606497df0b0e9328f8
[arvados.git] / tools / arvbox / lib / arvbox / docker / service / workbench2 / run-service
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 exec 2>&1
7 set -ex -o pipefail
8
9 .  /usr/local/lib/arvbox/common.sh
10
11 if test "$1" != "--only-deps" ; then
12   while [ ! -f $ARVADOS_CONTAINER_PATH/api.ready ]; do
13     sleep 1
14   done
15 fi
16
17 cd /usr/src/workbench2
18
19 npm -d install --prefix /usr/local --global yarn@1.17.3
20
21 yarn install
22
23 if test "$1" = "--only-deps" ; then
24     exit
25 fi
26
27 cat <<EOF > /usr/src/workbench2/public/config.json
28 {
29   "API_HOST": "${localip}:${services[controller-ssl]}",
30   "VOCABULARY_URL": "/vocabulary-example.json",
31   "FILE_VIEWERS_CONFIG_URL": "/file-viewers-example.json"
32 }
33 EOF
34
35 export ARVADOS_API_HOST=$localip:${services[controller-ssl]}
36 export ARVADOS_API_TOKEN=$(cat $ARVADOS_CONTAINER_PATH/superuser_token)
37
38 url_prefix="https://$localip:${services[workbench2-ssl]}/"
39
40 set +e
41 read -rd $'\000' apiclient <<EOF
42 {
43    "url_prefix": "$url_prefix",
44    "is_trusted": true
45 }
46 EOF
47 set -e
48
49 clientuuid=$(arv --format=uuid api_client list --filters '[["url_prefix", "=", "'$url_prefix'"]]')
50 if [[ -n "$clientuuid" ]] ; then
51     arv api_client update --uuid $clientuuid --api-client "$apiclient"
52 else
53     arv api_client create --api-client "$apiclient"
54 fi
55
56 # Can't use "yarn start", need to run the dev server script
57 # directly so that the TERM signal from "sv restart" gets to the
58 # right process.
59 export VERSION=$(./version-at-commit.sh)
60 export BROWSER=none
61 export CI=true
62 export HTTPS=false
63 node --version
64 exec node node_modules/react-scripts/scripts/start.js