Sign inSign up

ifoodhub/pre-commit

By ifoodhub

Updated almost 4 years ago

Image
0

10K+

ifoodhub/pre-commit repository overview

pre-commit

A framework for managing and maintaining multi-language pre-commit hooks.

Documentation: https://pre-commit.com

Usage

Map your local project to the container's /project directory. Example:

docker run --rm \
    -v /path/to/repository:/project \
    ifoodhub/pre-commit:2 \
    pre-commit run --all-files --verbose
Jenkins

Example stage for Jenkins' declarative pipeline:

stages {
    stage('Lint') {
        agent {
            docker {
                image 'ifoodhub/pre-commit:2'
                args '-u 0:0'  // Avoid permission-related errors
            }
        }

        steps {
            sh 'pre-commit run --all-files --verbose --color always'
        }
    }
}
GitLab CI

Example job for .gitlab-ci.yml:

pre-commit:
  stage: lint
  image: ifoodhub/pre-commit:2
  script:
    - pre-commit run --all-files --verbose --color always
GitHub Actions

Example job for GitHub Actions:

jobs:
  pre-commit:
    name: pre-commit
    runs-on: ubuntu-2
    container:
      image: ifoodhub/pre-commit:2
    steps:
      - uses: actions/checkout@v1
      - name: Run pre-commit
        run: |
          pre-commit run --all-files --verbose --color always

Tips

Depending on your hooks you may want to use the Debian-based image (e.g. pre-commit:2-debian).

For example, the markdownlint hook installs a pre-compiled NodeJS binary that requires glibc, which is not shipped with Alpine-based images (e.g. latest, 2-alpine, etc).

Environment variables

This image doesn't expect any specific environment variables, but you can use any Python-related one.

For example, in CI/CD pipelines you should set PYTHONUNBUFFERED to ensure the pre-commit output will be immediately dumped, avoiding unordered messages in your build logs:

pre-commit:
  stage: lint
  image: ifoodhub/pre-commit:2
  variables:
    PYTHONUNBUFFERED: "1"
  script:
    - pre-commit run --all-files --verbose --color always

Tag summary

Content type

Image

Digest

sha256:22b1ffca2

Size

86.3 MB

Last updated

almost 4 years ago

docker pull ifoodhub/pre-commit