diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0efbffa --- /dev/null +++ b/.drone.yml @@ -0,0 +1,29 @@ +--- +kind: pipeline +name: test + +workspace: + base: "/app" + path: "." + +steps: + + - name: test + image: python:3-alpine + commands: + - apk add bash shellcheck make gcc musl-dev libffi-dev openssl-dev + - pip install docker-compose + - make all + + - name: notify + image: drillster/drone-email + settings: + host: + from_secret: SMTP_HOST # pragma: whitelist secret + username: + from_secret: SMTP_USER # pragma: whitelist secret + password: + from_secret: SMTP_PASS # pragma: whitelist secret + from: drone@iamthefij.com + when: + status: [changed, failure] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c20cc9e --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: all test clean + +all: test shellcheck + +test: test-negative test-positive + +.PHONY: shellcheck +shellcheck: + shellcheck *.sh + +.PHONY: test-positive +test-positive: + @echo "Check valid compose file." + ./compose-check.sh tests/docker-compose.yml || { echo 'fail'; exit 1; } + +.PHONY: test-negative +test-negative: + @echo "Check bad file. Should error." + ./compose-check.sh tests/docker-compose.bad.yml && { echo 'fail'; exit 1; } || echo 'ok' + @echo "Check multiple files. Should error." + ./compose-check.sh tests/docker-compose* && { echo 'fail'; exit 1; } || echo 'ok' diff --git a/compose-check.sh b/compose-check.sh index 5cb2f05..b038955 100755 --- a/compose-check.sh +++ b/compose-check.sh @@ -6,15 +6,16 @@ check_file() { local file=$1 docker-compose -f "$file" config -q 2>&1 \ | sed "/variable is not set. Defaulting/d" - return ${PIPESTATUS[0]} + return "${PIPESTATUS[0]}" } check_files() { - local all_files=$@ + local all_files=( "$@" ) has_error=0 - for file in $all_files ; do + for file in "${all_files[@]}" ; do if [[ -f "$file" ]]; then if ! check_file "$file" ; then + echo "ERROR: $file" has_error=1 fi fi @@ -22,7 +23,7 @@ check_files() { return $has_error } -if ! check_files $@ ; then +if ! check_files "$@" ; then echo "To ignore, use --no-verify" fi diff --git a/tests/docker-compose.bad.yml b/tests/docker-compose.bad.yml new file mode 100644 index 0000000..87de008 --- /dev/null +++ b/tests/docker-compose.bad.yml @@ -0,0 +1 @@ +not: valid diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 0000000..be64343 --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,6 @@ +--- +version: '2' + +services: + main: + image: busybox