如何使用私有 git 服务器 (SSH) 安装 Bower 包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24853847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:19:36  来源:igfitidea点击:

How to install a bower package using a private git server (SSH)?

gitsshbowerbower-install

提问by gremo

EDIT: this guy do exactly the same with success, can't figure out why it's not working for me.

编辑这个人对成功完全一样,无法弄清楚为什么它对我不起作用。

I've just installed gitand setup permissions/SSH authentication with public/private key (Centos 6.5). I'm able to pull/push without problems using i.e.:

我刚刚git使用公钥/私钥(Centos 6.5)安装并设置了权限/SSH 身份验证。我可以使用 ie 毫无问题地拉/推:

git clone [email protected]:projects/boilerplate-template

Username is git, code placed in /home/git/projects, repository created with git --init --shared boilerplate-template.

用户名是git,代码放置在/home/git/projects,使用git --init --shared boilerplate-template.

How can I require boilerplate-templatewith Bower in another project?

如何boilerplate-template在另一个项目中使用 Bower?

I've tried with the following bower.json file without luck:

我尝试使用以下 bower.json 文件但没有成功:

{
    "name": "my/newproject",
    "dependencies": {
        "boilerplate-template": "git://code.organization.com:projects/boilerplate-template"
    }
}

ECMDERR: Failed to execute "git ls-remote --tags --heads git://code.organization.com:projects/boilerplate-template, exit code 128 unable to lookup code.organization.com (port project)...

ECMDERR:无法执行“git ls-remote --tags --heads git://code.organization.com:projects/boilerplate-template,退出代码 128 无法查找 code.organization.com(端口项目)...

Sadly it fails because :projectis not the port but the path. I've also tried with ssh://instead of git://:

可悲的是它失败了,因为:project不是端口而是路径。我也试过用ssh://代替git://

ENOTFOUND: Package ssh://code.organization.com:projects/boilerplate-template not found.

ENOTFOUND:未找到包 ssh://code.organization.com:projects/boilerplate-template。

回答by gremo

Ok, found the solution here: Using Bower as the Package Management tool for Internal, Private Libraries. Simply remove git://or ssh://and add .gitsuffix:

好的,在这里找到了解决方案:Using Bower as the Package Management tool for Internal, Private Libraries。只需删除git://ssh://添加.git后缀:

"[email protected]:projects/boilerplate-template.git#~1"

回答by Scott Sword

Also, if you're using Github and Bower for a private repo you can create a .netrcfile if you need to run bower installon a remote server.

此外,如果您将 Github 和 Bower 用于私有存储库,您可以.netrc在需要bower install在远程服务器上运行时创建一个文件。

e.g. You have a DO droplet and need to checkout a git repo that uses ssh keys, but needs to run bower installwith some deps that are private. If you add the .netrcfile to your remote machine you will be good to go for deploys/builds.

例如,您有一个 DO droplet,需要签出一个使用 ssh 密钥的 git repo,但需要bower install使用一些私有的 deps运行。如果您将.netrc文件添加到远程计算机,则可以进行部署/构建。

// .netrc where someToken is generated in Github under Personal access token
machine github.com
    login userName
    password someToken

回答by Dehli

I had trouble getting bower loginworking, so I went with this approach. <TOKEN>is generated here. It works for private repositories hosted on Github.

我在bower login工作时遇到了麻烦,所以我采用了这种方法。<TOKEN>在这里生成的。它适用于托管在 Github 上的私有存储库。

"dependencies": {
    "your-package": "https://<TOKEN>:[email protected]/Account/Repository.git"
}

回答by embee

TeamCity had this issue for us when trying to download a private repo from GitHub. In case this helps anyone we solved it by using SSH and providing a GitHub Personal Access Tokenby running bower loginbefore bower install:

TeamCity 在尝试从 GitHub 下载私有存储库时遇到了这个问题。如果这可以帮助任何人,我们通过使用 SSH 并通过运行之前提供GitHub 个人访问令牌来解决它:bower loginbower install

Example dependency in bower.json:

bower.json 中的示例依赖项:

"repository": "[email protected]:Account/Repository.git"

Commands to run within build script:

在构建脚本中运行的命令:

bower login -t {GitHub Personal Access Token}
bower install

回答by silverbull

go to https://github.com/settings/tokens, generate your token

https://github.com/settings/tokens,生成你的令牌

bower login -t {your token} 

bower install

回答by Bamieh

You might face this issue if you are cloning from a private repo as well. The accepted answer is correct, however I want to clarify this concern:

如果您也从私人存储库进行克隆,则可能会遇到此问题。接受的答案是正确的,但我想澄清这个问题:

  1. if you have github SSH access to your machine, go to the git repo and copy the "clone with SSH" link, then place it inside the bower.json file.

  2. if you have https(login authentication) setup for github on your machine, copy the "clone with https" link, then place it inside the bower.json file. repository

  1. 如果你有 github SSH 访问你的机器,去 git repo 并复制“clone with SSH”链接,然后把它放在 bower.json 文件中。

  2. 如果您的机器上为 github 设置了 https(登录身份验证),请复制“clone with https”链接,然后将其放入 bower.json 文件中。存储库

Example: SSH link: [email protected]:Account/Repository.git HTTPS link: https://github.com/Account/Repository.git

示例:SSH 链接:[email protected]:Account/Repository.git HTTPS 链接:https: //github.com/Account/Repository.git

Bower.json file:

Bower.json 文件:

"dependencies": { 
 "repository": "paste SSH/HTTPS clone line here"
}

回答by James Hulse

As others have mentioned, setting the package location to:

正如其他人所提到的,将包位置设置为:

"[email protected]:projects/yourproject.git"

Will allow bower to pull from a git repository.

将允许 bower 从 git 存储库中提取。

If you get an SSH issue on Windows you can follow these steps:

如果您在 Windows 上遇到 SSH 问题,您可以按照以下步骤操作:

  1. Download the PuTTY tools
  2. Use PuttyGen to generate a new key.
  3. Save the private key to your users .ssh folder as anything.ppk
  4. Copy the text starting ssh-rsain putty gen to the clipboard
  5. Go to github and Settings -> SSH keys -> Add SSH keygiving your key a title and pasting the text from PuttyGen in to the key portion
  6. Add an environment variable named GIT_SSHwith the value being the path to the Putty tool PLINK.exe e.g. C:\Program Files\Putty\PLINK.exe
  7. Run the Putty tool "Pageant.exe" then add your anything.ppkkey to pageant (you can add a shortcut to your startup folder with C:\pathtopageant\pageant.exe C:\Users\myuser\.ssh\anything.ppkto automatically add the key to pageant on startup)
  8. Open putty.exeitself, enter your github enteprise hostname (code.organization.com in the above example), or "github.com" in the hostname textbox and click "Open". You will probably be prompted to trust the host, click yes to add it to your known_hosts file as bower is unable to do this on first run and would have just hung
  9. Finally run bower install!
  1. 下载 PuTTY 工具
  2. 使用 PuttyGen 生成新密钥。
  3. 将私钥保存到您的用户 .ssh 文件夹中 anything.ppk
  4. ssh-rsaputty gen 中的文本复制到剪贴板
  5. 转到 github 并Settings -> SSH keys -> Add SSH key为您的密钥命名并将 PuttyGen 中的文本粘贴到密钥部分
  6. 添加一个环境变量GIT_SSH,其值为 Putty 工具 PLINK.exe 的路径,例如C:\Program Files\Putty\PLINK.exe
  7. 运行 Putty 工具“Pageant.exe”,然后将您的anything.ppk密钥添加到 pageant(您可以在启动文件夹中添加快捷方式,以便在启动时C:\pathtopageant\pageant.exe C:\Users\myuser\.ssh\anything.ppk自动将密钥添加到 pageant)
  8. 打开putty.exe自己,在主机名文本框中输入您的 github 企业主机名(上例中的 code.organization.com)或“github.com”,然后单击“打开”。您可能会被提示信任主机,单击“是”将其添加到您的 known_hosts 文件中,因为 bower 在第一次运行时无法执行此操作并且会挂起
  9. 终于跑了bower install

回答by Michal Moravcik

I ended with following, although working only for private github repos.

我以跟随结束,虽然只为私人 github 存储库工作。

  1. Generate Github access token hereand set it as environment variable GITHUB_TOKEN

  2. Define shorthand resolver in .bowerrc:

    "shorthand_resolver": "https://${GITHUB_TOKEN}@github.com/{{owner}}/{{package}}.git"
    
  3. Now I can add my dependency as bower install me/my-private-packageor list it in bower.json:

    "dependencies": {
        "my-private-package": "me/my-private-package"
    }
    
  1. 在此处生成 Github 访问令牌并将其设置为环境变量GITHUB_TOKEN

  2. 在 中定义速记解析器.bowerrc

    "shorthand_resolver": "https://${GITHUB_TOKEN}@github.com/{{owner}}/{{package}}.git"
    
  3. 现在我可以将我的依赖项添加为bower install me/my-private-package或列出它bower.json

    "dependencies": {
        "my-private-package": "me/my-private-package"
    }
    

Works also for Heroku builds.

也适用于 Heroku 构建。