-
-
Notifications
You must be signed in to change notification settings - Fork 270
Optimize frontend docker image #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arkid15r
merged 5 commits into
OWASP:main
from
abhi4578:feature/refactor-frontend-docker
Apr 9, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,52 @@ | ||
| FROM node:22-alpine AS builder | ||
| FROM node:22-alpine AS base | ||
|
|
||
| # Install depencies and build the project | ||
| FROM base AS builder | ||
| # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
|
|
||
| RUN npm install --ignore-scripts -g pnpm | ||
| COPY --chmod=444 package.json pnpm-lock.yaml ./ | ||
| RUN npm install --ignore-scripts -g pnpm && \ | ||
| pnpm install --ignore-scripts | ||
| RUN pnpm install --ignore-scripts | ||
|
|
||
| COPY .env next.config.ts postcss.config.js tailwind.config.js tsconfig.json ./ | ||
| COPY public public | ||
| COPY src src | ||
| COPY --chmod=444 .env next.config.ts postcss.config.js tailwind.config.js tsconfig.json ./ | ||
| COPY --chmod=555 public public | ||
| COPY --chmod=555 src src | ||
|
|
||
| # Next.js collects completely anonymous telemetry data about general usage. | ||
| # Learn more here: https://nextjs.org/telemetry | ||
| # Uncomment the following line in case you want to disable telemetry during the build. | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
| RUN pnpm run build | ||
|
|
||
| FROM builder | ||
| # Production image, copy all the files and run next | ||
| FROM base AS runner | ||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production | ||
| # Uncomment the following line in case you want to disable telemetry during runtime. | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN addgroup --system --gid 1001 nodejs && \ | ||
| adduser --system --uid 1001 nextjs | ||
| # Copying files with root as owner, so that executing user cannot change the container i.e immutable and reproducible | ||
| COPY --from=builder --chown=root:root --chmod=555 /app/public public | ||
|
|
||
| COPY --from=builder /app/.next .next | ||
| COPY --from=builder /app/node_modules node_modules | ||
| COPY --from=builder /app/package.json package.json | ||
| COPY --from=builder /app/public public | ||
| # Automatically leverage output traces to reduce image size | ||
| # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output | ||
| COPY --from=builder --chown=root:root --chmod=555 /app/.next/standalone . | ||
| # Create (if not there ) cache directory and assign ownership to nextjs user with write permission, so that cahce can be stored | ||
| RUN mkdir -p /app/.next/cache && chown -R nextjs:nodejs /app/.next/cache && chmod -R 755 /app/.next/cache | ||
| COPY --from=builder --chown=root:root --chmod=555 /app/.next/static .next/static | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["pnpm", "run", "start"] | ||
| ENV PORT=3000 | ||
|
|
||
| # server.js is created by next build from the standalone output | ||
| # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output | ||
| ENV HOSTNAME="0.0.0.0" | ||
| CMD ["node", "server.js"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ const nextConfig: NextConfig = { | |
| ], | ||
| }, | ||
| devIndicators: false, | ||
| output: "standalone", | ||
| } | ||
|
|
||
| export default nextConfig | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.