diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..3fb6715a3f3fa09ef2df82dc581fe735d4e6d28b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!docker-compose-config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3e66e1d5821e755498f864e372ae1dbe23c29414 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +~* +*~ +*.sw[op] +*.py[cod] +.DS_Store +__pycache__/ +.vagrant/ +vendor/ +Thumbs.db +*.retry +.svn/ +.sass-cache/ +*.log +*.out +*.so +node_modules/ +.npm/ +nbproject/ +*.ipynb +.idea/ +*.egg-info/ +*.[ao] +.classpath +.cache/ +bower_components/ +*.class +*.[ewj]ar +secring.* +.*.kate-swp +.swp.* +.directory +.Trash-* +build/ +_build/ +dist/ +.tox/ +*.pdf +*.exe +*.dll +*.gz +*.tgz +*.tar +*.rar +*.zip +*.pid +*.lock +*.env +.bundle/ +!Pipfile.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..86bee1e3835452a87803c605d501b4340d807497 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +# vim:ff=unix ts=2 sw=2 ai expandtab +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.2.3 + hooks: + - id: check-added-large-files + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: detect-private-key + - id: trailing-whitespace + - repo: https://github.com/adrienverge/yamllint + rev: v1.16.0 + hooks: + - id: yamllint + - repo: https://github.com/amperser/proselint + rev: 0.10.2 + hooks: + - id: proselint + types: [plain-text] + exclude: LICENSE + - repo: https://www.shore.co.il/git/shell-pre-commit/ + rev: v0.6.0 + hooks: + - id: shell-lint + - id: shellcheck + - repo: local + hooks: + - id: hadolint + name: Hadolint Dockerfile linter + description: Dockerfile linter, validate inline bash, written in Haskell + minimum_pre_commit_version: '0.18.0' + language: docker + entry: hadolint + files: Dockerfile + - id: docker-compose + name: docker-compose config + description: Validate the Docker Compose file using docker-compose config + minimum_pre_commit_version: '0.18.0' + language: docker + entry: docker-compose-config + files: docker-compose + types: [ yaml ] diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 3db8dd5170f8fef8296a343b07ce1c60043aa497..a2a9e772d5a5aab93f95c03a29adbc29fe483f9e 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -6,10 +6,10 @@ minimum_pre_commit_version: '0.18.0' language: docker_image entry: adarnimrod/docker-pre-commit hadolint - files: Dockerfile + type: [ dockerfile ] - id: docker-compose name: docker-compose config - description: Validate the docker-compose file + description: Validate the Docker Compose file using docker-compose config minimum_pre_commit_version: '0.18.0' language: docker_image entry: adarnimrod/docker-pre-commit docker-compose-config diff --git a/Dockerfile b/Dockerfile index 0790b5a936991c9dc926c7637e2149ada44eafce..fae5c67e963982180f5a1a7ce83714ff93dcd628 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,3 +2,4 @@ FROM alpine:3.10 RUN apk add --update --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ docker-compose && \ wget https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-Linux-x86_64 -O /usr/local/bin/hadolint && \ chmod +x /usr/local/bin/hadolint +COPY docker-compose-config /usr/local/bin/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..17196c5e9c0a73784b3bb2ba6299933de5c80980 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Adar Nimrod + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b7f3bcf5efc514fc203300c55a8b8d0d6657554c --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Docker pre-commmit + +> Pre-commit hooks for Docker and docker-compose. + +## Requirements + +- [Docker](https://www.docker.com/). +- [pre-commit](https://pre-commit.com/) 0.18.0 or later. + +## Hooks + +- `hadolint` - The [hadolint](https://github.com/hadolint/hadolint) Dockerfile + linter. +- `docker-compose` - Validate the Docker Compose file using `docker-compose + config`. + +## Usage example + +```yaml +- repo: https://www.shore.co.il/git/docker-pre-commit + rev: v0.1.0 + hooks: + - id: hadolint + - id: docker-compose +``` + +## License + +This software is licensed under the MIT license (see `LICENSE.txt`). + +## Author Information + +Nimrod Adar, [contact me](mailto:nimrod@shore.co.il) or visit my [website]( +https://www.shore.co.il/). Patches are welcome via [`git send-email`]( +http://git-scm.com/book/en/v2/Git-Commands-Email). The repository is located +at: <https://www.shore.co.il/git/>. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..8acdd82b765e8e0b8cd8787f7f18c7fe2ec52493 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/docker-compose-config b/docker-compose-config new file mode 100755 index 0000000000000000000000000000000000000000..c83b51800cc769d2882dd8a25c5755e891fe0eca --- /dev/null +++ b/docker-compose-config @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +for filename in "$@" +do + docker-compose --file "$filename" config || failed=1 +done +[ "${failed:-0}" -eq '0' ]