簡體   English   中英

從私有 Bitbucket 安裝 NPM 模塊時主機密鑰驗證失敗

[英]Host key verification failed when installing NPM module from private Bitbucket

我正在嘗試從私有 Bitbucket 存儲庫安裝 NPM 模塊。

我可以在我的系統上本地成功運行npm install ,但它在服務器上失敗。

錯誤是:

npm ERR! Error while executing:
npm ERR! /bin/git ls-remote -h -t ssh://git@bitbucket.org/myorg/my-repo.git
npm ERR! 
npm ERR! 
npm ERR! (ssh-askpass:10260): Gtk-WARNING **: cannot open display: :0.0
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

奇怪的是,手動克隆服務器上的 repo 工作正常: git clone git@bitbucket.org:myorg/my-repo

因此 SSH 密鑰配置正確。

這應該表明 npm 命令不是使用與用於在服務器上手動克隆 repo 的帳戶相同的帳戶執行的。

在該 npm 帳戶中,需要先更新~/.known_hosts

我認為您是從 Docker 容器訪問它,因為您沒有從存在問題的 docker 容器添加 ssh 密鑰。 所以有兩種解決方案

  1. 公開您的 Git 存儲庫,這是不推薦的

  2. npm 在 jenkins 上安裝所有節點模塊,然后將所有節點模塊復制到 docker 容器。 (基本上不是從 package.json 在 Docker 容器上安裝 npm,而是在 Jenkins 上安裝,然后將這些模塊直接復制到容器

docker 文件中的更改將是

INITIALLY :
FROM node:12.10-alpine
WORKDIR /app
RUN apk update \
  && apk add git
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]


AFTER CHANGES :
FROM node:12.10-alpine
WORKDIR /app
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]

並在 Jenkins [in configure] 的 shell 腳本中添加

npm install

就是這樣,它應該工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM