[e988c2]: / scripts / run-debug.sh

Download this file

90 lines (76 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -eou pipefail
if [[ -z "${1:-}" ]]; then
echo 'Runs ehrQL using the production Docker container with the local code'
echo 'checkout mounted in and the environment loaded from `environ.env`.'
echo
echo 'It also mounts the current directory under `/workspace` so it can be'
echo 'run in the checkout of a study repo to mimic production behaviour.'
echo
echo 'Remember to DELETE any extracted data as soon as possible after use.'
echo
echo 'By default it runs the container detached and tails the log file. Use'
echo 'the `-i` flag to run interactively.'
echo
echo 'Additional arguments are passed to ehrQL as normal e.g.'
echo
echo ' cd ~/some_study_repo'
echo ' ../ehrql/scripts/run-debug.sh generate-dataset analysis/dataset_definition.py --output test.csv'
echo
exit 1
fi
if [[ "$1" == "-i" ]]; then
detached=false
shift
else
detached=true
fi
script_dir="$( unset CDPATH && cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
ehrql_dir="$( unset CDPATH && cd "$script_dir/../" && pwd )"
env_file="$script_dir/environ.env"
container_name="$USER-ehrql-test-$(date -u +%Y%m%d-%H%M%S)"
if [[ ! -f "$env_file" ]]; then
echo "Expecting an env file at: $env_file"
echo
echo "This should contain appropriate configuration values e.g."
echo
echo " OPENSAFELY_BACKEND=tpp"
echo " TEMP_DATABASE_NAME=OPENCoronaTempTables"
echo " DATABASE_URL=__Your personal DB creds__"
echo
echo "** NOTE **"
echo "When exercising the system for debugging/development purposes you MUST"
echo "use your personal database credentials and NOT the system credentials."
exit 1
fi
if $detached; then
docker run \
--detach \
--name "$container_name" \
--env-file "$env_file" \
--volume "$ehrql_dir:/app" \
--volume "$PWD:/workspace" \
--user "$UID" \
ghcr.io/opensafely-core/ehrql:v1 \
"$@" \
> /dev/null
echo "Running container in background and tailing logs. Clean up with:"
echo
echo " docker rm -f $container_name"
echo
echo "Remember to DELETE any extracted data as soon as possible after use."
echo
exec docker logs -f "$container_name"
else
exec docker run \
--rm \
--interactive \
--tty \
--name "$container_name" \
--env-file "$env_file" \
--volume "$ehrql_dir:/app" \
--volume "$PWD:/workspace" \
--user "$UID" \
ghcr.io/opensafely-core/ehrql:v1 \
"$@"
fi