Skip to content

How to run pre-commit hook in docker container? #156

@heatherKoo07

Description

@heatherKoo07

Hi, I want to run pre-commit hook in my docker container as I moved my dev environment to the docker.

By default, pre-commit requires npm install in local environment to run ./node_modules/pre-commit/hook in .git/hooks/pre-commit script.

When I did some research, I found this link https://spectrum.chat/node/general/pre-commit-with-docker~840290ba-1cb6-40e2-a7ad-7566054638b8. I changed the first line of the pre-commit script manually as below and it worked as expected although it's quite slow.

#!/bin/bash
docker-compose run --rm web sh ./node_modules/pre-commit/hook # web is my docker-compose service name
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0

Is there a way to customize pre-commit script in configuration or something? (rather than manual change)

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions