Yarn: unable to clone private github repo. ssh: Could not resolve hostname github: nodename nor servname provided, or not known - npm

I have a private repo on github with dependencies on other private github repos and npm install installs all the dependencies without problems.
I installed Yarn (on MacOS) and tried to run yarn in the command line, but it failed cloning the private dependencies with the following error:
ssh: Could not resolve hostname github: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
How do I make yarn install the modules? Thanks!

Yarn#0.16.0 works by replacing the url of type
"private-test": "git+ssh://git#github.com:ramasilveyra/private-test.git#d6c5789"
with
"private-test": "git+ssh://git#github.com/ramasilveyra/private-test.git#d6c5789"
Replace : colon with / to make it work.

For now Yarn doesn't support installation from private package and private github repo
There is a workaround provided by Milos Ivanovic:
If you add the following to your ~/.ssh/config file:
Host github.com
User git
you can force all logins to github.com via SSH to use the user git by >default, and this makes yarn able to clone from
private repositories when using the ssh://github.com//
source format.
Fortunately this is just a matter of time before yarn support private repo on github, as there is already a pull request for it.

Related

Cannot clone from gitlab with SSH

I recently installed gitlab on an ubuntu 18.04 LTS instance. I am trying to clone a repo from GitLab.
My ssh config file is as below :
# ~/.ssh/config
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_ed25519
TCPKeepAlive yes
IdentitiesOnly yes
I have added the ed25519 public key to SSH keys in GitLab. When I try to clone the repo i get this issue-
$ git clone git#xxxx:root/test-project.git
Cloning into 'test-project'...
kex_exchange_identification: read: Connection reset by peer
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What am I doing wrong? I have checked out a couple of links on the internet but I cant figure out what I have done wrong.
I am able to clone and push if I use http instead of ssh.
git clone http://xxxx/root/test-project.git
Cloning into 'test-project'...
warning: You appear to have cloned an empty repository.
Why does http work and not ssh?
You have your ssh clone statement wrong: git clone username git#example.com:root/test.git
That statement would try to clone a repository named username into the location relative to your current path, git#example.com:root/test.git.
You want to leave out username:
git clone git#example.com:root/test.git
One alternative is Using sourcetree it will hit all the git clone and update command for you in just a click and also gives you a rich graphical representation on your repo and branches

Git Extensions Authentication Error

I just downloaded git extensions. It is configured to use putty that comes with the installation. I used putty to create a private and public key and I have the agent started and I have added the private key.
I am using bitbucket and I have loaded my public key to my bitbucket account.
I get the ssh clone link from bitbucket and go to clone it in git extensions, I load the SSH key and hit clone and I get this error message.
Error Message
I have an SSH key loaded. Why is it saying I need to load a key? I uninstalled gitextensions and generated different keys. I looked at all the settings, i'm not sure what i'm doing wrong.
Git Extensions SSH settings
Windows 10
Putty 0.70
Git extensions 2.51.01
bitbucket.org
I found the answer.
When you copy past the git command from bitbucket, it is the wrong syntax for git Extensions.
You will copy something like this:
git clone git#bitbucket.org:guitardenver/led-pad-pcb.git
But you need to remove the "git clone" part for it to work with git Extensions.
git#bitbucket.org:guitardenver/led-pad-pcb.git

How to use yarn with private npm registry in Sonatyoe Nexus OSS?

I ve setup the nexus oss 3 and it looks cool. All my projects are installed by using yarn because of the --pure-lockfile option.
Steps to reproduce the issue:
1. Setup nexus oss 3 with a private npm registry (as in documentation)
2. Disable anonymous access from nexus oss 3 admin panel
3. On a linux server with alpine try to yarn install --pure-lockfile (you must have a package that is hosted on the private repo in package.json)
4. Does not work, return 401 error
I tried everything but i could not manage to make yarn to login to get those packages.
If i use npm install, it works.
Can someone tell me how to make yarn work nexus oss3 using the setup from above?
If npm install is working, then you must have login credentials and repository correctly defined.
Open terminal and run npm login, give your username and password for nexus account. This will create a file ~/.npmrc. Open this file nano ~/.npmrc, output look like
//<repository>:_authToken=NpmToken.<token>
A dummy example:
//test.server.com/repository/npm-group/:_authToken=NpmToken.123456-12345-12345-tok-en0onum
Go to the project directory cd <project_dir>, create a new file .yarnrc, open it nano .yarnrc. Insert the following line, save and exit (Ctrl+O, Ctrl+X) it.
registry "<repository>"
Create another file .npmrc in the same directory <project_dir>. Open, add the following line, save and exsit.
registry=<repository>
always-auth=true
//<repository>:_authToken=NpmToken.<token>
Delete the .npmrc at home directory rm ~/.npmrc.
Now you can download node_modules with yarn or yarn install.
I had same issue with nexus 3 and use this configuration on my .npmrc file:
registry=https://your.nexus.com/repository/some-npm/
always-auth=true
/* basic-auth-token: your user:password in base64 */
_auth=<basic-auth-token>
Hope this help you!
The fact that your requests returns 401 (Unauthorized) means that you should supply credentials when connecting to Nexus.
It is far from being a nice solution but I got it working using
yarn set registry https://user:pwd#your.nexus.host/nexus3/repository/npmjs/
I use yarn 1.4.0 (release candidate). It should also work on 1.3.2, but I cannot test that because 1.3.2 has issues with HTTPS_PROXY env vars.

