Merge branch '12018-tool-docs'
[arvados.git] / sdk / cwl / test_with_arvbox.sh
1 #!/bin/sh
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -x
7
8 if ! which arvbox >/dev/null ; then
9     export PATH=$PATH:$(readlink -f $(dirname $0)/../../tools/arvbox/bin)
10 fi
11
12 reset_container=1
13 leave_running=0
14 config=dev
15 tag="latest"
16
17 while test -n "$1" ; do
18     arg="$1"
19     case "$arg" in
20         --no-reset-container)
21             reset_container=0
22             shift
23             ;;
24         --leave-running)
25             leave_running=1
26             shift
27             ;;
28         --config)
29             config=$2
30             shift ; shift
31             ;;
32         --tag)
33             tag=$2
34             shift ; shift
35             ;;
36         -h|--help)
37             echo "$0 [--no-reset-container] [--leave-running] [--config dev|localdemo] [--tag docker_tag]"
38             exit
39             ;;
40         *)
41             break
42             ;;
43     esac
44 done
45
46 if test -z "$ARVBOX_CONTAINER" ; then
47    export ARVBOX_CONTAINER=cwltest
48 fi
49
50 if test $reset_container = 1 ; then
51     arvbox stop
52     docker rm $ARVBOX_CONTAINER
53     arvbox reset -f
54 fi
55
56 arvbox start $config $tag
57
58 arvbox pipe <<EOF
59 set -eu -o pipefail
60
61 . /usr/local/lib/arvbox/common.sh
62
63 if test $config = dev ; then
64   cd /usr/src/arvados/sdk/cwl
65   python setup.py sdist
66   pip_install \$(ls -r dist/arvados-cwl-runner-*.tar.gz | head -n1)
67 fi
68
69 pip install cwltest
70
71 mkdir -p /tmp/cwltest
72 cd /tmp/cwltest
73 if ! test -d common-workflow-language ; then
74   git clone https://github.com/common-workflow-language/common-workflow-language.git
75 fi
76 cd common-workflow-language
77 git pull
78 export ARVADOS_API_HOST=localhost:8000
79 export ARVADOS_API_HOST_INSECURE=1
80 export ARVADOS_API_TOKEN=\$(cat /var/lib/arvados/superuser_token)
81
82
83 if test "$tag" = "latest" ; then
84   arv-keepdocker --pull arvados/jobs $tag
85 else
86   jobsimg=\$(curl http://versions.arvados.org/v1/commit/$tag | python -c "import json; import sys; sys.stdout.write(json.load(sys.stdin)['Versions']['Docker']['arvados/jobs'])")
87   arv-keepdocker --pull arvados/jobs \$jobsimg
88   docker tag arvados/jobs:\$jobsimg arvados/jobs:latest
89   arv-keepdocker arvados/jobs latest
90 fi
91
92 cat >/tmp/cwltest/arv-cwl-jobs <<EOF2
93 #!/bin/sh
94 exec arvados-cwl-runner --api=jobs \\\$@
95 EOF2
96 chmod +x /tmp/cwltest/arv-cwl-jobs
97
98 cat >/tmp/cwltest/arv-cwl-containers <<EOF2
99 #!/bin/sh
100 exec arvados-cwl-runner --api=containers \\\$@
101 EOF2
102 chmod +x /tmp/cwltest/arv-cwl-containers
103
104 env
105 exec ./run_test.sh RUNNER=/tmp/cwltest/arv-cwl-containers EXTRA=--compute-checksum $@
106 EOF
107
108 CODE=$?
109
110 if test $leave_running = 0 ; then
111     arvbox stop
112 fi
113
114 exit $CODE