docker-pre-commit/compose-check.sh

31 lines
642 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
echo "Some compose files failed"
2018-05-21 17:31:29 +00:00
fi
exit $has_error