docker-pre-commit/compose-check.sh

31 lines
643 B
Bash
Raw Normal View History

2018-05-21 17:31:29 +00:00
#! /bin/bash
# Verifies that files passed in are valid for docker-compose
set -e
check_file() {
local file=$1
2020-09-19 19:57:38 +00:00
docker-compose --file "$file" config --quiet 2>&1 \
2018-05-21 17:31:29 +00:00
| sed "/variable is not set. Defaulting/d"
2020-01-27 22:17:55 +00:00
return "${PIPESTATUS[0]}"
2018-05-21 17:31:29 +00:00
}
check_files() {
2020-01-27 22:17:55 +00:00
local all_files=( "$@" )
2018-05-21 17:31:29 +00:00
has_error=0
2020-01-27 22:17:55 +00:00
for file in "${all_files[@]}" ; do
2018-05-21 17:31:29 +00:00
if [[ -f "$file" ]]; then
if ! check_file "$file" ; then
2020-01-27 22:17:55 +00:00
echo "ERROR: $file"
2018-05-21 17:31:29 +00:00
has_error=1
fi
fi
done
return $has_error
}
2020-01-27 22:17:55 +00:00
if ! check_files "$@" ; then
2018-05-21 17:31:29 +00:00
echo "To ignore, use --no-verify"
fi
exit $has_error