Merge pull request #328 from konstruktoid/issue286

add include option #286
This commit is contained in:
Thomas Sjögren 2018-10-25 08:47:04 +02:00 committed by GitHub
commit 6789403599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,6 +44,7 @@ usage () {
-l FILE optional Log output in FILE -l FILE optional Log output in FILE
-c CHECK optional Comma delimited list of specific check(s) -c CHECK optional Comma delimited list of specific check(s)
-e CHECK optional Comma delimited list of specific check(s) to exclude -e CHECK optional Comma delimited list of specific check(s) to exclude
-i INCLUDE optional Comma delimited list of patterns within a container name to check
-x EXCLUDE optional Comma delimited list of patterns within a container name to exclude from check -x EXCLUDE optional Comma delimited list of patterns within a container name to exclude from check
EOF EOF
} }
@ -51,13 +52,14 @@ EOF
# Get the flags # Get the flags
# If you add an option here, please # If you add an option here, please
# remember to update usage() above. # remember to update usage() above.
while getopts hl:c:e:x: args while getopts hl:c:e:i:x: args
do do
case $args in case $args in
h) usage; exit 0 ;; h) usage; exit 0 ;;
l) logger="$OPTARG" ;; l) logger="$OPTARG" ;;
c) check="$OPTARG" ;; c) check="$OPTARG" ;;
e) checkexclude="$OPTARG" ;; e) checkexclude="$OPTARG" ;;
i) include="$OPTARG" ;;
x) exclude="$OPTARG" ;; x) exclude="$OPTARG" ;;
*) usage; exit 1 ;; *) usage; exit 1 ;;
esac esac
@ -87,13 +89,6 @@ beginjson "$version" "$(date +%s)"
# Load all the tests from tests/ and run them # Load all the tests from tests/ and run them
main () { main () {
# List all running containers
if [ -z "$exclude" ]; then
containers=$(docker ps | sed '1d' | awk '{print $NF}')
else
pattern=$(echo "$exclude" | sed 's/,/|/g')
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -Ev "$pattern" )
fi
# If there is a container with label docker_bench_security, memorize it: # If there is a container with label docker_bench_security, memorize it:
benchcont="nil" benchcont="nil"
for c in $containers; do for c in $containers; do
@ -102,12 +97,15 @@ main () {
benchcont="$c" benchcont="$c"
fi fi
done done
# List all running containers except docker-bench (use names to improve readability in logs)
if [ -z "$exclude" ]; then if [ -n "$include" ]; then
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont") pattern=$(echo "$include" | sed 's/,/|/g')
else containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -E "$pattern")
elif [ -n "$exclude" ]; then
pattern=$(echo "$exclude" | sed 's/,/|/g') pattern=$(echo "$exclude" | sed 's/,/|/g')
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -Ev "$pattern" | grep -v "$benchcont") containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -Ev "$pattern")
else
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont")
fi fi
if [ -z "$containers" ]; then if [ -z "$containers" ]; then