Diff of /scripts/run-debug.sh [000000] .. [e988c2]

Switch to unified view

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