Compare commits

...

20 Commits

Author SHA1 Message Date
IamTheFij d67a852ae8 Add test hooks with try-repo
continuous-integration/drone/push Build is passing Details
2023-10-26 14:56:42 -07:00
IamTheFij 6cf8fe749d Use personal drone-pre-commit image that has docker-compose binary installed
continuous-integration/drone/push Build is passing Details
2023-10-26 14:53:53 -07:00
IamTheFij f626253b23 Fix regex to match a literal dot before extension
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
Also simplifies the optional a match a bit.

Fixes #15
2023-04-19 09:19:08 -07:00
IamTheFij 15a900b1bb Use compose plugin language in documentation 2023-04-19 09:18:55 -07:00
IamTheFij 098ffc1472 Remove hadolint completely (inclusing script)
continuous-integration/drone/push Build is passing Details
2023-04-18 17:19:44 -07:00
IamTheFij 1acd61cff1 Remove hadolint completely
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2023-04-18 17:18:48 -07:00
IamTheFij 95effa7859 Add installation instructions
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
Fixes #11
2023-04-18 17:17:43 -07:00
IamTheFij 617b8880e4 Merge branch 'update-docker-compose-regex' of github.com:claha/docker-pre-commit into claha-update-docker-compose-regex
continuous-integration/drone/push Build is passing Details
2023-04-18 17:13:18 -07:00
M. R 3380d1a68e
Prefer docker compose v2
continuous-integration/drone/push Build is passing Details
2023-04-14 12:35:01 +01:00
Claes Hallström 5ed0959cc4 Update regex to also detect compose.yaml files
According to the new compose specification, compose.yaml is the
preferred file name.
2023-04-08 23:30:53 +02:00
Alex Hafner f16a4574c1
wrap "docker compose" command in quotes
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details
2022-05-19 12:28:39 +01:00
IamTheFij 71cd8ff86a Update compose-check to suport compose subcommand
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2022-03-04 15:57:05 -08:00
IamTheFij 5a0378fee5 Remove hadolint and add deprecation notice
continuous-integration/drone/push Build is passing Details
2021-04-09 10:11:11 -07:00
IamTheFij 9a22a2046c Merge remote-tracking branch 'github/master'
continuous-integration/drone/push Build is passing Details
2021-04-07 08:44:14 -07:00
IamTheFij 67b85ce990 Remove no-verify recommendation
Fixes #2
2021-04-07 08:42:35 -07:00
IamTheFij 86d69eafb9
Merge pull request #1 from lkwg82/patch-1
fixes link to hadolint
2021-04-06 10:40:27 -07:00
IamTheFij aeda358a4a Change drone steps
continuous-integration/drone/push Build is passing Details
2020-09-19 21:26:29 +00:00
IamTheFij 5c7dc7758b Add pre-commit hooks of our own
continuous-integration/drone/push Build is failing Details
Adds some basic near-universal checks and shellcheck
2020-09-19 20:07:34 +00:00
IamTheFij 9a0ea5ca85 Expand command line flags 2020-09-19 19:57:38 +00:00
Lars K.W. Gohlke 6cf90c5656
fixes link to hadolint 2020-09-13 19:35:08 +02:00
6 changed files with 61 additions and 35 deletions

View File

@ -9,11 +9,8 @@ workspace:
steps:
- name: test
image: python:3-slim
image: iamthefij/drone-pre-commit@sha256:6ed8dae6b0067bd2e145e36421bcfbbc68975ff7ddaa5a3f285b5bcdaf0989c8
commands:
- apt-get update
- apt-get install -y --no-install-recommends make shellcheck
- pip install docker-compose
- make all
- name: notify

14
.pre-commit-config.yaml Normal file
View 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

View File

@ -1,19 +1,7 @@
---
- 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.y[a]{0,1}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
files: (docker-)?compose\.ya?ml$

View File

@ -1,12 +1,8 @@
.PHONY: all test clean
all: test shellcheck
all: check test
test: test-negative test-positive
.PHONY: shellcheck
shellcheck:
shellcheck *.sh
test: test-negative test-positive test-hooks
.PHONY: test-positive
test-positive:
@ -19,3 +15,17 @@ test-negative:
./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

View File

@ -2,13 +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.
### 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.
Verifies that docker compose files are valid by using `docker compose config` to parse them.

View File

@ -1,10 +1,19 @@
#! /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]}"
}
@ -24,7 +33,7 @@ check_files() {
}
if ! check_files "$@" ; then
echo "To ignore, use --no-verify"
echo "Some compose files failed"
fi
exit $has_error