如何使用私有 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
How to install a bower package using a private git server (SSH)?
提问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 git
and 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-template
with 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 :project
is 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 .git
suffix:
好的,在这里找到了解决方案: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 .netrc
file if you need to run bower install
on 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 install
with some deps that are private. If you add the .netrc
file 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 login
working, 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 login
before bower install
:
TeamCity 在尝试从 GitHub 下载私有存储库时遇到了这个问题。如果这可以帮助任何人,我们通过使用 SSH 并通过运行之前提供GitHub 个人访问令牌来解决它:bower login
bower 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:
如果您也从私人存储库进行克隆,则可能会遇到此问题。接受的答案是正确的,但我想澄清这个问题:
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.
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
如果你有 github SSH 访问你的机器,去 git repo 并复制“clone with SSH”链接,然后把它放在 bower.json 文件中。
如果您的机器上为 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 问题,您可以按照以下步骤操作:
- Download the PuTTY tools
- Use PuttyGen to generate a new key.
- Save the private key to your users .ssh folder as
anything.ppk
- Copy the text starting
ssh-rsa
in putty gen to the clipboard - Go to github and
Settings -> SSH keys -> Add SSH key
giving your key a title and pasting the text from PuttyGen in to the key portion - Add an environment variable named
GIT_SSH
with the value being the path to the Putty tool PLINK.exe e.g.C:\Program Files\Putty\PLINK.exe
- Run the Putty tool "Pageant.exe" then add your
anything.ppk
key to pageant (you can add a shortcut to your startup folder withC:\pathtopageant\pageant.exe C:\Users\myuser\.ssh\anything.ppk
to automatically add the key to pageant on startup) - Open
putty.exe
itself, 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 - Finally run
bower install
!
- 下载 PuTTY 工具
- 使用 PuttyGen 生成新密钥。
- 将私钥保存到您的用户 .ssh 文件夹中
anything.ppk
- 将
ssh-rsa
putty gen 中的文本复制到剪贴板 - 转到 github 并
Settings -> SSH keys -> Add SSH key
为您的密钥命名并将 PuttyGen 中的文本粘贴到密钥部分 - 添加一个环境变量
GIT_SSH
,其值为 Putty 工具 PLINK.exe 的路径,例如C:\Program Files\Putty\PLINK.exe
- 运行 Putty 工具“Pageant.exe”,然后将您的
anything.ppk
密钥添加到 pageant(您可以在启动文件夹中添加快捷方式,以便在启动时C:\pathtopageant\pageant.exe C:\Users\myuser\.ssh\anything.ppk
自动将密钥添加到 pageant) - 打开
putty.exe
自己,在主机名文本框中输入您的 github 企业主机名(上例中的 code.organization.com)或“github.com”,然后单击“打开”。您可能会被提示信任主机,单击“是”将其添加到您的 known_hosts 文件中,因为 bower 在第一次运行时无法执行此操作并且会挂起 - 终于跑了
bower install
!
回答by Michal Moravcik
I ended with following, although working only for private github repos.
我以跟随结束,虽然只为私人 github 存储库工作。
Generate Github access token hereand set it as environment variable
GITHUB_TOKEN
Define shorthand resolver in
.bowerrc
:"shorthand_resolver": "https://${GITHUB_TOKEN}@github.com/{{owner}}/{{package}}.git"
Now I can add my dependency as
bower install me/my-private-package
or list it inbower.json
:"dependencies": { "my-private-package": "me/my-private-package" }
在此处生成 Github 访问令牌并将其设置为环境变量
GITHUB_TOKEN
在 中定义速记解析器
.bowerrc
:"shorthand_resolver": "https://${GITHUB_TOKEN}@github.com/{{owner}}/{{package}}.git"
现在我可以将我的依赖项添加为
bower install me/my-private-package
或列出它bower.json
:"dependencies": { "my-private-package": "me/my-private-package" }
Works also for Heroku builds.
也适用于 Heroku 构建。