Make database optional when building
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?
-
[x] Build Cal.com locally, without a database being available
(cd packages/prisma && docker-compose down) && yarn build- [x] Bring up the database and run
yarn startwith no issues(cd packages/prisma && docker-compose up -d) && yarn start - [x] Visit http://localhost:3000/apps/whatsapp and see a list of apps
- [x] Visit http://localhost:3000/apps/categories and see a list of categories
- [x] Visit http://localhost:3000/apps/categories/video and see apps in that category
- [x] Bring up the database and run
-
[x] Build Cal.com locally, with a database being available
(cd packages/prisma && docker-compose up -d) && yarn build- [x] Run via
yarn startwith no issues - [x] Visit http://localhost:3000/apps/whatsapp and see a list of apps
- [x] Visit http://localhost:3000/apps/categories and see a list of categories
- [x] Visit http://localhost:3000/apps/categories/video and see apps in that category
- [x] Run via
-
[x] Run via
yarn dxwith no issues- [x] Visit http://localhost:3000/apps/whatsapp and see a list of apps
- [x] Visit http://localhost:3000/apps/categories and see a list of categories
- [x] Visit http://localhost:3000/apps/categories/video and see apps in that category
-
[x] 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 buildwithout 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)
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 |
@rjackson is attempting to deploy a commit to the cal Team on Vercel.
A member of the Team first needs to authorize it.
📦 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 "+/-
Thank you for your contribution. Will review ASAP!
excited for this!
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.