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

8

54

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 clone [email protected]:projects/boilerplate-template

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

How can I require boilerplate-template with Bower in another project?

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

{
    "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)...

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

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

Fung answered 20/7, 2014 at 18:59 Comment(0)
F
68

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:

"[email protected]:projects/boilerplate-template.git#~1"
Fung answered 20/7, 2014 at 20:32 Comment(4)
I got this error 'ssh: connect to host github.com port 22: Connection refused' and help.github.com/articles/using-ssh-over-the-https-port helpedLaraelaraine
Any idea where bower looks for your private key on windows?Fimbria
In the user .ssh folderFung
wow, bower.json not same syntaxe than package.json....love front end!Kindness
C
11

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.

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.

// .netrc where someToken is generated in Github under Personal access token
machine github.com
    login userName
    password someToken
Callisto answered 26/9, 2014 at 22:54 Comment(0)
S
9

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.

"dependencies": {
    "your-package": "https://<TOKEN>:[email protected]/Account/Repository.git"
}
Satisfy answered 22/3, 2016 at 16:36 Comment(1)
Some of the other methods did not work on different machines in my office but this one worked consistently! (thankyou!!!)Unimposing
D
6

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 Token by running bower login before bower install:

Example dependency in bower.json:

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

Commands to run within build script:

bower login -t {GitHub Personal Access Token}
bower install
Devoir answered 13/10, 2015 at 18:7 Comment(0)
P
3

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

bower login -t {your token} 

bower install
Practitioner answered 19/1, 2016 at 17:1 Comment(1)
This won't work: github.com/bower/bower/issues/2317#issuecomment-230050330Pearman
T
2

As others have mentioned, setting the package location to:

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

Will allow bower to pull from a git repository.

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

  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-rsa in putty gen to the clipboard
  5. 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
  6. 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
  7. Run the Putty tool "Pageant.exe" then add your anything.ppk key to pageant (you can add a shortcut to your startup folder with C:\pathtopageant\pageant.exe C:\Users\myuser\.ssh\anything.ppk to automatically add the key to pageant on startup)
  8. 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
  9. Finally run bower install!
Thermic answered 5/7, 2016 at 11:23 Comment(0)
G
2

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

  1. Generate Github access token here and 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-package or list it in bower.json:

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

Works also for Heroku builds.

Grivation answered 2/8, 2016 at 11:20 Comment(0)
U
1

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

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

Bower.json file:

"dependencies": { 
 "repository": "paste SSH/HTTPS clone line here"
}
Unnerve answered 8/10, 2015 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.