简体   繁体   English

NPM 从私有 GitLab 存储库中提取

[英]NPM to pull from private GitLab repository

I have a GitLab domain, project and repo.我有一个 GitLab 域、项目和存储库。 This project is accessible via a group I am apart of.这个项目可以通过我所在的一个小组访问。

I would like for this to be downloaded via npm install in the following ways:我希望通过以下方式通过npm install下载它:

  • Local computer本地计算机
  • GitLab CI job GitLab CI 工作
  • Inside of a Docker container Docker 容器内部

I'm guessing the easiest way of doing this is to just make it public.我猜最简单的方法就是公开它。 Is there a way to fix this so it is secure.有没有办法解决这个问题,所以它是安全的。 I can imagine that it must be done with keys.我可以想象它必须用钥匙来完成。

In my package.json under dependencies I currently have this, but it gives a 401 error of course:在依赖项下的package.json ,我目前有这个,但它当然会给出 401 错误:

"my-module": "my-domain.com:my-project/my-repo#my-branch",

I do not want hardcoded tokens in the package.json file, if it can be avoided.如果可以避免的话,我不想在package.json文件中使用硬编码的令牌。

You can use SSH keys to access your repository.您可以使用 SSH 密钥访问您的存储库。 Add ssh keys to GitLab server and define url to your repsitory in following form:将 ssh 密钥添加到 GitLab 服务器并以以下形式定义您的存储库的 url:

git+ssh://git@git.mydomain.com:Username/Repository#{branch|tag}

or或者

git+ssh://git@git.mydomain.com/Username/Repository#{branch|tag}

In your package.json it will be something like this "my-module": "git+ssh://git@my-domain.com:my-project/my-repo#my-branch"在您的package.json ,它将类似于"my-module": "git+ssh://git@my-domain.com:my-project/my-repo#my-branch"

If your ssh key is password protected, then npm will ask for password.如果您的 ssh 密钥受密码保护,则 npm 将要求输入密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM