Vig*_*nte 3 npm jenkins docker
我正在尝试在 Jenkins 管道中自动化 docker 构建。在我的 dockerfile 中,我基本上构建了一个节点应用程序。在我的 npm 安装中,我有一些需要操作系统绑定的私有 git 存储库,因此必须安装在容器中。当我手动运行此命令时,我将 ssh 密钥 (id_rsa) 传输到用于执行 npm 安装的 dockerfile。现在,我的问题是在 jenkins 管道中运行此任务时,我将配置 ssh-agent(Jenkins 插件)。无法从 ssh-agent 中提取私钥。我应该如何将我的 ssh-agent 传递到我的 dockerfile。
编辑1:
我通过这个部分地工作了:
Docker Build Command:
DOCKER_BUILDKIT=1 docker build --no-cache -t $DOCKER_REGISTRY_URL/$IMAGE_NAME:v$BUILD_NUMBER --ssh default . &&
Run Code Online (Sandbox Code Playgroud)
然后在 Docker 文件中:
这工作正常:
RUN --mount=type=ssh GIT_SSH_COMMAND="ssh -vvvT -o StrictHostKeyChecking=no"
git clone git@github.com:****
Run Code Online (Sandbox Code Playgroud)
奇怪的是这不起作用:
RUN --mount=type=ssh GIT_SSH_COMMAND="ssh -vvvT -o StrictHostKeyChecking=no" npm install git+ssh//git@github.com:****
Run Code Online (Sandbox Code Playgroud)
我觉得这与StrictHostKeyChecking=no
我终于通过在 Dockerfile 中使用 ROOT 用户并将 npm 缓存设置为 root 使其工作。问题是 git 使用该/root/.ssh文件夹,而 npm 使用不同的路径 -/home/.ssh因为它的 npm 缓存已设置为/home/.ssh
对于仍在苦苦挣扎的人,这是我使用的配置
Docker 构建命令:
DOCKER_BUILDKIT=1 docker build --no-cache -t test --ssh default .
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
USER root
RUN apt-get update && \
apt-get install -y \
git \
openssh-server \
openssh-client
RUN mkdir -p -m 600 /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts && echo "Host *\n StrictHostKeyChecking no" > /root/.ssh/config
RUN echo "Check ssh_config" && cat /root/.ssh/config
RUN rm -rf node_modules
RUN npm config set cache /root
RUN --mount=type=ssh GIT_SSH_COMMAND="ssh -vvvT" npm install
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2264 次 |
| 最近记录: |