-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerize pre-commit #190
Comments
I dockerized pre-commit and most of the tasks are running fine except running the project inside docker containers. This is running docker inside docker. There's a permission denied error when mounting the host directory to the container. |
Looks like my mistake was trying to take the shortcut and mount the host's docker socket into the container. When the container's docker-compose tries to do a bind mount of the container's path into the container's docker container, it tries to use the Anyway, the solution is to use an actual docker in docker (dind) setup. |
It feels like it's possible to do this with just mounting the host docker socket. It seems to work if I feed it with the host's path rather than the path inside the container. Progress was slow due to many image rebuilds. I attempted to use cache mounts but that seemed to have created problems. I'm now passing --no-cache to docker-compose build so it will do clean builds and show when a change breaks something. |
StatusI got to the point where pre-commit works from within the docker container. Link to branch in my fork. Here are some useful commands. Note: APP_PATH=`git rev-parse --show-toplevel`/app but I'm just pasting the commands that work for me. from host# build the pre-commit tools image
APP_PATH=/home/fang/src/peopledepot/app docker-compose build tools
# run an interactive shell in the container. Useful for working on small steps inside the container.
docker-compose run tools sh
# these next lines run pre-commit from inside the container
# run a single pre-commit hook
docker-compose run tools sh -c "pre-commit run --all-files check-django-migrations"
# run all the hooks
docker-compose run tools sh -c "pre-commit run --all-files" from container# build the app and run in the background
# pass in the host's app path even though we're in the container
APP_PATH=/home/fang/src/peopledepot/app ./scripts/buildrun.sh
# run the app in the foreground. useful for making sure it runs without errors
APP_PATH=/home/fang/src/peopledepot/app docker-compose up
# run pre-commit specifying a single hook. This hook requires the app to be running
APP_PATH=/home/fang/src/peopledepot/app pre-commit run --all-files check-django-migrations Next stepThe next step would be to create a pre-commit hook that calls the pre-commit in the container. Either it also has to set up the container or there needs to be a setup script to build the pre-commit image. Another option is to have the image built somewhere else and upload it to docker hub. But The first step should be to build it as a separate step and call it from the pre-commit hook script. |
Another option instead of dockerizing pre-commit is to ask developers to install it locally via pipx. pipx installs the package in an isolated environment rather than globally. Installing packages globally is a bad idea because of dependency conflict hell. pipx can be used to install other things like poetry. |
I think that the pipx option is a better one at this point. Even though I would like to dockerize everything, this one is a much greater effort than I anticipated and I think it will take more time to get right. I feel the strategic thing to do is to leave this for later and do #199 to solve the current issue. |
|
Overview
We need to dockerize pre-commit so that it's easily deployable for development.
Action Items
Resources/Instructions
The text was updated successfully, but these errors were encountered: