Private GitLab repos as dependencies

Prerequisites

How to

  1. configure gitlab so it can be accessed despite being private
  2. and add it to a project

1. Configuring gitlab access

To allow third parties to use this dependency without giving them access to your entire gitlab account you can use a gitlab deploy token specific to the dependency repo.

You create the READ ONLY deploy token in the gitlab ui at repo > settings > repository > expand > deploy tokens. Make note of both the token name and the token.

2. Adding the dependency to a node project

The syntax for the url we need to add to the project is

git+https://{token-name}:{token}@gitlab.com/{Username}/{Repository}#{branch|tag}

We add it with yarn or npm, like with this example:

$ yarn add git+https://gitlab+deploy-token-84004:i43pm4EmzXQD6DLSzbsj@gitlab.com/djurensratt/labs/npm-module-test.git#master

Which adds it to packages.json:

// packages.json
// ...
  "dependencies": {
    "npm-module-test": "git+https://gitlab+deploy-token-84004:i43pm4EmzXQD6DLSzbsj@gitlab.com/djurensratt/labs/npm-module-test.git#master"
  }
// ...

Examples

References