Working with Docker, I'm trying to make Husky work when there is Node.js in the container but no on the local machine.
As it will be triggered with git commands, with the info from here: "if you're running git commands in the terminal, husky will use the version defined in your shell PATH
", and this other: "Husky will source ~/.huskyrc
file if it exists before running hook scripts. You can use it, for example, to load a node version manager or run some shell commands before hooks."
Could something like changing the PATH
so it points to the Node.js that is in the container be a solution? If so, how could be done?
Thanks in advance!
Docker images can be inherited from other images. Therefore, instead of creating our own base image, we'll use the official Node. js image that already has all the tools and packages that we need to run a Node. js application.
No, it doesn't come with npm.
If I understand you right, I've solved the issue in two steps:
# at docker-compose.yaml
version: '3'
services:
app:
build:
...
volumes:
- /usr/bin/git:/usr/bin/git
# installing dependencies missing at guest (in my case, guest debian, host ubuntu)
- /lib/x86_64-linux-gnu/libpcre2-8.so.0:/lib/x86_64-linux-gnu/libpcre2-8.so.0
and 2. by running the hook command inside the container, for example:
# at .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# instead of only npx lint-staged
docker exec great-app npx lint-staged
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With