如何在GitHub操作中使用令牌从私有Git存储库安装NPM包 [英] How to install npm pckage from private git repoistory using a token in github actions

查看:3
本文介绍了如何在GitHub操作中使用令牌从私有Git存储库安装NPM包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Dockerfile中为我的应用程序安装NPM包。但是,在从私有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

文档文件

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"
  }
}

要从私有的Github存储库安装,我使用了用户名和令牌组合,正如您在我的Package.json中看到的那样。

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

此问题仅在GitHub操作管道中发生。

推荐答案

此问题仅在GitHub操作管道中发生。可以通过将persist-credentials设置为FALSE来解决此问题,否则它将使用GitHub操作令牌,该令牌没有拉取/安装存储库所需的权限。 。

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

https://github.com/actions/checkout

这篇关于如何在GitHub操作中使用令牌从私有Git存储库安装NPM包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