Make subsequent calls of npm run docker faster

This makes subsequent calls of `npm run docker` a lot faster if source code was changed.

How it works:
- The build step only executes `npm install`. So it only needs the `package.json` file.
- By copying the whole project folder as late as possible, docker can use cached layers for all previous steps. This includes long-running steps like `apt-get` and `npm install`.
This commit is contained in:
Til Schneider 2021-05-21 17:09:08 +02:00 committed by GitHub
parent c89a5ae029
commit 5b7f291c3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY . /usr/src/app COPY package.json /usr/src/app/package.json
ENV NODE_ENV="production" ENV NODE_ENV="production"
@ -37,7 +37,9 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app /app RUN mkdir /app
COPY --from=builder /usr/src/app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV="production" ENV NODE_ENV="production"
ENV CHOKIDAR_USEPOLLING=1 ENV CHOKIDAR_USEPOLLING=1