Skip to content

Commit 3701eaa

Browse files
authored
♻️ Improve frontend build time, use dependencies caches
♻️ Improve frontend build time, use dependencies caches #2112
2 parents c54e61d + 1d215ba commit 3701eaa

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

make/web/Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ COPY frontend /opt/frontend
77

88
# Build Next.js application
99
WORKDIR /opt/frontend
10-
RUN if [ -n "$MIRROR" ]; then npm config set registry "$MIRROR"; fi && \
10+
11+
# BuildKit must be enabled for --mount=type=cache to work
12+
# Docker 23.0+ has BuildKit enabled by default
13+
# For older versions, set environment variable: DOCKER_BUILDKIT=1
14+
# Or add "features": {"buildkit": true} to ~/.docker/config.json
15+
# Use BuildKit named caches for npm cache and node_modules
16+
# - id=npm-cache: persists across builds, keyed by cache id
17+
# - sharing=locked: allows concurrent access from multiple builds
18+
# Cache will be reused as long as package.json and package-lock.json content don't change
19+
RUN --mount=type=cache,id=npm-cache,target=/root/.npm,sharing=locked \
20+
--mount=type=cache,id=node-modules,target=/opt/frontend/node_modules,sharing=locked \
21+
if [ -n "$MIRROR" ]; then npm config set registry "$MIRROR"; fi && \
1122
npm install --verbose && \
1223
NODE_ENV=production npm run build && \
1324
mkdir -p ../frontend-dist && \
@@ -32,9 +43,6 @@ RUN if [ -n "$MIRROR" ]; then npm config set registry "$MIRROR"; fi && \
3243
cd ../frontend-dist && \
3344
if [ -n "$MIRROR" ]; then npm config set registry "$MIRROR"; fi && \
3445
npm install --verbose --omit=dev --production && \
35-
npm cache clean --force && \
36-
rm -rf /root/.npm && \
37-
rm -rf /root/.cache && \
3846
rm -rf .next/cache
3947

4048
# Production stage

0 commit comments

Comments
 (0)