Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
d67a852ae8 | |||
6cf8fe749d | |||
f626253b23 | |||
15a900b1bb | |||
098ffc1472 | |||
1acd61cff1 | |||
95effa7859 | |||
617b8880e4 | |||
|
3380d1a68e | ||
|
5ed0959cc4 | ||
|
f16a4574c1 | ||
71cd8ff86a | |||
5a0378fee5 | |||
9a22a2046c | |||
67b85ce990 | |||
86d69eafb9 | |||
aeda358a4a | |||
5c7dc7758b | |||
9a0ea5ca85 | |||
|
6cf90c5656 | ||
96e53d68bb | |||
433aa60a38 | |||
d0670c0c9f | |||
af49bee4e5 |
27
.drone.yml
Normal file
27
.drone.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: test
|
||||
|
||||
workspace:
|
||||
base: "/app"
|
||||
path: "."
|
||||
|
||||
steps:
|
||||
|
||||
- name: test
|
||||
image: iamthefij/drone-pre-commit@sha256:6ed8dae6b0067bd2e145e36421bcfbbc68975ff7ddaa5a3f285b5bcdaf0989c8
|
||||
commands:
|
||||
- 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]
|
14
.pre-commit-config.yaml
Normal file
14
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.2.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
args:
|
||||
- --allow-multiple-documents
|
||||
- id: check-merge-conflict
|
||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||
rev: v0.7.1.1
|
||||
hooks:
|
||||
- id: shellcheck
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
- id: docker-compose-check
|
||||
name: Validate docker-compose files
|
||||
description: Checks that vault files are encrypted
|
||||
entry: compose-check.sh
|
||||
files: docker-compose.y[a]{0,1}ml$
|
||||
name: Validate docker compose files
|
||||
description: Checks that docker compose files are valid
|
||||
language: script
|
||||
entry: compose-check.sh
|
||||
files: (docker-)?compose\.ya?ml$
|
||||
|
|
31
Makefile
Normal file
31
Makefile
Normal file
|
@ -0,0 +1,31 @@
|
|||
.PHONY: all test clean
|
||||
|
||||
all: check test
|
||||
|
||||
test: test-negative test-positive test-hooks
|
||||
|
||||
.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'
|
||||
|
||||
.PHONY: test-hooks
|
||||
test-hooks:
|
||||
pre-commit try-repo . --all-files
|
||||
|
||||
# Installs pre-commit hooks
|
||||
.PHONY: install-hooks
|
||||
install-hooks:
|
||||
pre-commit install --install-hooks
|
||||
|
||||
# Checks files for encryption
|
||||
.PHONY: check
|
||||
check:
|
||||
pre-commit run --all-files
|
16
README.md
16
README.md
|
@ -2,7 +2,21 @@
|
|||
|
||||
A set of [pre-commit](http://pre-commit.com) hooks for Docker services
|
||||
|
||||
# Installation
|
||||
|
||||
Add the following to your `.pre-commit-config.yaml` file
|
||||
|
||||
```yaml
|
||||
- repo: https://github.com/iamthefij/docker-pre-commit
|
||||
rev: master
|
||||
hooks:
|
||||
- id: docker-compose-check
|
||||
```
|
||||
|
||||
and then run `pre-commit autoupdate`.
|
||||
|
||||
|
||||
## Hooks
|
||||
|
||||
### docker-compose-check
|
||||
Verifies that docker-compose files are valid by using `docker-compose config` to parse them.
|
||||
Verifies that docker compose files are valid by using `docker compose config` to parse them.
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
#! /bin/bash
|
||||
#! /usr/bin/env bash
|
||||
# Verifies that files passed in are valid for docker-compose
|
||||
set -e
|
||||
|
||||
if command -v docker &> /dev/null && docker help compose &> /dev/null; then
|
||||
COMPOSE="docker compose"
|
||||
elif command -v docker-compose &> /dev/null ; then
|
||||
COMPOSE=docker-compose
|
||||
else
|
||||
echo "ERROR: Neither 'docker-compose' or 'docker compose' were found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_file() {
|
||||
local file=$1
|
||||
docker-compose -f "$file" config -q 2>&1 \
|
||||
env $COMPOSE --file "$file" config --quiet 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,8 +32,8 @@ check_files() {
|
|||
return $has_error
|
||||
}
|
||||
|
||||
if ! check_files $@ ; then
|
||||
echo "To ignore, use --no-verify"
|
||||
if ! check_files "$@" ; then
|
||||
echo "Some compose files failed"
|
||||
fi
|
||||
|
||||
exit $has_error
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
- id: docker-compose-check
|
||||
name: Validate docker-compose files
|
||||
description: Checks that docker-compose files are valid
|
||||
entry: compose-check.sh
|
||||
files: docker-compose.y[a]{0,1}ml$
|
||||
language: script
|
1
tests/docker-compose.bad.yml
Normal file
1
tests/docker-compose.bad.yml
Normal file
|
@ -0,0 +1 @@
|
|||
not: valid
|
6
tests/docker-compose.yml
Normal file
6
tests/docker-compose.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
main:
|
||||
image: busybox
|
Loading…
Reference in New Issue
Block a user