I am trying to run CaptainHookPHP in a Docker setup that might not be a usual setup but since the pre-built containers make some assumptions that differ from my use case I had to find a creative work-round.
Directory layout on the host:
./.git
./src/captainhook.json
Directory layout in container:
/var/www/.git
/var/www/html/captainhook.json
So basically everything stored locally in src get's mounted in html directory in the container. Since I use a pre-built container I can't do much about it. /var/www/html
is defined as the working directory in the Dockerfile.
This is what the configuration in my captainhook.json file looks like:
{
"config": {
"run-mode": "docker",
"run-exec": "docker-compose exec -w /var/www -T phpfpm",
"git-directory": "/var/www/.git/",
"run-path": "/var/www/html/vendor/bin/captainhook"
}
}
I had to explictly change the working directory of Docker when invoking the Git Hooks because CaptainHook assumes that the config file is stored in html/captainhook.json
not in captainhook.json
(as the command gets to be executed in /var/www/html
already thanks to the configured working directory in Docker). Interestingly also the hook install command get's triggered in /var/www/html
which at first made me assume that CaptainHookPHP would know where things are located.
The same issue occurs when executing action commands, e.g. some tool located in vendor/bin, I have to add the html/
prefix as well:
{
"action": "html/vendor/bin/phpcs --standard=Magento2 html/app/code/",
"options": []
}
As you can see, I need to apply the html/
prefix not only for the command I want to execute but also to path I want phpcs to examine.
Long story short, I think we do not only need a git-directory
config setting, but also a workdir-directory
config setting so that guessing the work directory can be ommited in cases where its needed.