Using Husky with Docker when no Node.js is available in local
Asked Answered
M

1

7

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!

Minaret answered 3/4, 2020 at 15:25 Comment(0)
R
1

If I understand you right, I've solved the issue in two steps:

  1. by sharing git from the host with the guest
# 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 

Riha answered 14/6, 2021 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.