chore: docker add mise hook

This commit is contained in:
engigu
2026-03-23 21:20:35 +08:00
parent c448cd747b
commit 2660d156f0
4 changed files with 38 additions and 0 deletions
+3
View File
@@ -147,7 +147,10 @@ COPY docker/docker-entrypoint.sh .
# Copy agent binaries to /opt/agent
COPY --from=agent-builder /opt/agent /opt/agent
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
RUN chmod +x docker-entrypoint.sh \
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
&& ln -sf /app/baihu /usr/local/bin/baihu
+3
View File
@@ -20,6 +20,9 @@ RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.li
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists/*
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
RUN cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc
RUN go env -w GOPROXY=https://goproxy.cn,direct
ENV MISE_GLOBAL_DIR=/opt/mise-dev
+3
View File
@@ -131,7 +131,10 @@ COPY docker/docker-entrypoint.minimal.sh ./docker-entrypoint.sh
# Copy agent binaries
COPY --from=agent-builder /opt/agent /opt/agent
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
RUN chmod +x docker-entrypoint.sh \
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
&& ln -sf /app/baihu /usr/local/bin/baihu
+29
View File
@@ -0,0 +1,29 @@
#!/bin/bash
# 面向终端的交互式 Hook 拦截器
# 目的是为了在终端手动执行 `mise exec node -- node xxx` 时也能具有与 Go 系统底层相同的 NODE_PATH 环境
mise() {
if [[ "$1" == "exec" || "$1" == "x" ]]; then
local is_node=false
for arg in "$@"; do
if [[ "$arg" == *"node"* ]]; then
is_node=true
break
fi
done
if [[ "$is_node" == true ]]; then
local node_bin=$(command mise which node 2>/dev/null)
if [[ -n "$node_bin" && "$node_bin" == *"/bin/node" ]]; then
# 截取路径并附加到当前进程执行环境的前置变量
NODE_PATH="${node_bin%/bin/node}/lib/node_modules" command mise "$@"
return $?
fi
fi
fi
# 非 Node 场景或拦截失败,正常向下执行
command mise "$@"
}
# 导出此函数,供所有子环境继承使用
export -f mise