在没有安装节点的情况下使用 Husky在 Docker 中使用

问题描述

我们有多个团队。 前端后端。所有前端开发人员在计算机上都有 node,但后端开发人员没有。

Husky (https://typicode.github.io/husky/#/) 安装 commit-Hooks。 对于后端开发人员,我们收到错误消息 Can't find Husky,skipping pre-commit hook 。 (因为他们的计算机上没有node)。

我不希望它们被强制安装节点,因为我们在 docker-container 内完成所有这些工作。

.git/hooks 看起来像这样:

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"

或在更高版本中:

#!/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

我能否以某种方式将 husky 配置为启动脚本执行 docker-compose run app ....? 我想在容器内运行实际的脚本,但我没有得到哈士奇本身 在容器中执行。

解决方法

如果我没听错的话,我已经分两步解决了这个问题:

  1. 通过与来宾共享来自主机的 git
# 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

和 2.通过在容器内部运行hook命令,例如:

# at .husky/pre-commit

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# instead of only npx lint-staged
docker exec great-app npx lint-staged 

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...