In 2014, Yelp launched pre-commit, a framework for managing pre-commit hooks. Since then, the community has contributed many different hooks to help with development in a wide variety of languages, including Python, Ruby, Go, Node.js, and Clojure. You can see a list of many of these here. Pre-commit has been invaluable in increasing the productivity of Yelp’s code base and code-reviews by making style issues a thing of the past and allowing us to easily check for broken and deprecated code usage with a variety of code linters.

While pre-commit supports a number of popular languages, the goal of pre-commit is to simplify writing pre-commit hooks in any language. Through system-level executable support this has been possible for a while, but this requires pre-commit hook users to manually go grab those programs. In addition to that, there are a number of languages it’s difficult to support multiple concurrent versions for, such as PHP.

We wanted to simplify the process so that users can easily run hooks created in any language without having to install new dependencies for each.

To accomplish this, pre-commit 0.10.0 adds support for Docker-based hooks. Docker’s ability to package dependencies alongside programs is perfectly suited to the task of supporting hooks across many different languages and even operating systems. While Docker is used by many for distributing long-running web applications, it’s also very capable of running command-line programs.

benp@yelp:~/eat24 $ docker run cogniteev/echo echo Raynor here.
Raynor here.

Creating a Docker-based hook is easy. You’ll need a git repo with two files: A Dockerfile, and a .pre-commit-hooks.yaml configuration.

With that, your hook can be used in a project exactly like any other pre-commit hook.

If you’re not using pre-commit in your projects yet, try it out! It’s a great way to enforce consistency before code reaches code review, whether it’s for an open- or closed- source project.

Read more about pre-commit at:

Back to blog