Bluemix node buildpack and modules in private repos

My node.js app uses a number of private shared modules hosted in git repos. I use git URLs like below in the dependencies block in package.json:
"xxx-accountMgr": "git+ssh://git#github.xxx.ibm.com:xxx/lib-account-mgr.git",
when "cf push" this errors during npm install on ssh:
npm ERR! git clone --template=/home/vcap/.npm/_git-remotes/_templates --mirror ssh://git#github.xxx.ibm.com/ipaas/lib-account-mgr.git /home/vcap/.npm/_git-remotes/ssh-git-github-xxx-ibm-com-xxx-lib-account-mgr-git-bf65c10c: ssh: Could not resolve hostname github.xxx.ibm.com: Name or service not known
i expected this as I haven't configured the ssh key in bluemix. is that possible? if not, what's the alternative to install modules from a private repo in bluemix?
If you are downloading a private module hosted on Git, you should be able to use https protocol (with creds) to access it.
There is a trick that could help avoid this issue if that is not an option for you:
1) Package private modules with your application (in node_modules)
2) Move the private modules to devDependencies in package.json, rather than dependencies, so that your local dev workflow is unaffected.
npm install will install dependencies and devDependencies. By
default, Bluemix will only install dependencies
Step 2 is necessary because even if you package the private node_modules with your application, staging for your application will fail because npm still tries to access your private repo to validate the dependency.
Also, if you had a .cfignore file ignoring the entire node_modules directory, that would have to be changed to ignore only the public modules.
If the private repo requires Github authentication to access the shared mdoules, Bluemix won't be able to access them. You can use a command such as git clone https://github.com/repo/etc but that will require the files to be accessible without authentication.
An alternative could be to manual install the files in your repo prior to using cf push so they are available. This is not a great solution but it will solve the problem in the short term.
The problem here is that Bluemix cannot reach back into the corporate network which is apparently where your github repo lives.
It has nothing to do with authentication, although what the others say here is accurate for publically accessible git repositories
This is a workaround what works for me is to use npmjs private modules. On one hand it will work and on the other hand it is really easy to manange versions, and reuse code. Of course you'll need to make some minor changes, but is totally worth it.
Upgrade your npmjs account to use private modules: https://www.npmjs.com/private-modules
On your computer log in to npmjs:
npm login
Publish your modules
Copy your npmrc file to your project:
cp ~/.npmrc /path/to/your/project
npm install your_module --save
Enjoy!
Be aware that if you ever change your password the token inside .npmrc will be revocated.
The token is not derived from your password password, but changing
your password will invalidate all tokens. The token will be valid
until the password is changed. You can also invalidate a single token
by logging out on a machine that is logged in with that token.
Source: https://docs.npmjs.com/private-modules/ci-server-config#checking-in-your-npmrc
You can also use cfnpm module (https://www.npmjs.com/package/cfnpm) it is designed to deal with private package in cliud foundry

How to "repo init" on a disconnected system?

I have mirrored a repository with
repo init -u <uri of manifest> --mirror
repo sync
and copied it (by usb) to a system disconnected from the internet along with the repo script and the repo clone bundle repository from https://gerrit.googlesource.com/git-repo/clone.bundle.
I now want to create new client from the mirror, but when I run the command.
repo init -u <uri of manifest on mirror>
i get the following error.
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno -2] Name or service not known
So I have the clone.bundle but have no way to persuade repo to use it.
Any suggestions?
There is an option, that appears to be totaly undocumented on the internet for repo. It is --repo-url which allows you to overide where repo looks for the latest version of itself.
This is what I did:
I had the bundle saved in my home as git-repo-clone.bundle
repo init -u < uri of manifest on mirror > --repo-url ~/git-repo-clone.bundle
I found this out by reading the repo script itself, and thought I would share.
There is an option to ignore the clone bundle.
repo init -u <your-manifest-mirror-url> --no-clone-bundle