From 434588fa34e748daef685879376f01b061ab223f Mon Sep 17 00:00:00 2001 From: BrandonStudio <55647556+BrandonStudio@users.noreply.github.com> Date: Mon, 17 Mar 2025 12:12:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=B7=20build:=20Attempt=20to=20reus?= =?UTF-8?q?e=20layers=20of=20Docker=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 +---- Dockerfile.database | 5 +---- Dockerfile.pglite | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 272d53d49a86d..a4a30a2500990 100644 --- a/Dockerfile +++ b/Dockerfile @@ -114,10 +114,7 @@ RUN \ && chown -R nextjs:nodejs /app /etc/proxychains4.conf ## Production image, copy all the files and run next -FROM scratch - -# Copy all the files from app, set the correct permission for prerender cache -COPY --from=app / / +FROM app ENV NODE_ENV="production" \ NODE_OPTIONS="--dns-result-order=ipv4first --use-openssl-ca" \ diff --git a/Dockerfile.database b/Dockerfile.database index abd9108d4462f..5113e4e63c328 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -138,10 +138,7 @@ RUN \ && chown -R nextjs:nodejs /app /etc/proxychains4.conf ## Production image, copy all the files and run next -FROM scratch - -# Copy all the files from app, set the correct permission for prerender cache -COPY --from=app / / +FROM app ENV NODE_ENV="production" \ NODE_OPTIONS="--dns-result-order=ipv4first --use-openssl-ca" \ diff --git a/Dockerfile.pglite b/Dockerfile.pglite index d694cea6eaac7..943a09fd1cc89 100644 --- a/Dockerfile.pglite +++ b/Dockerfile.pglite @@ -115,10 +115,7 @@ RUN \ && chown -R nextjs:nodejs /app /etc/proxychains4.conf ## Production image, copy all the files and run next -FROM scratch - -# Copy all the files from app, set the correct permission for prerender cache -COPY --from=app / / +FROM app ENV NODE_ENV="production" \ NODE_OPTIONS="--dns-result-order=ipv4first --use-openssl-ca" \ From e0301c4dca9e2773b6c8d54c640185b6df8f0ad6 Mon Sep 17 00:00:00 2001 From: BrandonStudio <55647556+BrandonStudio@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:09:25 +0800 Subject: [PATCH 2/2] Remove duplicate layers --- Dockerfile | 16 ++++++++-------- Dockerfile.database | 30 +++++++++++++++--------------- Dockerfile.pglite | 16 ++++++++-------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index a4a30a2500990..bec5cb8de1b83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -99,19 +99,19 @@ FROM busybox:latest AS app COPY --from=base /distroless/ / -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder /app/.next/standalone /app/ - -# Copy server launcher -COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js - RUN \ # Add nextjs:nodejs to run the app addgroup -S -g 1001 nodejs \ && adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \ # Set permission for nextjs:nodejs - && chown -R nextjs:nodejs /app /etc/proxychains4.conf + && chown nextjs:nodejs /etc/proxychains4.conf + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone /app/ + +# Copy server launcher +COPY --from=builder --chown=nextjs:nodejs /app/scripts/serverLauncher/startServer.js /app/startServer.js ## Production image, copy all the files and run next FROM app diff --git a/Dockerfile.database b/Dockerfile.database index 5113e4e63c328..cbf253a3d0d23 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -113,29 +113,29 @@ FROM busybox:latest AS app COPY --from=base /distroless/ / +RUN \ + # Add nextjs:nodejs to run the app + addgroup -S -g 1001 nodejs \ + && adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \ + # Set permission for nextjs:nodejs + && chown nextjs:nodejs /etc/proxychains4.conf + # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder /app/.next/standalone /app/ +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone /app/ # Copy database migrations -COPY --from=builder /app/src/database/migrations /app/migrations -COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs -COPY --from=builder /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js +COPY --from=builder --chown=nextjs:nodejs /app/src/database/migrations /app/migrations +COPY --from=builder --chown=nextjs:nodejs /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs +COPY --from=builder --chown=nextjs:nodejs /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js # copy dependencies -COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm -COPY --from=builder /deps/node_modules/pg /app/node_modules/pg -COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm +COPY --from=builder --chown=nextjs:nodejs /deps/node_modules/.pnpm /app/node_modules/.pnpm +COPY --from=builder --chown=nextjs:nodejs /deps/node_modules/pg /app/node_modules/pg +COPY --from=builder --chown=nextjs:nodejs /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm # Copy server launcher -COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js - -RUN \ - # Add nextjs:nodejs to run the app - addgroup -S -g 1001 nodejs \ - && adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \ - # Set permission for nextjs:nodejs - && chown -R nextjs:nodejs /app /etc/proxychains4.conf +COPY --from=builder --chown=nextjs:nodejs /app/scripts/serverLauncher/startServer.js /app/startServer.js ## Production image, copy all the files and run next FROM app diff --git a/Dockerfile.pglite b/Dockerfile.pglite index 943a09fd1cc89..fe5c6059f8855 100644 --- a/Dockerfile.pglite +++ b/Dockerfile.pglite @@ -100,19 +100,19 @@ FROM busybox:latest AS app COPY --from=base /distroless/ / -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder /app/.next/standalone /app/ - -# Copy server launcher -COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js - RUN \ # Add nextjs:nodejs to run the app addgroup -S -g 1001 nodejs \ && adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \ # Set permission for nextjs:nodejs - && chown -R nextjs:nodejs /app /etc/proxychains4.conf + && chown nextjs:nodejs /etc/proxychains4.conf + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone /app/ + +# Copy server launcher +COPY --from=builder --chown=nextjs:nodejs /app/scripts/serverLauncher/startServer.js /app/startServer.js ## Production image, copy all the files and run next FROM app