From a1a37fd1ded3c7dd22fd2a0ecdb63fd4440b5811 Mon Sep 17 00:00:00 2001 From: TITeee <57000565+TITeee@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:21:07 +0900 Subject: [PATCH] build: set ownership as files are copied, not in a step of its own The runner's last step, chown -R /app, copied all of node_modules into another layer (420 MB). The files are now copied with --chown, to the same owner as before, and only /app itself is chowned. The image goes from 2.4 GB to 1.9 GB. --- Dockerfile | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index d5e2b97..8a8ad70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,17 +51,20 @@ WORKDIR /app RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 heretix -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/dist ./dist -COPY --from=builder /app/public ./public -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml -COPY --from=builder /app/.npmrc ./.npmrc -COPY --from=builder /app/prisma ./prisma -COPY --from=builder /app/prisma.config.ts ./prisma.config.ts - -COPY entrypoint.sh ./entrypoint.sh -RUN chmod +x ./entrypoint.sh && chown -R heretix:nodejs /app +# Owned by heretix as they are copied: a chown -R of /app in a step of its own +# copies all of node_modules into another layer, 420 MB more image. +COPY --from=builder --chown=heretix:nodejs /app/node_modules ./node_modules +COPY --from=builder --chown=heretix:nodejs /app/dist ./dist +COPY --from=builder --chown=heretix:nodejs /app/public ./public +COPY --from=builder --chown=heretix:nodejs /app/package.json ./package.json +COPY --from=builder --chown=heretix:nodejs /app/pnpm-lock.yaml ./pnpm-lock.yaml +COPY --from=builder --chown=heretix:nodejs /app/.npmrc ./.npmrc +COPY --from=builder --chown=heretix:nodejs /app/prisma ./prisma +COPY --from=builder --chown=heretix:nodejs /app/prisma.config.ts ./prisma.config.ts + +COPY --chown=heretix:nodejs --chmod=755 entrypoint.sh ./entrypoint.sh +# /app itself, which the copies above leave to root. +RUN chown heretix:nodejs /app USER heretix