chore: docker add mise hook
This commit is contained in:
@@ -147,7 +147,10 @@ COPY docker/docker-entrypoint.sh .
|
|||||||
# Copy agent binaries to /opt/agent
|
# Copy agent binaries to /opt/agent
|
||||||
COPY --from=agent-builder /opt/agent /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 \
|
RUN chmod +x docker-entrypoint.sh \
|
||||||
|
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
|
||||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
||||||
&& ln -sf /app/baihu /usr/local/bin/baihu
|
&& ln -sf /app/baihu /usr/local/bin/baihu
|
||||||
|
|
||||||
|
|||||||
@@ -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 \
|
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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
|
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
ENV MISE_GLOBAL_DIR=/opt/mise-dev
|
ENV MISE_GLOBAL_DIR=/opt/mise-dev
|
||||||
|
|||||||
@@ -131,7 +131,10 @@ COPY docker/docker-entrypoint.minimal.sh ./docker-entrypoint.sh
|
|||||||
# Copy agent binaries
|
# Copy agent binaries
|
||||||
COPY --from=agent-builder /opt/agent /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 \
|
RUN chmod +x docker-entrypoint.sh \
|
||||||
|
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
|
||||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
||||||
&& ln -sf /app/baihu /usr/local/bin/baihu
|
&& ln -sf /app/baihu /usr/local/bin/baihu
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user