Slim the Docker image and clean up after every deploy
Deploy Vault CMS / deploy (push) Successful in 1m15s
Deploy Vault CMS / deploy (push) Successful in 1m15s
- Build Next.js as a standalone server and copy only that into the runtime image, instead of the whole node_modules tree - Mark three dynamic file reads with turbopackIgnore so the standalone trace does not pull in the entire project - Deploy workflow prunes unused images and build cache older than a day at the start and end of every run, including failed ones, and logs disk usage before building Failed builds were leaving their layers behind until the server's disk filled, which broke the deploy, the database and Gitea sign-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+10
-7
@@ -36,17 +36,20 @@ WORKDIR /app
|
||||
# Install dumb-init for proper signal handling
|
||||
RUN apk add --no-cache dumb-init
|
||||
|
||||
# Copy from builder: node_modules and .next build output.
|
||||
# Copy the standalone server (only the files it actually uses, including the
|
||||
# traced parts of node_modules), plus static assets, which it does not include.
|
||||
# Files stay root-owned so the app user cannot rewrite its own code; only the
|
||||
# Next.js cache directory is writable.
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
RUN mkdir -p .next/cache && chown node:node .next/cache
|
||||
|
||||
# Set production environment
|
||||
# Set production environment. HOSTNAME makes the server listen on all
|
||||
# interfaces rather than only the container's hostname.
|
||||
ENV NODE_ENV=production
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
ENV PORT=3000
|
||||
|
||||
# Run as the unprivileged "node" user (uid 1000) instead of root
|
||||
USER node
|
||||
@@ -57,5 +60,5 @@ EXPOSE 3000
|
||||
# Use dumb-init to handle signals properly
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# Start Next.js production server (directly, so npm doesn't need a writable home)
|
||||
CMD ["node", "node_modules/next/dist/bin/next", "start"]
|
||||
# Start the standalone Next.js server
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
Reference in New Issue
Block a user