我一直在嘗試除錯這個超級奇怪的問題。有一個專案,我正在嘗試使用npm命令安裝私有存盤庫。
當它在現有專案中時這不起作用,但當它是一個剛創建的新專案時npm init。
現有專案在/app,新專案在/opt(用于測驗目的)
運行npm add git ssh://[email protected]:company/repository.git在/app與回報:
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://[email protected]/company/repository.git
npm ERR! [email protected]: Permission denied (publickey).
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! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-11-24T00_25_10_559Z-debug.log
從/opt專案運行完全相同的命令可以正確安裝包,沒有任何問題。
我正在從一個openssh已安裝的 alpine docker box 運行它。
這是 Dockerfile
FROM node:16.13-alpine
RUN apk add --no-cache openssh-client git python2
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts && ln -s /run/secrets/ssh_key ~/.ssh/id_rsa && ln -s /run/secrets/ssh_pub_key ~/.ssh/id_rsa.pub
RUN mkdir /app
WORKDIR /app
一些更多的資訊
/app # node -v
v16.13.0
/app # npm -v
8.1.4
/app # ssh -T [email protected]
Hi AzaZPPL! You've successfully authenticated, but GitHub does not provide shell access.
package.json
{
"name": "project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"generate-schema": "node apollo/generate-schema.js",
"lint": "eslint --ext .js,.vue --ignore-path .eslintignore .",
"lintfix": "eslint --fix --ext .js,.vue --ignore-path .eslintignore ."
},
"dependencies": {
"@nuxtjs/apollo": "^4.0.1-rc.4",
"@nuxtjs/auth": "^4.9.1",
"@nuxtjs/axios": "^5.12.2",
"@nuxtjs/dayjs": "^1.2.1",
"@nuxtjs/style-resources": "^1.0.0",
"apollo-cache-inmemory": "^1.6.6",
"copy-to-clipboard": "^3.3.1",
"core-js": "^3.6.5",
"date-fns": "^2.19.0",
"dotenv": "^8.2.0",
"filepond": "^4.27.1",
"filepond-plugin-file-validate-type": "^1.2.6",
"filepond-plugin-image-preview": "^4.6.6",
"graphql-tag": "^2.11.0",
"js-file-download": "^0.4.12",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.20",
"nuxt": "^2.14.6",
"nuxt-buefy": "^0.4.10",
"nuxt-i18n": "^6.15.4",
"vee-validate": "^3.4.3",
"vue": "^2.6.12",
"vue-filepond": "^6.0.3"
},
"devDependencies": {
"@babel/eslint-parser": "^7.16.3",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-vue": "^7.1.0",
"prettier": "^2.1.2",
"sass": "^1.32.8",
"sass-loader": "^12.3.0"
}
}
關于這里發生了什么的任何想法?
uj5u.com熱心網友回復:
嘗試在您的 Dockerfile 中設定
ENV GIT_SSH_COMMAND='ssh -Tv'
這應該會為您提供更多關于為什么在npm add.
uj5u.com熱心網友回復:
在@VonC 的回答的幫助下,我能夠弄清楚發生了什么。
仔細查看日志,我發現實際上有一個名為的用戶node在運行時使用npm。在 Alpine 映像的 Dockerfile 中,正在創建此用戶并npm配置為使用此用戶。
因此,每當我登錄 docker 容器時,我都以root用戶身份登錄,并且所有在 Dockerfile 中設定的 ssh 密鑰都由root用戶運行。
運行ssh -T [email protected]作業,因為root用戶設定正確但不是node用戶
我仍然無法理解的是為什么在/opt檔案夾中運行命令有效?無論如何,這是一個不同的日子的謎。
這是我更新的 Dockerfile。我設定了SSH密鑰的node用戶和登錄的node用戶
FROM node:16.13-alpine
RUN apk add --no-cache openssh-client git
RUN mkdir /app && chown node:node /app
USER node
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN ln -s /run/secrets/ssh_key ~/.ssh/id_rsa
WORKDIR /app
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/364659.html
上一篇:Cors錯誤strict-origin-when-cross-originsimplenodeJS-reactJS專案
