Situation:
- In our CI we want to run
pre-commit inside Docker.
- Some of our hooks are
docker_image
Problem
This line mostly
|
'-v', f'{os.getcwd()}:/src:rw,Z', |
Currently pre-commit mounts the current directory to /src and uses current directory name as mount base.
However this does not work when pre-commit is run inside the container on some mounted path already, because mount points are relative to the host, not to the container.
Example:
/opt/my_code <- host, mounts /opt/my_code:/project
/project <- in Docker running pre-commit, pre-commit is doing mount /project:/src
/src <- (in Dockerized hook)
Currently pre-commit will try to mount it as -v /project:/src,rw,Z. Expected - to mount it as -v /opt/my_code:/src
Possible solution:
When I replaced os.getcwd() from the code above to translate_path(os.getcwd()) where translate_path is taken from https://gist.github.com/dpfoose/f96d4e4b76c2e01265619d545b77987a, it worked perfectly. It does add extra docker pip-dependency though.
See also: https://forums.docker.com/t/mounting-a-volume-not-working-with-running-docker-in-docker/25775/2
Situation:
pre-commitinside Docker.docker_imageProblem
This line mostly
pre-commit/pre_commit/languages/docker.py
Line 94 in 528c7af
Currently
pre-commitmounts the current directory to/srcand uses current directory name as mount base.However this does not work when
pre-commitis run inside the container on some mounted path already, because mount points are relative to the host, not to the container.Example:
Currently pre-commit will try to mount it as
-v /project:/src,rw,Z. Expected - to mount it as-v /opt/my_code:/srcPossible solution:
When I replaced
os.getcwd()from the code above totranslate_path(os.getcwd())wheretranslate_pathis taken from https://gist.github.com/dpfoose/f96d4e4b76c2e01265619d545b77987a, it worked perfectly. It does add extradockerpip-dependency though.See also: https://forums.docker.com/t/mounting-a-volume-not-working-with-running-docker-in-docker/25775/2