-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·62 lines (54 loc) · 1.23 KB
/
entrypoint.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
#!/bin/sh
set -ex
while getopts ":t:c:l:o:f:" o; do
case "${o}" in
t)
export imageName="$(echo "${OPTARG}" | sed 's/^ *\| *$//')"
;;
c)
export exitCode="$(echo "${OPTARG}" | sed 's/^ *\| *$//')"
;;
l)
export exitLevel="$(echo "${OPTARG}" | sed 's/^ *\| *$//')"
;;
o)
export output="$(echo "${OPTARG}" | sed 's/^ *\| *$//')"
;;
f)
export format="$(echo "${OPTARG}" | sed 's/^ *\| *$//')"
;;
\?)
echo "unknown flag"
;;
esac
done
function run_dockle() {
/usr/bin/dockle $@ $imageName
}
FIRST_ARGS=""
SECOND_ARGS=""
if [ $exitLevel ]; then
FIRST_ARGS="$FIRST_ARGS --exit-level $exitLevel"
SECOND_ARGS="$SECOND_ARGS --exit-level $exitLevel"
fi
# 1st time: run dockle with exit 0 for left a report file
if [ $format ]; then
FIRST_ARGS="$FIRST_ARGS --format $format"
fi
if [ $output ]; then
FIRST_ARGS="$FIRST_ARGS --output $output"
fi
# 2nd time: run dockle with exit code without report file
if [ $exitCode ]; then
SECOND_ARGS="$SECOND_ARGS --exit-code $exitCode"
fi
RUN_TWICE=""
if [ "$output" != "" ] && [ "$exitCode" != '0' ]; then
RUN_TWICE="TRUE"
fi
if [ $RUN_TWICE ]; then
run_dockle $FIRST_ARGS
run_dockle $SECOND_ARGS
else
run_dockle $FIRST_ARGS $SECOND_ARGS
fi