Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing NPM package from gitlab doesn't download all repo files only on CI

I'm using GitLab as my npm package repo. The project consuming this package is using an ssh url and targeting a specific tag. The entry in the consuming projects package.json looks like: "my-package": "git+ssh://[email protected]:company/repo.git#tag"

Now to clarify, this works just fine on my dev machine. I can wipe my node_modules and package-lock.json file, clear my npm cache, and do an npm i and my-package gets successfully built and installed.

The package.json for the my-package project has a prepare script used to build the package on install. It looks like this:

"scripts": {
    "prepare": "npm run build",
    "clean": "npx rimraf lib",
    "build": "npm run clean && tsc && npx gulp"
  },

my-package is in a private repo, and so to solve the initial permission issues, I had to create ssh keys, I added the public key to the my-package GitLab repo under the Deploy Keys section, as per these instructions https://docs.gitlab.com/ee/ssh/#deploy-keys.

The .gitlab-ci.yml file in the consuming project includes the private key into the ssh-agent like so:

before_script:
  - apk update
  - 'which ssh-agent || ( apk update -y && apk add openssh-client -y )'
  - mkdir -p ~/.ssh
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | ssh-add -
  - ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts

And I have no permission issues. The test stage on the cosuming projects CI looks like this:

test:
  stage: test
  script:
    - apk update
    - apk --no-cache add --update nodejs nodejs-npm git
    - npm install
    - ls node_modules/my-package/
    - npm run lint
    - npm run test

The strange thing is, the npm install doesn't download and build my-package here (like it does on my computer), it only installs the package.json and readme file. The result of the ls node_modeuls/my-package on the ci platform from above results in this:

$ ls node_modules/my-package/
package.json
readme.md

and of course since my package isn't being downloaded the tests fail to run that use that package.

I've tried a million different permutations of tweaks on both of the projects over the last 2 days. And nothing I do works on the CI platform (yet the whole time it always works locally 🧐). I'd really love to know what I'm overlooking, as since this works on my computer, then there has to be a way for it to work on the CI platform.

Any thoughts?

like image 426
BradStell Avatar asked Oct 16 '22 11:10

BradStell


1 Answers

I got it,

Solution, add this instruction

- npm config set unsafe-perm true

before yours

- npm install

unsafe-perm

Default: false if running as root, true otherwise

Type: Boolean Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

This did NOT work npm install --unsafe-perm

like image 197
Market Avatar answered Oct 20 '22 15:10

Market