Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use gitlab repo in NPM with package.json

I'm working on a internal project and want to share a tools inside the group.

but if I use the npm tools. it either request the module has registered on npm website or public git repo.

I'm using gitlab. and there is a private token. git+https://gitlab-ci-token:\<private token>@<domain>/<username>/<repo_name>.git i tried to put it like this in package.json but it's not working.

Is there a way to install a private gitlab repo with authorization?

thanks a lot.

like image 909
Tomi Li Avatar asked Apr 06 '17 07:04

Tomi Li


People also ask

What is Verdaccio npm?

Verdaccio is a simple, zero-config-required local private npm registry. No need for an entire database just to get started! Verdaccio comes out of the box with its own tiny database, and the ability to proxy other registries (eg. npmjs.org), caching the downloaded modules along the way.

How use npm private package?

With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. Private packages always have a scope, and scoped packages are private by default.


1 Answers

If I understand your question correctly, you want your CI pipeline which runs npm to be able to pull a private project from your gitlab as a dependency.

In that case, you can use the deploy keys mechanism in gitlab for that (see here).

First generate a SSH key pair. You can use ssh-keygen -t rsa for that.

Then go to the private repository's gitlab page and locate the Deploy Keys setting. There you should paste the public key you just generated.

Then go to the project that runs npm in its CI and locate the Variables page. Create a new private variable with the name SSH_PRIVATE_KEY for instance and paste the private key you generated there.

Finally, in your .gitlab-ci.yml file add the following so that your private key will be available to your CI environment:

- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

Your CI environment should now be setup so that in can pull your private repository.

like image 100
Jawad Avatar answered Oct 17 '22 04:10

Jawad