-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_docker.sh
executable file
·64 lines (59 loc) · 1.85 KB
/
run_docker.sh
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
#!/usr/bin/env bash
set -e -o pipefail
# Exit 1 unless arguments in "$@" are a valid command line.
#
is_usage_ok () {
local -r tag=$1 config=$2
if [ $# -lt 4 ] && [ "$tag" ] && jq . "$config" >/dev/null
then
: OK
else
1>&2 echo
1>&2 echo "Usage: bash run_docker.sh TAG CONFIG [PORT]"
1>&2 echo
1>&2 echo "Where: CONFIG is the absolute path to a Lira config file."
1>&2 echo " TAG is the docker image tag."
1>&2 echo " PORT is a port number to bind (default 8080)."
1>&2 echo
1>&2 echo "NOTE: CONFIG is a JSON file."
1>&2 echo
exit 1
fi
}
# Run "$@" as a docker command line.
#
run_it () {
1>&2 echo
1>&2 echo Removing any previously started lira containers.
1>&2 echo
1>&2 echo Running: docker stop lira
docker stop lira || true
1>&2 echo Running: docker rm lira
docker rm lira || true
1>&2 echo
1>&2 echo Run '"docker stop lira"' in another shell session
1>&2 echo to shut the lira container down.
1>&2 echo
1>&2 echo Running: docker "$@"
docker "$@"
}
main () {
is_usage_ok "$@"
local -r wd=$(pwd) tag=$1 config=$2 port=${3:-8080}
local -r tmpdir=$(mktemp -d "$wd/${0##*/}XXXXXX")
trap "rm -rf ${tmpdir}" ERR EXIT HUP INT TERM
local -r lira=/etc/secondary-analysis/lira
local cmd=(run --name lira --publish "$port:$port"
--volume "$tmpdir:$lira:ro"
-e "lira_config=$lira/config.json")
cp "$config" "$tmpdir/config.json"
if jq --exit-status .use_caas "$config" > /dev/null; then
vault read --format=json --field=data \
secret/dsde/mint/test/lira/caas-prod-key.json \
> "$tmpdir/caas_key.json"
cmd+=(-e "caas_key=$lira/caas_key.json")
fi
cmd+=("lira:$tag" "$port")
run_it "${cmd[@]}"
}
main "$@"