1

We have multiple teams. Frontend and Backend. All Frontend devs have node on the computer, but not the Backend devs.

Husky (https://typicode.github.io/husky/#/) installs commit-Hooks. For the Backend devs we get the error message Can't find Husky, skipping pre-commit hook . (Because the have no nodeon their computer).

I don't want them to be forced install node, because we do all that stuff inside of a Docker-Container.

The .git/hooks look like that:

if [ -f "$scriptPath" ]; then
  # if [ -t 1 ]; then
  #   exec < /dev/tty
  # fi
  if [ -f ~/.huskyrc ]; then
    debug "source ~/.huskyrc"
    source ~/.huskyrc
  fi
  node_modules/run-node/run-node "$scriptPath" $hookName "$gitParams"

Or in later versions:

#!/bin/sh
if [ -z "$husky_skip_init" ]; then
  debug () {
    [ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
  }

  readonly hook_name="$(basename "$0")"
  debug "starting $hook_name..."

  if [ "$HUSKY" = "0" ]; then
    debug "HUSKY env variable is set to 0, skipping hook"
    exit 0
  fi

  if [ -f ~/.huskyrc ]; then
    debug "sourcing ~/.huskyrc"
    . ~/.huskyrc
  fi

  export readonly husky_skip_init=1
  sh -e "$0" "$@"
  exitCode="$?"

  if [ $exitCode != 0 ]; then
    echo "husky - $hook_name hook exited with code $exitCode (error)"
    exit $exitCode
  fi

  exit 0
fi

Can i somehow configure husky to that the startup script executes docker-compose run app ....? I want do run the actual script inside of the container, but I don't get husky itself to execute in the container.

Joe
  • 41,484
  • 20
  • 104
  • 125
Patrick
  • 1,562
  • 1
  • 16
  • 33
  • Does this answer your question? [Using Husky with Docker when no Node.js is available in local](https://stackoverflow.com/questions/61015181/using-husky-with-docker-when-no-node-js-is-available-in-local) – Joe Jun 14 '21 at 21:23

1 Answers1

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 

hudata
  • 31
  • 4