-
Notifications
You must be signed in to change notification settings - Fork 125
perf: ship a standalone slim Docker image (~590MB → ~283MB) #841
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
+30
−26
Merged
Changes from all commits
Commits
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
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,31 +1,30 @@ | ||
| FROM node:20-alpine | ||
| FROM node:20-slim | ||
|
|
||
| # Set working directory | ||
| WORKDIR /usr/app | ||
|
|
||
| # Install PM2 globally | ||
| RUN npm install --global pm2 | ||
| ENV NODE_ENV=production | ||
| # Next's standalone server binds to localhost by default; listen on all | ||
| # interfaces inside the container, and pin the port. | ||
| ENV HOSTNAME=0.0.0.0 | ||
| ENV PORT=3000 | ||
|
|
||
| # Next's standalone output (built on the CI runner, see build_n_push.yml) | ||
| # bundles a minimal, traced node_modules plus server.js — there is nothing to | ||
| # install here. The output is traced against the runner (Ubuntu/glibc), so this | ||
| # runtime image must also be glibc (node:20-slim, NOT alpine/musl) or the traced | ||
| # native binaries won't load. | ||
| COPY .next/standalone ./ | ||
| # standalone does not include static assets or the public dir — copy them in. | ||
| COPY .next/static ./.next/static | ||
| COPY public ./public | ||
|
|
||
| COPY docker/entrypoint.sh ./entrypoint.sh | ||
| RUN chmod +x ./entrypoint.sh | ||
|
|
||
| # Copy package.json and package-lock.json before other files | ||
| # Utilise Docker cache to save re-installing dependencies if unchanged | ||
| COPY ./package*.json ./ | ||
|
|
||
| # Install runtime dependencies (npm ci = clean, reproducible install from the lockfile) | ||
| RUN npm ci --omit=dev | ||
|
|
||
| # Copy the app, including the prebuilt .next output. The build now runs on the | ||
| # CI runner (see .github/workflows/build_n_push.yml) with a warm .next/cache, | ||
| # so there is no `npm run build` step here — we only package the result. | ||
| COPY ./ ./ | ||
|
|
||
| COPY /docker/entrypoint.sh ./entrypoint.sh | ||
|
|
||
| RUN chmod u+x /usr/app/entrypoint.sh | ||
|
|
||
| # Expose the listening port | ||
| EXPOSE 3000 | ||
|
|
||
| # apply env variables to the Nextjs .env file | ||
| # entrypoint.sh substitutes the APP_NEXT_PUBLIC_DOCSEARCH_* placeholders baked | ||
| # into .next with real values from the container env, then execs the CMD. | ||
| ENTRYPOINT ["/usr/app/entrypoint.sh"] | ||
|
|
||
| CMD npm run start | ||
| 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
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
Oops, something went wrong.
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.