commit 6c87ff318d62cb955dcb934f95e9d1e49ffad5e4 Author: Benjamin Renard Date: Thu Feb 29 17:44:55 2024 +0100 Initial version diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..4b62525 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,6 @@ +[codespell] +ignore-words-list = equipments +skip = ./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf +quiet-level = 2 +ignore-regex = .*codespell-ignore$ + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0e3b925 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +# Pre-commit hooks to run tests and ensure code is cleaned. +# See https://pre-commit.com for more information +--- +repos: + - repo: https://github.com/codespell-project/codespell + rev: v2.2.2 + hooks: + - id: codespell + args: + #- --write-changes # Uncomment to write changes + - --config .codespellrc + exclude_types: [csv, json] + + - repo: https://github.com/digitalpulp/pre-commit-php.git + rev: 1.4.0 + hooks: + - id: php-stan + files: \.(php)$ + args: ["--configuration=phpstan.neon"] + + - repo: https://github.com/adrienverge/yamllint + rev: v1.32.0 + hooks: + - id: yamllint + args: ["-c", ".yamllint.yml"] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier + args: ["--print-width", "100"] diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..8ecafdb --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,6 @@ +--- +extends: default + +rules: + line-length: + max: 100 diff --git a/Dockerfile.common b/Dockerfile.common new file mode 100644 index 0000000..4b408c1 --- /dev/null +++ b/Dockerfile.common @@ -0,0 +1,8 @@ +RUN mkdir /src && \ + git config --global --add safe.directory /src +COPY .pre-commit-config.yaml .yamllint.yml .codespellrc fake_php_project /src/ +RUN cd /src && \ + git init && \ + git add * && \ + pre-commit run --all-files && \ + rm -fr /src diff --git a/Dockerfile.common.init b/Dockerfile.common.init new file mode 100644 index 0000000..3f4e8a5 --- /dev/null +++ b/Dockerfile.common.init @@ -0,0 +1,16 @@ +ENV PYTHON_APT_PACKAGES="python3-all python3-dev python3-pip python3-venv" +ENV PHP_APT_PACKAGES="composer php-apcu php-cli php-curl php-deepcopy php-gd php-gnupg php-imagick php-intl php-json php-ldap php-mbstring php-memcache php-mysql php-pgsql php-rrd php-xdebug php-xml php-xmlrpc php-yaml php-zip php-gmp" +ENV DEB_APT_PACKAGES="apt-file dpkg-dev fakeroot build-essential devscripts debhelper dh-python equivs" +ENV TOOLS_APT_PACKAGES="sed lsb-release gnupg2 curl jq git rsync gitdch wget ca-certificates openssh-client unzip" +ENV APT_PACKAGES="$PYTHON_APT_PACKAGES $PHP_APT_PACKAGES $DEB_APT_PACKAGES $TOOLS_APT_PACKAGES" + +ENV PIP_PACKAGES="pre-commit" + +RUN echo "deb http://debian.zionetrix.net stable main" > /etc/apt/sources.list.d/zionetrix.list && \ + apt-get -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true update && \ + apt-get -o APT::Get::AllowUnauthenticated=true install --yes zionetrix-archive-keyring && \ + apt-get update && \ + apt-get install --no-install-recommends -y $APT_PACKAGES && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + apt-file update diff --git a/Dockerfile.debian10 b/Dockerfile.debian10 new file mode 100644 index 0000000..ef6bec4 --- /dev/null +++ b/Dockerfile.debian10 @@ -0,0 +1,10 @@ +# syntax = edrevo/dockerfile-plus + +FROM debian:10-slim + +INCLUDE+ Dockerfile.common.init + +RUN python3 -m pip install -U pip && \ + python3 -m pip install $PIP_PACKAGES + +INCLUDE+ Dockerfile.common diff --git a/Dockerfile.debian11 b/Dockerfile.debian11 new file mode 100644 index 0000000..d063416 --- /dev/null +++ b/Dockerfile.debian11 @@ -0,0 +1,9 @@ +# syntax = edrevo/dockerfile-plus + +FROM debian:11-slim + +INCLUDE+ Dockerfile.common.init + +RUN python3 -m pip install $PIP_PACKAGES + +INCLUDE+ Dockerfile.common diff --git a/Dockerfile.debian12 b/Dockerfile.debian12 new file mode 100644 index 0000000..a251d53 --- /dev/null +++ b/Dockerfile.debian12 @@ -0,0 +1,9 @@ +# syntax = edrevo/dockerfile-plus + +FROM debian:12-slim + +INCLUDE+ Dockerfile.common.init + +RUN python3 -m pip install --break-system-packages $PIP_PACKAGES + +INCLUDE+ Dockerfile.common diff --git a/README.md b/README.md new file mode 100644 index 0000000..48c10e8 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# Docker image to run pre-commit on PHP apps/libraries + +Debian slim based images with common dependencies to run `pre-commit` on PHP apps/libraries: + +- `pre-commit` and `git` commands +- common PHP packages: `php-apcu php-cli php-curl php-deepcopy php-gd php-gnupg php-imagick php-intl php-json php-ldap php-mbstring php-memcache php-mysql php-pgsql php-rrd php-xdebug php-xml php-xmlrpc php-yaml php-zip php-gmp` +- common PHP tools: `composer` +- common Debian packages building tools: `apt-file dpkg-dev fakeroot build-essential devscripts debhelper dh-python equivs` +- common python packages: `python3-all python3-dev python3-pip python3-venv` +- common tools: `sed lsb-release gnupg2 curl jq rsync wget ca-certificates openssh-client unzip` +- [gitdch](https://gitea.zionetrix.net/bn8/gitdch) tool +- an initialized `pre-commit` environments in `/src` according to provided `.pre-commit-config.yaml` + example file. + +**Note:** Multiple tagged images are provided to allow test on the right Debian version you are +using in your production environment. Tags are named `debianX` with `XX` corresponding to the Debian +version. Currently supported Debian version: + +- `debian10` (Debian Buster) +- `debian11` (Debian Bullseye) +- `debian12` (Debian Bookworm) + +## Usage + +To use it: + +```bash +docker run \ + -it --rm \ + -v "$(pwd)":/src -w /src \ + brenard/php-pre-commit \ + pre-commit run --all-files +``` + +**Note:** To test your project with the provided `.pre-commit-config.yaml` file, use to following +command: + +```bash +docker run \ + -it --rm \ + -v "$(pwd)":/src -w /src \ + -v "$(pwd)/.pre-commit-config.yaml":/src/.pre-commit-config.yaml \ + brenard/php-pre-commit \ + pre-commit run --all-files +``` + +## Build + +```bash +# Need to use Dockerfile+ (https://github.com/edrevo/dockerfile-plus) +export DOCKER_BUILDKIT=1 +export COMPOSE_DOCKER_CLI_BUILD=1 + +for deb_version in 10 11 12 +do + docker build -t docker.io/brenard/php-pre-commit:debian${deb_version} -f Dockerfile.debian${deb_version} . +done +docker build -t docker.io/brenard/php-pre-commit:latest -f Dockerfile.debian${deb_version} . +``` + +## Publish + +```bash +for deb_version in 10 11 12 +do + docker push docker.io/brenard/php-pre-commit:debian${deb_version} +done +docker push docker.io/brenard/php-pre-commit:latest +``` diff --git a/fake_php_project/.gitignore b/fake_php_project/.gitignore new file mode 100644 index 0000000..7579f74 --- /dev/null +++ b/fake_php_project/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock diff --git a/fake_php_project/composer.json b/fake_php_project/composer.json new file mode 100644 index 0000000..efdef43 --- /dev/null +++ b/fake_php_project/composer.json @@ -0,0 +1,17 @@ +{ + "name": "brenard/fake_php_project", + "description": "Fake project", + "type": "project", + "autoload": { + "psr-4": { + "Brenard\\FakePhpProject\\": "src/" + } + }, + "authors": [ + { + "name": "Benjamin Renard", + "email": "brenard@easter-eggs.com" + } + ], + "require": {} +}