Compare commits
No commits in common. "master" and "v2.1.0" have entirely different histories.
@ -9,8 +9,9 @@ workspace:
|
||||
steps:
|
||||
|
||||
- name: test
|
||||
image: iamthefij/drone-pre-commit@sha256:6ed8dae6b0067bd2e145e36421bcfbbc68975ff7ddaa5a3f285b5bcdaf0989c8
|
||||
image: iamthefij/drone-pre-commit:latest
|
||||
commands:
|
||||
- pip install docker-compose
|
||||
- make all
|
||||
|
||||
- name: notify
|
||||
|
@ -1,7 +1,21 @@
|
||||
---
|
||||
- id: docker-compose-check
|
||||
name: Validate docker compose files
|
||||
description: Checks that docker compose files are valid
|
||||
name: Validate docker-compose files
|
||||
description: Checks that docker-compose files are valid
|
||||
language: script
|
||||
entry: compose-check.sh
|
||||
files: (docker-)?compose\.ya?ml$
|
||||
files: docker-compose.y[a]{0,1}ml$
|
||||
|
||||
- id: hadolint
|
||||
name: Lint Dockerfiles
|
||||
description: Deprecated! Runs hadolint Docker image to lint Dockerfiles
|
||||
language: script
|
||||
entry: hadolint-deprecation.sh
|
||||
files: Dockerfile
|
||||
|
||||
- id: hadolint-system
|
||||
name: Lint Dockerfiles
|
||||
description: Deprecated! Runs system hadolint to lint Dockerfiles
|
||||
language: script
|
||||
entry: hadolint-deprecation.sh
|
||||
files: Dockerfile
|
||||
|
6
Makefile
6
Makefile
@ -2,7 +2,7 @@
|
||||
|
||||
all: check test
|
||||
|
||||
test: test-negative test-positive test-hooks
|
||||
test: test-negative test-positive
|
||||
|
||||
.PHONY: test-positive
|
||||
test-positive:
|
||||
@ -16,10 +16,6 @@ test-negative:
|
||||
@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:
|
||||
|
19
README.md
19
README.md
@ -2,21 +2,10 @@
|
||||
|
||||
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.
|
||||
|
||||
### hadolint (Removed)
|
||||
These hooks have been removed in favor of the ones that have been added to https://github.com/hadolint/hadolint
|
||||
|
@ -2,40 +2,28 @@
|
||||
# Verifies that files passed in are valid for docker-compose
|
||||
set -e
|
||||
|
||||
# Check if docker or podman commands are available
|
||||
if [[ -z "${CONTAINER_ENGINE}" ]]; then
|
||||
if command -v docker &>/dev/null; then
|
||||
CONTAINER_ENGINE=docker
|
||||
elif command -v podman &>/dev/null; then
|
||||
CONTAINER_ENGINE=podman
|
||||
else
|
||||
echo "ERROR: Neither 'docker' or 'podman' were found"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v "${CONTAINER_ENGINE}" &>/dev/null && ${CONTAINER_ENGINE} help compose &> /dev/null; then
|
||||
COMPOSE="${CONTAINER_ENGINE} compose"
|
||||
elif command -v "${CONTAINER_ENGINE}-compose" &> /dev/null; then
|
||||
COMPOSE="${CONTAINER_ENGINE}-compose"
|
||||
if command -v docker-compose &> /dev/null ; then
|
||||
COMPOSE=docker-compose
|
||||
elif command -v docker &> /dev/null && docker help compose &> /dev/null; then
|
||||
COMPOSE=docker compose
|
||||
else
|
||||
echo "ERROR: Neither '${CONTAINER_ENGINE}-compose' or '${CONTAINER_ENGINE} compose' were found"
|
||||
echo "ERROR: Neither 'docker-compose' or 'docker compose' were found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_file() {
|
||||
local file=$1
|
||||
env $COMPOSE --file "$file" config --quiet 2>&1 |
|
||||
sed "/variable is not set. Defaulting/d"
|
||||
env $COMPOSE --file "$file" config --quiet 2>&1 \
|
||||
| sed "/variable is not set. Defaulting/d"
|
||||
return "${PIPESTATUS[0]}"
|
||||
}
|
||||
|
||||
check_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
|
||||
if ! check_file "$file" ; then
|
||||
echo "ERROR: $file"
|
||||
has_error=1
|
||||
fi
|
||||
@ -44,7 +32,7 @@ check_files() {
|
||||
return $has_error
|
||||
}
|
||||
|
||||
if ! check_files "$@"; then
|
||||
if ! check_files "$@" ; then
|
||||
echo "Some compose files failed"
|
||||
fi
|
||||
|
||||
|
8
hadolint-deprecation.sh
Executable file
8
hadolint-deprecation.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#! /bin/sh
|
||||
|
||||
echo "Hadolint hooks have been deprecated in favor of upstream"
|
||||
echo "repo: https://github.com/hadolint/hadolint"
|
||||
echo "Replace hook 'hadolint' with 'hadolint-docker'"
|
||||
echo "Replace hook 'hadolint-system' with 'hadolint'"
|
||||
|
||||
exit 1
|
Loading…
Reference in New Issue
Block a user