@@ -54,19 +54,28 @@ RUN --mount=type=secret,id=DOCS_BOT_PAT_BASE,mode=0444 \
54
54
. ./build-scripts/fetch-repos.sh
55
55
56
56
# -----------------------------------------
57
- # DEPENDENCIES STAGE: Install node packages
57
+ # PROD_DEPS STAGE: Install production dependencies
58
58
# -----------------------------------------
59
- FROM base AS dependencies
59
+ FROM base AS prod_deps
60
60
USER node:node
61
61
WORKDIR $APP_HOME
62
62
63
63
# Copy what is needed to run npm ci
64
64
COPY --chown=node:node package.json package-lock.json ./
65
65
66
- RUN npm ci --omit=optional --registry https://registry.npmjs.org/
66
+ # Install only production dependencies (skip scripts to avoid husky)
67
+ RUN npm ci --omit=dev --ignore-scripts --registry https://registry.npmjs.org/
67
68
68
69
# -----------------------------------------
69
- # BUILD STAGE: Prepare for production stage
70
+ # ALL_DEPS STAGE: Install all dependencies on top of prod deps
71
+ # -----------------------------------------
72
+ FROM prod_deps AS all_deps
73
+
74
+ # Install dev dependencies on top of production ones
75
+ RUN npm ci --registry https://registry.npmjs.org/
76
+
77
+ # -----------------------------------------
78
+ # BUILD STAGE: Build the application
70
79
# -----------------------------------------
71
80
FROM base AS build
72
81
USER node:node
@@ -84,14 +93,27 @@ COPY --chown=node:node --from=clones $APP_HOME/assets assets/
84
93
COPY --chown=node:node --from=clones $APP_HOME/content content/
85
94
COPY --chown=node:node --from=clones $APP_HOME/translations translations/
86
95
87
- # From the dependencies stage
88
- COPY --chown=node:node --from=dependencies $APP_HOME/node_modules node_modules/
96
+ # From the all_deps stage (need dev deps for build)
97
+ COPY --chown=node:node --from=all_deps $APP_HOME/node_modules node_modules/
98
+
99
+ # Build the application
100
+ RUN npm run build
101
+
102
+ # -----------------------------------------
103
+ # WARMUP_CACHE STAGE: Warm up remote JSON cache
104
+ # -----------------------------------------
105
+ FROM build AS warmup_cache
106
+
107
+ # Generate remote JSON cache
108
+ RUN npm run warmup-remotejson
89
109
90
- # Generate build files
91
- RUN npm run build \
92
- && npm run warmup-remotejson \
93
- && npm run precompute-pageinfo -- --max-versions 2 \
94
- && npm prune --production
110
+ # -----------------------------------------
111
+ # PRECOMPUTE STAGE: Precompute page info
112
+ # -----------------------------------------
113
+ FROM build AS precompute_stage
114
+
115
+ # Generate precomputed page info
116
+ RUN npm run precompute-pageinfo -- --max-versions 2
95
117
96
118
# -------------------------------------------------
97
119
# PRODUCTION STAGE: What will run on the containers
@@ -112,13 +134,17 @@ COPY --chown=node:node --from=clones $APP_HOME/assets assets/
112
134
COPY --chown=node:node --from=clones $APP_HOME/content content/
113
135
COPY --chown=node:node --from=clones $APP_HOME/translations translations/
114
136
115
- # From dependencies stage (*modified in build stage )
116
- COPY --chown=node:node --from=build $APP_HOME/node_modules node_modules/
137
+ # From prod_deps stage (production-only node_modules )
138
+ COPY --chown=node:node --from=prod_deps $APP_HOME/node_modules node_modules/
117
139
118
140
# From build stage
119
141
COPY --chown=node:node --from=build $APP_HOME/.next .next/
120
- COPY --chown=node:node --from=build $APP_HOME/.remotejson-cache ./
121
- COPY --chown=node:node --from=build $APP_HOME/.pageinfo-cache.json.br* ./
142
+
143
+ # From warmup_cache stage
144
+ COPY --chown=node:node --from=warmup_cache $APP_HOME/.remotejson-cache ./
145
+
146
+ # From precompute_stage
147
+ COPY --chown=node:node --from=precompute_stage $APP_HOME/.pageinfo-cache.json.br* ./
122
148
123
149
# This makes it possible to set `--build-arg BUILD_SHA=abc123`
124
150
# and it then becomes available as an environment variable in the docker run.
0 commit comments