calcom / cal.com

Scheduling infrastructure for absolutely everyone.
https://cal.com
Other
32.64k stars 8.09k forks source link

[CAL-3737] Railway deployment does not work #15032

Open dipyamanroy opened 6 months ago

dipyamanroy commented 6 months ago

Issue Summary

Deployment using Railway shows up as active, however the URL which points to Cal does not load, or loads briefly with error 500.

Steps to Reproduce

  1. Use the one-click deploy with Railway.
  2. Add your Google API key, and proceed to deploy both Cal and Postgres.
  3. Click on URL generated by Railway.

Expected result is a deployment of Cal with a login page.

Actual Results

Expected Results

Technical details

Logs from Railway:

@calcom/web:start: SyntaxError: Unexpected token A in JSON at position 0
@calcom/web:start:     at JSON.parse (<anonymous>)
@calcom/web:start:     at 761191 (/calcom/apps/web/.next/server/pages/auth/login.js:1:12370)
@calcom/web:start:     at __webpack_require__ (/calcom/apps/web/.next/server/webpack-runtime.js:1:161)
@calcom/web:start:     at /calcom/apps/web/.next/server/pages/auth/login.js:1:11124
@calcom/web:start:     at __webpack_require__.a (/calcom/apps/web/.next/server/webpack-runtime.js:1:1070)
@calcom/web:start:     at 222186 (/calcom/apps/web/.next/server/pages/auth/login.js:1:10981)
@calcom/web:start:     at __webpack_require__ (/calcom/apps/web/.next/server/webpack-runtime.js:1:161)
@calcom/web:start:     at /calcom/apps/web/.next/server/pages/auth/login.js:1:6541
@calcom/web:start:     at __webpack_require__.a (/calcom/apps/web/.next/server/webpack-runtime.js:1:1070)
@calcom/web:start:     at 130133 (/calcom/apps/web/.next/server/pages/auth/login.js:1:6135)
@calcom/web:start: 16:07:46:497 WARNorgDomains.ts Match of WEBAPP_URL with ALLOWED_HOSTNAME failed {
@calcom/web:start:   WEBAPP_URL: 'https://cal-production-a4cb.up.railway.app'/;,
@calcom/web:start:   ALLOWED_HOSTNAMES: []
@calcom/web:start: }

Evidence

CAL-3737

dosubot[bot] commented 6 months ago

The error logs indicate two primary issues with your Railway deployment of Cal: a JSON syntax error and a domain matching warning. Here's how to address them:

  1. JSON Syntax Error: This likely stems from improperly set or parsed environment variables. Verify that your DATABASE_URL and other relevant environment variables are correctly configured in Railway, matching the format and values expected by Cal.

  2. Domain Matching Warning: Add your Railway app's domain to the ALLOWED_HOSTNAMES environment variable to resolve the domain matching warning. If your app's URL is https://cal-production-a4cb.up.railway.app, include this in the ALLOWED_HOSTNAMES.

  3. Environment Variables: Double-check all required environment variables are set, including those for authentication, database connections, and any other services your deployment needs. For SSL connections with PostgreSQL, you might need to set PGSSLMODE to no-verify.

  4. Database Migrations: Ensure you've run the necessary database migrations for Cal, as a mismatch between the database schema and the application's expectations can lead to errors.

Addressing these points should help resolve the issues you're encountering with your Railway deployment of Cal.

#### Details **Sources** - [Railway deployment problem - crowdin](https://github.com/calcom/cal.com/issues/2308) - [[CAL-468] Deployments empty state](https://github.com/calcom/cal.com/issues/5732) - [.env.example](https://github.com/calcom/cal.com/blob/main/.env.example) - [deploy/README.md](https://github.com/calcom/cal.com/blob/main/deploy/README.md) - [app.json](https://github.com/calcom/cal.com/blob/main/app.json) - [apps/api/v1/lib/helpers/safeParseJSON.ts](https://github.com/calcom/cal.com/blob/main/apps/api/v1/lib/helpers/safeParseJSON.ts) - [packages/features/test/orgDomains.test.ts](https://github.com/calcom/cal.com/blob/main/packages/features/test/orgDomains.test.ts) - [packages/lib/constants.ts](https://github.com/calcom/cal.com/blob/main/packages/lib/constants.ts) - [apps/web/pages/auth/login.tsx](https://github.com/calcom/cal.com/blob/main/apps/web/pages/auth/login.tsx) - [apps/web/test/lib/next-config.test.ts](https://github.com/calcom/cal.com/blob/main/apps/web/test/lib/next-config.test.ts) - [packages/features/ee/organizations/lib/orgDomains.ts](https://github.com/calcom/cal.com/blob/main/packages/features/ee/organizations/lib/orgDomains.ts)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

PeerRich commented 6 months ago

would love some help from the railway team

JakeCooper commented 6 months ago

Looks like @brody192 owns the Cal template. Brody do you want to have a look to make sure that this works?

I’d bet it’s missing an envvar that was added or something

JakeCooper commented 6 months ago

Alternatively, might be good for the Cal team to own the template itself. Got thousands of people on it so:

1) You’d control the health of that experience/deployment 2) You’d make $$$ for it

brody192 commented 6 months ago

Thanks for the ping Cooper, Will be heading out on a trip with friends today and tomorrow, but will see what I can find out!

brody192 commented 6 months ago

After deploying the template I set a ALLOWED_HOSTNAMES variable to "${{RAILWAY_PUBLIC_DOMAIN}}" (with the quotes) and without the scheme as the env.example file shows.

@calcom/web:start: 12:14:48:757 WARNorgDomains.ts Match of WEBAPP_URL with ALLOWED_HOSTNAME failed {
@calcom/web:start:   WEBAPP_URL: 'https://cal-production-f5f0.up.railway.app';,
@calcom/web:start:   ALLOWED_HOSTNAMES: [
@calcom/web:start:     'cal-production-f5f0.up.railway.app'
@calcom/web:start:   ]
@calcom/web:start: }

I must be missing something because that hostname is definitely a match to the hostname in WEBAPP_URL?

NEXT_PUBLIC_WEBAPP_URL is set to https://${{RAILWAY_PUBLIC_DOMAIN}}

And for what it's worth, the Railway generated domain still opens and redirects to /auth/setup without any error codes or white screens returned.

mattly commented 5 months ago

for what it's worth, you can make that error go away by either including the protocol in the value in ALLOWED_HOSTNAMES or excluding it from the value in NEXT_PUBLIC_WEBAPP_URL, however based on the documentation and examples these seem to be in conflict. I still haven't gotten it working with either method.

brody192 commented 5 months ago

If you mean you are still seeing the white screen, then I think that means your GOOGLE_API_CREDENTIALS key is wrong.

mattly commented 5 months ago

If you mean you are still seeing the white screen, then I think that means your GOOGLE_API_CREDENTIALS key is wrong.

What was happening for me is that the service would exit a few seconds after yarn start with no error message. I did not configure GOOGLE_API_CREDENTIALS because I do not have a google account and have no wish to connect one.

brody192 commented 5 months ago

Would you mind opening a thread on our help station? - https://help.railway.app/questions

This seems like it's getting a little out of scope of the GitHub issues.

shubhankartrivedi commented 2 months ago

Issue still persists

shubhankartrivedi commented 1 month ago

However I was able to make it work. I'm gonna let y'all know soon.