Hello everyone, I’m using gitlab ci + docker to build an angular2 application. Now the build of the project takes too much time, namely the installation of npm dependencies. I would like to set up the cache correctly, can you please help me with this?
My build .gitlab-ci.yml looks like this:
.build:dev:
stage: build
image: ...
services:...
variables: ...
cache:
key:
files:
- /app/package-lock.json
paths:
- /app/node_modules/
script:
- docker build ... -t $REGISTRY/$IMAGE_NAME:latest --build-arg node_image=$REGISTRY/node:14 --build-arg nginx_image=$REGISTRY/nginx:stable --cache-from $REGISTRY/$IMAGE_NAME:latest --compress --build-arg configuration=dev --build-arg project=$PROJECT
- docker push $REGISTRY/$IMAGE_NAME:latest
tags:...
environment: ...
DockerFile:
FROM $node_image as build-stage
WORKDIR /app
COPY package*.json /app/
COPY .npmrc /app/
RUN mkdir node_modules && npm ci
COPY ./ /app/
...
RUN npm run build
But it doesn’t use the cache, and as I understand it, as long as I use npm ci in the dockerfile - it won’t use the cache at all.
Can anyone help me please with setting up the cache? It would be nice to distribute the cache between jobs.
Thanks!