SeanKilleen
SeanKilleen

Reputation: 8977

How do I reduce the time for npm install across multiple TeamCity builds?

Problem

Question

What is the recommended way to centralize / re-use the node_modules folder between builds given our stack?

Technology Stack

What We've Tried

Other Approaches We're Trying

Upvotes: 6

Views: 3019

Answers (3)

banyudu
banyudu

Reputation: 1102

Have you tried docker cache?

Put your npm install in Dockerfile, run docker build

FROM node:12

WORKDIR /code

COPY ./package.json ./package-lock.json /code

RUN npm install # skiped when package.json/package-lock.json not changed.

ADD . /code

# do other things

Docker build creates a layer for each command(COPY/ADD/RUN), and use the layer as cache(if nothing changed) when build agagin.

As long as package.json/package-lock.json not changed

docker build will use cache for

COPY ./package.json ./package-lock.json /code

and

RUN npm install

so you don't need to speed up npm install, it just skiped.

Upvotes: 0

MGDavies
MGDavies

Reputation: 1054

I'm told you can turn off progress reporting and speed it up significantly: http://biercoff.com/how-to-crazy-easily-speed-up-your-npm-install-speed/

Upvotes: 0

Sagi_Avinash_Varma
Sagi_Avinash_Varma

Reputation: 1509

What you have been doing is the best practice in the industry. I dont know if u can make it any better with npm.

have u tried yarn instead https://github.com/yarnpkg/yarn there is a way to use along with docker too https://hackernoon.com/using-yarn-with-docker-c116ad289d56#.8bhk0tkz4

Upvotes: 1

Related Questions