perf: streamline cached production builds
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -23,7 +23,7 @@ FROM image-build AS dependencies
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ARG NPM_REGISTRY=https://package-mirror.liara.ir/repository/npm/
|
ARG NPM_REGISTRY=https://registry.npmjs.org/
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1 \
|
ENV NEXT_TELEMETRY_DISABLED=1 \
|
||||||
PKG_CONFIG_PATH=/opt/vips/lib/pkgconfig \
|
PKG_CONFIG_PATH=/opt/vips/lib/pkgconfig \
|
||||||
LD_LIBRARY_PATH=/opt/vips/lib \
|
LD_LIBRARY_PATH=/opt/vips/lib \
|
||||||
@@ -40,21 +40,21 @@ RUN --mount=type=cache,id=portfolio-npm-node22,target=/root/.npm,sharing=locked
|
|||||||
RUN if [ "$(uname -m)" = x86_64 ]; then export CFLAGS='-O2 -march=x86-64 -mtune=generic' CXXFLAGS='-O2 -march=x86-64 -mtune=generic'; fi \
|
RUN if [ "$(uname -m)" = x86_64 ]; then export CFLAGS='-O2 -march=x86-64 -mtune=generic' CXXFLAGS='-O2 -march=x86-64 -mtune=generic'; fi \
|
||||||
&& npm explore sharp -- npm run build
|
&& npm explore sharp -- npm run build
|
||||||
|
|
||||||
COPY scripts/check-image-runtime.mjs ./scripts/check-image-runtime.mjs
|
|
||||||
RUN node scripts/check-image-runtime.mjs --require-source
|
|
||||||
|
|
||||||
FROM dependencies AS verification
|
FROM dependencies AS build
|
||||||
|
|
||||||
COPY . .
|
# Only application inputs invalidate compilation. Tests and docs stay outside.
|
||||||
RUN npm run lint
|
COPY next.config.mjs tsconfig.json next-env.d.ts ./
|
||||||
RUN npm run typecheck
|
COPY src ./src
|
||||||
|
COPY public ./public
|
||||||
|
COPY migrations ./migrations
|
||||||
|
COPY scripts/maintenance.ts scripts/build-maintenance.mjs scripts/prepare-standalone.mjs ./scripts/
|
||||||
RUN --mount=type=cache,id=portfolio-next-node22,target=/app/.next/cache,sharing=locked \
|
RUN --mount=type=cache,id=portfolio-next-node22,target=/app/.next/cache,sharing=locked \
|
||||||
npm run build
|
npm run build
|
||||||
RUN npm test
|
|
||||||
|
|
||||||
# Carry the exact shared-library dependency closure from the working build stage.
|
# Carry the exact shared-library dependency closure from the working build stage.
|
||||||
# Development packages can provide libraries that are absent from image-runtime.
|
# Development packages can provide libraries that are absent from image-runtime.
|
||||||
FROM verification AS native-runtime-libraries
|
FROM dependencies AS native-runtime-libraries
|
||||||
RUN mkdir -p /runtime-libs \
|
RUN mkdir -p /runtime-libs \
|
||||||
&& (ldd /app/node_modules/sharp/src/build/Release/*.node /opt/vips/lib/libvips*.so* 2>/dev/null || true) \
|
&& (ldd /app/node_modules/sharp/src/build/Release/*.node /opt/vips/lib/libvips*.so* 2>/dev/null || true) \
|
||||||
| awk '/=> \// { print $3 } /^[[:space:]]*\// { print $1 }' \
|
| awk '/=> \// { print $3 } /^[[:space:]]*\// { print $1 }' \
|
||||||
@@ -77,15 +77,11 @@ ENV NODE_ENV=production \
|
|||||||
RUN addgroup --system --gid 1001 nodejs \
|
RUN addgroup --system --gid 1001 nodejs \
|
||||||
&& adduser --system --uid 1001 nextjs
|
&& adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
COPY --from=verification --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=verification --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
||||||
COPY --from=verification --chown=nextjs:nodejs /app/public ./public
|
|
||||||
COPY --from=image-build /opt/vips/lib /opt/vips/lib
|
COPY --from=image-build /opt/vips/lib /opt/vips/lib
|
||||||
# Preserve the package and its native dependency closure beyond Next's tracing.
|
# Preserve the package and its native dependency closure beyond Next's tracing.
|
||||||
COPY --from=dependencies --chown=nextjs:nodejs /app/node_modules/sharp/ ./node_modules/sharp/
|
COPY --from=dependencies --chown=nextjs:nodejs /app/node_modules/sharp/ ./node_modules/sharp/
|
||||||
COPY --from=native-runtime-libraries /runtime-libs/ /
|
COPY --from=native-runtime-libraries /runtime-libs/ /
|
||||||
COPY scripts/check-image-runtime.mjs ./scripts/check-image-runtime.mjs
|
|
||||||
RUN node scripts/check-image-runtime.mjs --require-source
|
|
||||||
RUN mkdir -p .next/cache /data && chown -R nextjs:nodejs .next/cache /data
|
RUN mkdir -p .next/cache /data && chown -R nextjs:nodejs .next/cache /data
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ Use a single application instance and local storage. SQLite is not intended for
|
|||||||
multiple replicas or a network filesystem. Startup applies committed migrations.
|
multiple replicas or a network filesystem. Startup applies committed migrations.
|
||||||
The image includes `maintenance.mjs`, so maintenance needs no npm installation.
|
The image includes `maintenance.mjs`, so maintenance needs no npm installation.
|
||||||
Baseline CPU support for image processing is retained; native compilation is
|
Baseline CPU support for image processing is retained; native compilation is
|
||||||
cached separately and can make the first build slower.
|
cached separately and can make the first build slower. UI edits reuse dependency
|
||||||
|
and native-library layers. Docker builds only the application, including Next.js
|
||||||
|
TypeScript validation, and packages it; lint, audits, tests, and image probes do
|
||||||
|
not run in the production build. Postbuild packages assets once.
|
||||||
|
|
||||||
## Persistent files and configuration
|
## Persistent files and configuration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user