node.js - 如何使用 github actions 中的 token 从私有(private) git 存储库安装 npm 包

标签 node.js docker github npm github-actions

我正在尝试在 Dockerfile 中为我的应用程序安装 npm 包。但是,当我从私有(private) git 存储库安装包时,出现以下错误。

 Step 9/10 : RUN npm ci
 ---> Running in 57960fe4df81
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ***github.com/<redacted-private-org>/<redacted-private-repo>.git
npm ERR! 
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/<redacted-private-org>/<redacted-private-repo>.git/' not found
npm ERR! 
npm ERR! exited with error code: 128

Dockerfile

FROM node:12.18.0-alpine3.10

RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh

RUN mkdir -p /home/dev

WORKDIR /home/dev

COPY . /home/dev

RUN npm ci

CMD ["node", "api/api.js"]

package.json

{
  "name": "api",
  "version": "0.1.0",
  "author": "me",
  "license": "",
  "scripts": {
    "prestart": "",
    "start": "NODE_ENV=development nodemon ./api/server.js",
  },
  "dependencies": {
    "bcrypt-nodejs": "^0.0.3",
    "body-parser": "^1.18.2",
    "org-common-utils": "git+https://<redacted-username>:<redacted-token>@github.com/<redacted-private-org>/<redacted-private-repo>.git",
    "cors": "^2.8.4",
    "dotenv": "^8.2.0",
    "express": "^4.16.3",
    "express-routes-mapper": "^1.1.0",
    "helmet": "^3.12.0",
    "igdb-api-node": "^3.1.7",
    "jsonwebtoken": "^8.2.1",
    "mysql": "^2.16.0",
    "mysql2": "^1.6.4",
    "node-cache": "^4.2.0",
    "sequelize": "^5.21.3",
    "sqlite3": "^4.0.0",
  },
  "devDependencies": {
    "cross-env": "^5.1.4",
    "eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-plugin-import": "^2.18.0",
    "husky": "^0.14.3",
    "jest": "^22.4.3",
    "nodemon": "^1.17.3",
    "shx": "^0.2.2",
    "supertest": "^3.0.0"
  }
}

要从私有(private) Github 存储库安装,我使用用户名和 token 组合,如您在我的 package.json 中看到的那样。

存储库之所以存在,是因为如果我尝试导航到登录时它会加载的 URL https://github.com/redacted-private-org/redacted-private-repo

此问题仅发生在 github actions pipeline 中。

最佳答案

此问题仅发生在 github actions pipeline 中。通过将 persist-credentials 设置为 false 可以解决此问题,否则它将使用 github 操作 token ,该 token 没有拉取/安装存储库所需的权限。 .

- name: Checkout
  uses: actions/checkout@master
  with:
    persist-credentials: false

https://github.com/actions/checkout

关于node.js - 如何使用 github actions 中的 token 从私有(private) git 存储库安装 npm 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62407913/

相关文章:

docker - 为什么nextcloud在Docker中找不到数据库?

wordpress - github上的公共(public)密码

git - 上传一个空文件夹到github

git - OpenSSL SSL_connect : Connection was reset in connection to github. com:443

javascript - 循环不适用于间隔

c# - 从 Visual Studio 2017 调试 .Net Core 控制台应用程序

node.js - 从Angle 8向Express.js后端Docker容器发送HTTP请求时,跨域请求被阻止(原因:CORS请求未成功)

node.js - 如何仅获取给定用户 Express.js 的文章

node.js - 在 cassandra 中更新具有大量数据(8000 万行以上)的表中的列

javascript - MongoDB 查询优化