-
Notifications
You must be signed in to change notification settings - Fork 399
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
Create Dockerfile to match Next.js example closely, use "standalone" output, and with 40% smaller image size. #355
Open
jckw
wants to merge
5
commits into
calcom:main
Choose a base branch
from
outro-health:simplify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2d31a3
Remove junk.
jckw ed1f796
Use a more standardised Dockerfile for Next.js monorepos.
jckw b05e76c
Better .dockerignore.
jckw 45f44f9
Copy over migration files in Dockerfile.
jckw 34d208f
Increase memory limit and pass Sentry DSN as ENV in Dockerfile.
jckw 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 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,3 +1,6 @@ | ||
.git | ||
.github | ||
.env.example | ||
.env.example | ||
**/.github | ||
**/node_modules | ||
**/.next | ||
calcom/.yarn/cache |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,76 +1,81 @@ | ||
FROM node:18 as builder | ||
FROM node:18-alpine AS base | ||
|
||
WORKDIR /calcom | ||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
# Set working directory | ||
WORKDIR /app | ||
RUN yarn global add turbo | ||
COPY calcom/. . | ||
RUN turbo prune @calcom/web --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
|
||
ARG NEXT_PUBLIC_LICENSE_CONSENT | ||
ARG CALCOM_TELEMETRY_DISABLED | ||
ARG DATABASE_URL | ||
ARG NEXTAUTH_SECRET=secret | ||
ARG NEXT_PUBLIC_API_V2_URL | ||
ARG CALENDSO_ENCRYPTION_KEY=secret | ||
ARG MAX_OLD_SPACE_SIZE=4096 | ||
ARG MAX_OLD_SPACE_SIZE=8192 | ||
ARG NEXT_PUBLIC_WEBAPP_URL | ||
ARG NEXT_PUBLIC_SENTRY_DSN | ||
|
||
ENV NEXT_PUBLIC_WEBAPP_URL=http://NEXT_PUBLIC_WEBAPP_URL_PLACEHOLDER \ | ||
ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \ | ||
NEXT_PUBLIC_LICENSE_CONSENT=$NEXT_PUBLIC_LICENSE_CONSENT \ | ||
CALCOM_TELEMETRY_DISABLED=$CALCOM_TELEMETRY_DISABLED \ | ||
DATABASE_URL=$DATABASE_URL \ | ||
DATABASE_DIRECT_URL=$DATABASE_URL \ | ||
NEXTAUTH_SECRET=${NEXTAUTH_SECRET} \ | ||
NEXT_PUBLIC_API_V2_URL=${NEXT_PUBLIC_API_V2_URL} \ | ||
CALENDSO_ENCRYPTION_KEY=${CALENDSO_ENCRYPTION_KEY} \ | ||
NODE_OPTIONS=--max-old-space-size=${MAX_OLD_SPACE_SIZE} | ||
|
||
COPY calcom/package.json calcom/yarn.lock calcom/.yarnrc.yml calcom/playwright.config.ts calcom/turbo.json calcom/git-init.sh calcom/git-setup.sh ./ | ||
COPY calcom/.yarn ./.yarn | ||
COPY calcom/apps/web ./apps/web | ||
COPY calcom/packages ./packages | ||
COPY calcom/tests ./tests | ||
NODE_OPTIONS=--max-old-space-size=${MAX_OLD_SPACE_SIZE} \ | ||
NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN} | ||
|
||
RUN yarn config set httpTimeout 1200000 && \ | ||
npx turbo prune --scope=@calcom/web --docker && \ | ||
yarn install && \ | ||
yarn db-deploy && \ | ||
yarn --cwd packages/prisma seed-app-store | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
WORKDIR /app | ||
|
||
RUN yarn turbo run build --filter=@calcom/web | ||
# First install the dependencies (as they change less often) | ||
COPY .gitignore .gitignore | ||
COPY --from=builder /app/out/json/ . | ||
COPY --from=builder /app/out/yarn.lock ./yarn.lock | ||
|
||
# RUN yarn plugin import workspace-tools && \ | ||
# yarn workspaces focus --all --production | ||
RUN rm -rf node_modules/.cache .yarn/cache apps/web/.next/cache | ||
|
||
FROM node:18 as builder-two | ||
# app-store packages aren't explicitly required but need to be available | ||
COPY calcom/packages ./packages | ||
|
||
WORKDIR /calcom | ||
ARG NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000 | ||
RUN yarn install | ||
|
||
ENV NODE_ENV production | ||
# Build the project | ||
COPY --from=builder /app/out/full/ . | ||
|
||
COPY calcom/package.json calcom/.yarnrc.yml calcom/yarn.lock calcom/turbo.json ./ | ||
COPY calcom/.yarn ./.yarn | ||
COPY --from=builder /calcom/node_modules ./node_modules | ||
COPY --from=builder /calcom/packages ./packages | ||
COPY --from=builder /calcom/apps/web ./apps/web | ||
COPY --from=builder /calcom/packages/prisma/schema.prisma ./prisma/schema.prisma | ||
COPY scripts scripts | ||
# Disable linting and type checking in the next build | ||
ENV CI=1 | ||
|
||
# Save value used during this build stage. If NEXT_PUBLIC_WEBAPP_URL and BUILT_NEXT_PUBLIC_WEBAPP_URL differ at | ||
# run-time, then start.sh will find/replace static values again. | ||
ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \ | ||
BUILT_NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL | ||
RUN yarn turbo run build --filter=@calcom/web... | ||
|
||
RUN scripts/replace-placeholder.sh http://NEXT_PUBLIC_WEBAPP_URL_PLACEHOLDER ${NEXT_PUBLIC_WEBAPP_URL} | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
FROM node:18 as runner | ||
# 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 . | ||
|
||
WORKDIR /calcom | ||
COPY --from=builder-two /calcom ./ | ||
ARG NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000 | ||
ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \ | ||
BUILT_NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL | ||
|
||
ENV NODE_ENV production | ||
EXPOSE 3000 | ||
# 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 | ||
|
||
HEALTHCHECK --interval=30s --timeout=30s --retries=5 \ | ||
CMD wget --spider http://localhost:3000 || exit 1 | ||
RUN yarn global add prisma | ||
COPY calcom/packages/prisma/migrations/. ./prisma/migrations | ||
COPY calcom/packages/prisma/schema.prisma ./prisma/schema.prisma | ||
|
||
CMD ["/calcom/scripts/start.sh"] | ||
# TODO: Consider adding seeding script here | ||
CMD ["sh", "-c", "$(yarn global bin)/prisma migrate deploy --schema=prisma/schema.prisma && node apps/web/server.js"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing
**/<folder>
here? Wouldn't simply<folder>
do the same thing?Ref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's true. Dockerignore works differently to gitignore and is a bit unintuitive because of that:
https://shisho.dev/blog/posts/how-to-use-dockerignore/#:~:text=Syntax%20difference%20between%20.dockerignore%20and%20.gitignore
All paths are relative to the root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Surprising that this isn't mentioned in the official docker docs. Thank you for the reference.