-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.sh
executable file
·68 lines (57 loc) · 2.3 KB
/
run.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
65
66
67
68
image=parkeraddison/policyrecon
devimage=parkeraddison/policyrecon-devcontainer
tag=latest
show_help() {
echo "Usage: ./run.sh [TARGET] [-i/--image IMAGE] [-d/--dev-image DEVIMAGE] [-t/--tag TAG]\n"
echo "Available Targets"
echo "-----------------"
grep ') #: ' run.sh | sed '1d' | sed 's, \(.*\)) #: \(.*\), \1#\2\n,' | column -ts '#'
echo
}
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
while getopts hi:d:t:-: OPT; do
# support long options: https://stackoverflow.com/a/28466267/519360
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
h | help ) show_help; exit 0 ;;
i | image ) needs_arg; image="$OPTARG" ;;
d | dev-image ) needs_arg; devimage="$OPTARG" ;;
t | tag ) needs_arg; tag="$OPTARG" ;;
??* ) die "Illegal option --$OPT" ;; # bad long option
? ) exit 2 ;; # bad short option (error reported via getopts)
esac
done
exe() { echo "\$ $@\n" ; "$@" ; }
case $1 in
help) #: Show this help message. Default when no target provided.
show_help
;;
build) #: Build the base container image. Available options: image, tag
exe docker build -t "${image}:${tag}" .
;;
build-dev) #: Build the devcontainer image. Available options: dev-image, tag
exe docker build -t "${devimage}:${tag}" -f .devcontainer/Dockerfile .
;;
launch) #: Launch a base container image for easy manual pipeline runs. Available options: image, tag
exe docker run -it \
-v $(pwd):/workspace -w /workspace \
-v $(pwd)/.docker-cache:/root \
"${image}:${tag}" \
bash
;;
pipeline) #: Run pipeline from a base container image. Available options: image, tag
exe docker run -it \
-v $(pwd):/workspace -w /workspace \
-v $(pwd)/.docker-cache:/root \
"${image}:${tag}" \
python pipeline.py
;;
*)
show_help
;;
esac