Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
62a24686f7 | |||
|
d10b550878 | ||
d67a852ae8 | |||
6cf8fe749d | |||
f626253b23 | |||
15a900b1bb | |||
098ffc1472 | |||
1acd61cff1 | |||
95effa7859 | |||
617b8880e4 | |||
|
3380d1a68e | ||
|
5ed0959cc4 | ||
|
f16a4574c1 | ||
71cd8ff86a | |||
5a0378fee5 | |||
9a22a2046c | |||
67b85ce990 | |||
86d69eafb9 | |||
aeda358a4a | |||
5c7dc7758b | |||
9a0ea5ca85 | |||
|
6cf90c5656 |
@ -9,11 +9,8 @@ workspace:
|
|||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
image: python:3-slim
|
image: iamthefij/drone-pre-commit@sha256:6ed8dae6b0067bd2e145e36421bcfbbc68975ff7ddaa5a3f285b5bcdaf0989c8
|
||||||
commands:
|
commands:
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y --no-install-recommends make shellcheck
|
|
||||||
- pip install docker-compose
|
|
||||||
- make all
|
- make all
|
||||||
|
|
||||||
- name: notify
|
- name: notify
|
||||||
|
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,19 +1,7 @@
|
|||||||
---
|
---
|
||||||
- id: docker-compose-check
|
- id: docker-compose-check
|
||||||
name: Validate docker-compose files
|
name: Validate docker compose files
|
||||||
description: Checks that docker-compose files are valid
|
description: Checks that docker compose files are valid
|
||||||
language: script
|
language: script
|
||||||
entry: compose-check.sh
|
entry: compose-check.sh
|
||||||
files: docker-compose.y[a]{0,1}ml$
|
files: (docker-)?compose\.ya?ml$
|
||||||
- id: hadolint
|
|
||||||
name: Lint Dockerfiles
|
|
||||||
description: Runs hadolint Docker image to lint Dockerfiles
|
|
||||||
language: docker_image
|
|
||||||
entry: hadolint/hadolint hadolint
|
|
||||||
files: Dockerfile
|
|
||||||
- id: hadolint-system
|
|
||||||
name: Lint Dockerfiles
|
|
||||||
description: Runs system hadolint to lint Dockerfiles
|
|
||||||
language: system
|
|
||||||
entry: hadolint
|
|
||||||
files: Dockerfile
|
|
||||||
|
22
Makefile
22
Makefile
@ -1,12 +1,8 @@
|
|||||||
.PHONY: all test clean
|
.PHONY: all test clean
|
||||||
|
|
||||||
all: test shellcheck
|
all: check test
|
||||||
|
|
||||||
test: test-negative test-positive
|
test: test-negative test-positive test-hooks
|
||||||
|
|
||||||
.PHONY: shellcheck
|
|
||||||
shellcheck:
|
|
||||||
shellcheck *.sh
|
|
||||||
|
|
||||||
.PHONY: test-positive
|
.PHONY: test-positive
|
||||||
test-positive:
|
test-positive:
|
||||||
@ -19,3 +15,17 @@ test-negative:
|
|||||||
./compose-check.sh tests/docker-compose.bad.yml && { echo 'fail'; exit 1; } || echo 'ok'
|
./compose-check.sh tests/docker-compose.bad.yml && { echo 'fail'; exit 1; } || echo 'ok'
|
||||||
@echo "Check multiple files. Should error."
|
@echo "Check multiple files. Should error."
|
||||||
./compose-check.sh tests/docker-compose* && { echo 'fail'; exit 1; } || echo 'ok'
|
./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
|
||||||
|
22
README.md
22
README.md
@ -2,13 +2,21 @@
|
|||||||
|
|
||||||
A set of [pre-commit](http://pre-commit.com) hooks for Docker services
|
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
|
## Hooks
|
||||||
|
|
||||||
### docker-compose-check
|
### 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
|
|
||||||
Uses the [hadolint Docker image](https://hub.docker.com/hadolint/hadolint) to lint Dockerfiles.
|
|
||||||
|
|
||||||
### hadolint-system
|
|
||||||
Uses the whatever version of hadolint that you have installed to lint Dockerfiles. This requires you to have hadolint installed somewhere in your path.
|
|
||||||
|
@ -1,20 +1,41 @@
|
|||||||
#! /bin/bash
|
#! /usr/bin/env bash
|
||||||
# Verifies that files passed in are valid for docker-compose
|
# Verifies that files passed in are valid for docker-compose
|
||||||
set -e
|
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"
|
||||||
|
else
|
||||||
|
echo "ERROR: Neither '${CONTAINER_ENGINE}-compose' or '${CONTAINER_ENGINE} compose' were found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
check_file() {
|
check_file() {
|
||||||
local file=$1
|
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"
|
sed "/variable is not set. Defaulting/d"
|
||||||
return "${PIPESTATUS[0]}"
|
return "${PIPESTATUS[0]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_files() {
|
check_files() {
|
||||||
local all_files=( "$@" )
|
local all_files=( "$@" )
|
||||||
has_error=0
|
has_error=0
|
||||||
for file in "${all_files[@]}" ; do
|
for file in "${all_files[@]}"; do
|
||||||
if [[ -f "$file" ]]; then
|
if [[ -f "$file" ]]; then
|
||||||
if ! check_file "$file" ; then
|
if ! check_file "$file"; then
|
||||||
echo "ERROR: $file"
|
echo "ERROR: $file"
|
||||||
has_error=1
|
has_error=1
|
||||||
fi
|
fi
|
||||||
@ -23,8 +44,8 @@ check_files() {
|
|||||||
return $has_error
|
return $has_error
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! check_files "$@" ; then
|
if ! check_files "$@"; then
|
||||||
echo "To ignore, use --no-verify"
|
echo "Some compose files failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit $has_error
|
exit $has_error
|
||||||
|
Loading…
Reference in New Issue
Block a user