V
V
Valery2021-09-30 15:43:26
Node.js
Valery, 2021-09-30 15:43:26

How to do NPM install when building docker image for build in gitlab ci?

Automated node.js build in .gitlab-ci.yml in this way:

build:
    stage: build
    image: trion/ng-cli:latest
    script:
      - npm ci --loglevel verbose
      - ng build --prod --aot --output-hashing=all --serviceWorker
    artifacts:
      expire_in: 60 minutes
      paths:
        - ./dist/webpp
    interruptible: true
    tags:
      - docker
    only:
    - stage

Everything works but every time npm install takes time.
I want to optimize this process and install npm in docker itself, I
tried to build the image in this way:

FROM trion/ng-cli:latest
COPY package.json package-lock.json angular.json ./
RUN npm install && npm install --loglevel verbose


and already use this image for the application build:

build:
    stage: build
    image: имя образа
    script:
      - ng build --prod --aot --output-hashing=all --serviceWorker
    artifacts:
      expire_in: 60 minutes
      paths:
        - ./dist/webpp
    interruptible: true
    tags:
      - docker
    only:
    - stage

but it didn't work, when building, an error pops up:
An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'

although the modules are in theory all installed.

Tried another one like this, with the same success.
FROM node:latest
COPY package.json package-lock.json angular.json ./
RUN npm install && npm install @angular-devkit/build-angular  --loglevel verbose

Can you advise what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-09-30
@valerka_shtirliz

You can cache node_modules .
Gitlab CI Discussion : npm doesn't like the cached node_modules
pnpm is faster npm can use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question