-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docker): Optimized web Dockerfile to reduct image size (#173)
Signed-off-by: Abhishek kushwaha <abhishekkushwaha1479@gmail.com> Co-authored-by: Rajdip Bhattacharya <agentR47@gmail.com>
- Loading branch information
1 parent
dd43ed9
commit 444286a
Showing
5 changed files
with
49 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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,57 @@ | ||
FROM node:20-alpine AS build | ||
FROM node:20-alpine AS base | ||
|
||
|
||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update && apk upgrade | ||
# working directory | ||
WORKDIR /app | ||
RUN npm install --ignore-scripts -g turbo | ||
COPY . . | ||
RUN turbo prune web --docker | ||
|
||
RUN npm i -g pnpm | ||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
WORKDIR /app | ||
|
||
# COPY package.json . | ||
COPY turbo.json . | ||
COPY pnpm-workspace.yaml . | ||
COPY package*.json . | ||
COPY ./packages ./packages | ||
# install the dependencies | ||
RUN npm install --ignore-scripts -g pnpm | ||
COPY .gitignore .gitignore | ||
COPY --from=builder /app/out/json/ . | ||
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | ||
RUN pnpm install --no-cache --ignore-scripts | ||
|
||
COPY apps/web/package.json apps/web/package.json | ||
COPY apps/web/tsconfig.json apps/web/tsconfig.json | ||
# Build the project | ||
COPY --from=builder /app/out/full/ . | ||
COPY turbo.json turbo.json | ||
|
||
RUN pnpm install | ||
|
||
COPY . . | ||
RUN pnpm turbo build --filter=web... | ||
|
||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
# Don't run production as root | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
USER nextjs | ||
|
||
COPY --from=installer /app/apps/web/next.config.js . | ||
COPY --from=installer /app/apps/web/package.json . | ||
|
||
RUN pnpm run build:web | ||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./ | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public | ||
|
||
|
||
ENV PORT=3000 | ||
ENV NEXT_SHARP_PATH=/app/apps/web/.next/sharp | ||
EXPOSE 3000 | ||
ENV HOSTNAME "0.0.0.0" | ||
|
||
|
||
ENTRYPOINT ["pnpm", "run", "start:web"] | ||
CMD node apps/web/server.js |
This file contains 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 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 |
---|---|---|
|
@@ -15,7 +15,6 @@ services: | |
POSTGRES_DB: tests | ||
networks: | ||
- keyshade-test | ||
|
||
networks: | ||
keyshade-test: | ||
driver: bridge |
This file contains 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 |
---|---|---|
|
@@ -13,7 +13,6 @@ services: | |
- ./data:/var/lib/postgresql/data | ||
networks: | ||
- keyshade-dev | ||
|
||
networks: | ||
keyshade-dev: | ||
driver: bridge |
This file contains 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