Skip to content
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

feat: Make database optional when building #8561

Merged
merged 11 commits into from May 31, 2023

Conversation

rjackson
Copy link
Contributor

@rjackson rjackson commented Apr 29, 2023

What does this PR do?

We have a few app-store related pages that require a database connection at build time.

This change adds try-catch blocks in getStaticPaths for those pages; when no database is available we respond with no paths, but fall back to rendering the pages on-demand.

(Update: 2023-04-30)

I'd previously also added a try...catch block to the getStaticProps function used by pages/apps/categories/index.tsx and set it up to revalidate until a request which loaded categories was processed. I wasn't a fan of how this behaved, however. The first load of the page was empty, but the second load came through with a list of categories.

To make the first load of the categories index page nicer, I've gotten rid of the try...catch block and instead changed it over to be server-rendered. That gets it, and its database connection, out of the build path; and it makes sure that its database-loaded info (how many apps are within each category) are always up-to-date.

(End update)

These changes makes Cal.com more compatible with typical Docker-based workflows that do not expect external services to be available at build time. This includes Docker-based hosting providers, such as Cloudron (#3026).

I have also added a GitHub Action to test this, which is the same as the Production build GitHub action but without database credentials. I've not been able to test this locally of course, so hopefully this PR will kick that off and prove whether or not it works.

Solves #3026 and #6780

/claim #3026

Environment: Staging(main branch)

Type of change

  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Build Cal.com locally, without a database being available

    (cd packages/prisma && docker-compose down) && yarn build
    
  • Build Cal.com locally, with a database being available

    (cd packages/prisma && docker-compose up -d) && yarn build
    
  • Run via yarn dx with no issues

  • Using a modified calcom/docker, build the Dockerfile without a database connection

    # docker-compose build wouldn't work on my machine (m1 mac)
    DOCKER_BUILDKIT=0 docker build -t calcom ./
    
  • Deploy the built image to a hosted Cloudron instance
    Cloudron doesn't seem quite happy taking an existing Docker image and running it directly. It appears they prefer their own intermediary Docker runtime, usually built atop cloudron:base, with bespoke scripts to map their Postgres credentials (CLOUDRON_POSTGRESQL_...) to however an application takes those credentials.

    I'm therefore considering testing on Cloudron and related changes for calcom/docker out-of-scope for this issue. I don't think a full Cloudron package was expected from the reported issues, as others were attempting to build those packages themselves. The reported issue was the inability to run yarn build without a database, which this PR addresses.

  • See the "Production build (without database)" Github Action work

Checklist

  • I haven't checked if my PR needs changes to the documentation
  • Create associated PR against calcom/docker (out-of-scope)
  • Finish testing against Cloudron (out-of-scope)

Solves calcom#3026 and calcom#6780

We have a few app-store related pages that require a database connection at build time.

This change adds try-catch blocks in getStaticPaths or getStaticProps for those pages, and when no database is available we either:

- getStaticPaths: Respond with no paths, but fall back to rendering the pages on-demand
- getStaticProps: Respond with no data, but enable revalidation until a future request does respond with data

This makes Cal.com more compatible with typical Docker-based workflows, that do not expect external services to be available at build time. This includes Docker-based hosting providers, such as Cloudron (calcom#3026).
@vercel
Copy link

vercel bot commented Apr 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cal ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2023 3:23am
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2023 3:23am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
api ⬜️ Ignored (Inspect) May 31, 2023 3:23am

@vercel
Copy link

vercel bot commented Apr 29, 2023

@rjackson is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Ten Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/[user]/book 254.97 KB 406.16 KB 116.05% (🟢 -0.15%)
/apps/[slug]/[...pages] 459.18 KB 610.37 KB 174.39% (🟡 +0.25%)
/auth/setup 174.9 KB 326.09 KB 93.17% (🟡 +0.16%)
/d/[link]/book 254.62 KB 405.81 KB 115.94% (🟢 -0.14%)
/event-types/[type] 479.62 KB 630.81 KB 180.23% (🟡 +0.19%)
/getting-started/[[...step]] 426.28 KB 577.47 KB 164.99% (🟢 -0.22%)
/new-booker/[user]/[type] 290.23 KB 441.42 KB 126.12% (🟢 -0.14%)
/new-booker/team/[slug]/[type] 290.24 KB 441.43 KB 126.12% (🟢 -0.14%)
/settings/my-account/calendars 252.55 KB 403.74 KB 115.35% (🟢 -0.23%)
/team/[slug]/book 254.62 KB 405.81 KB 115.95% (🟢 -0.15%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

@rjackson rjackson marked this pull request as ready for review April 29, 2023 17:30
@rjackson rjackson requested a review from a team April 29, 2023 17:30
@zomars
Copy link
Member

zomars commented May 12, 2023

Thank you for your contribution. Will review ASAP!

@PeerRich
Copy link
Member

excited for this!

@alannnc alannnc added the ♻️ autoupdate tells kodiak to keep this branch up-to-date label May 19, 2023
@leog leog requested a review from zomars May 23, 2023 18:56
@leog
Copy link
Contributor

leog commented May 23, 2023

Thank you for your contribution. Will review ASAP!

Assigned you @zomars, as you have it in your list already, to avoid having the PR in other people's list too, hope that's OK.

@PeerRich PeerRich changed the title Make database optional when building feat: Make database optional when building May 24, 2023
@PeerRich PeerRich added Low priority Created by Linear-GitHub Sync self-hosting Medium priority Created by Linear-GitHub Sync and removed Low priority Created by Linear-GitHub Sync labels May 25, 2023
Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience. Tested and LGTM!

Ship it

@zomars zomars added this pull request to the merge queue May 31, 2023
Merged via the queue into calcom:main with commit 7a9a2fc May 31, 2023
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ autoupdate tells kodiak to keep this branch up-to-date ✨ feature New feature or request Medium priority Created by Linear-GitHub Sync self-hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants