medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.25k stars 2.67k forks source link

'Deploy Medusa Backend on Railway' fails to deploy #5104

Closed coderreco closed 5 months ago

coderreco commented 1 year ago

Bug report

When deploying the 'Deploy Medusa Backend on Railway' Railway template(Railway, (Github)[https://github.com/shahednasser/railway-deploy-demo]), the build and deployment fails. cc: @shahednasser

Describe the bug

When deploying the 'Deploy Medusa Backend on Railway' Railway template(Railway, (Github)[https://github.com/shahednasser/railway-deploy-demo]), the build and deployment fails. The build logs indicate that the healthcheck fails:

====================

Starting Healthcheck

====================

Path: /health

Retry window: 5m0s

Attempt #1 failed with service unavailable. Continuing to retry for 4m59s

Attempt #2 failed with service unavailable. Continuing to retry for 4m58s

Attempt #3 failed with service unavailable. Continuing to retry for 4m56s

Attempt #4 failed with service unavailable. Continuing to retry for 4m52s

Attempt #5 failed with service unavailable. Continuing to retry for 4m44s

Attempt #6 failed with service unavailable. Continuing to retry for 4m28s

Attempt #7 failed with service unavailable. Continuing to retry for 3m58s

Attempt #8 failed with service unavailable. Continuing to retry for 3m28s

Attempt #9 failed with service unavailable. Continuing to retry for 2m58s

Attempt #10 failed with service unavailable. Continuing to retry for 2m28s

Attempt #11 failed with service unavailable. Continuing to retry for 1m58s

Attempt #12 failed with service unavailable. Continuing to retry for 1m28s

Attempt #13 failed with service unavailable. Continuing to retry for 58s

Attempt #14 failed with service unavailable. Continuing to retry for 28s

1/1 replicas never became healthy!

Healthcheck failed!

And the deploy logs indicate that the redis instance may not be connecting properly?

[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.

No Redis url was provided - using Medusa in production without a proper Redis instance is not recommended

Using fake Redis

Initializing models

Models initialized

Initializing plugin models

Plugin models initialized

Initializing strategies

Strategies initialized

Initializing modules

Local Event Bus installed. This is not recommended for production.

Modules initialized

Initializing database

Database initialized

Initializing repositories

Repositories initialized

Initializing services

Services initialized

Initializing express

Warning: connect.session() MemoryStore is not

designed for a production environment, as it will leak

memory, and will not scale past a single process.

Express intialized

Initializing plugins

[info] [webpackbar] Compiling Webpack

System information

Managed deployment via Railway Template

Steps to reproduce the behavior

  1. Go to ('Deploy Medusa Backend on Railway' template)[https://railway.app/template/zC7eOq]
  2. Click on 'Deploy'
  3. Connect github if not already authorized, then provide name for repo to be created.
  4. Allow deployment process
  5. See errors in backend logs

Expected behavior

Expected a successful deployment of the medusa backend and admin panel.

Screenshots

CleanShot 2023-09-17 at 14 44 57 CleanShot 2023-09-17 at 14 45 46 CleanShot 2023-09-17 at 14 46 18 CleanShot 2023-09-17 at 14 46 37

Code snippets

N/A

Additional context

N/A

shahednasser commented 1 year ago

Thank you for opening this issue @coderreco . It seems like the build time is taking long and the healthcheck is executing before, which stops the build after retrying 10 times.

Can I get you to try the following:

  1. In your GitHub instance, click on the Settings tab
  2. Scroll down to find the "Healthcheck Timeout" field and set its value to 300
  3. Click save and wait for the redeployment.

If that doesn't work, you can also try either increasing the timeout value or the number in the "On-Failure Restart Policy Max Retry" field. Let me know if any of these solutions work out

jpizzle34 commented 1 year ago

I had this issue as well. The timeout is probably because the backend service is unable to connect to another dependent service, i.e. the Postgres instance.

You will need to amend a couple of the env vars as the default ones are incorrect.

Change {{Postgresql.DATABASE_URL}} to lowercase, like, {{postgresql.DATABASE_URL}}

Similar for the redis instance.

shahednasser commented 1 year ago

Thank you @jpizzle34 , but we've fixed the docs and the button to fix the variable names, so that's not the issue. Also, if there's any issue in connected to PostgreSQL or Redis then there would be an error like "cannot connect to xxx"

There are no error in the logs, and the build hasn't finished before the deployment is considered as failed, so I think it's most likely due to the healthcheck timeout.

coderreco commented 1 year ago

I had this issue as well. The timeout is probably because the backend service is unable to connect to another dependent service, i.e. the Postgres instance.

You will need to amend a couple of the env vars as the default ones are incorrect.

Change {{Postgresql.DATABASE_URL}} to lowercase, like, {{postgresql.DATABASE_URL}}

Similar for the redis instance.

Thanks for the insight, but I checked and confirmed the variables in mine were already correct.

jpizzle34 commented 1 year ago

Ahhh i see. Sorry i jumped the gun there :)

shahednasser commented 1 year ago

@jpizzle34 all good! I actually only recently discovered the issue with environment variables, so it's always helpful to be made aware of this stuff 😄

coderreco commented 1 year ago

Ahhh i see. Sorry i jumped the gun there :)

No apology necessary! Appreciate the help and any other insights into how you got it working.

@shahednasser I checked the timeout and it was already set to 300. I upped it to 500, and updated to the new version from upstream. It is building currently and I will report back on whether it succeeds or fails this time around.

coderreco commented 1 year ago

@shahednasser No changes and same outcome unfortunately.

During each health check(I think), I can see in the deploy logs that it is not finding the redis_url: CleanShot 2023-09-18 at 06 55 32@2x

I am attempting a deploy with the redis_url value pasted directly into the environment variable instead of using the plugin value to see if that makes any change.

shahednasser commented 1 year ago

This is not an issue, as Medusa will use a fake redis (although functionalities related to scheduled jobs will not work). To enable Redis, you can refer to this documentation.

Did it stop at the "Compiling Webpack" step, or did it move forward? It's strange but I can't reproduce it on my end, so that's why a lot of this is just mainly me guessing 😅

coderreco commented 1 year ago

It looks like it always stops on the compiling webpack step. Well I appreciate your help! That is strange as I have had the same result on two entirely separate attempts to use the template.

shahednasser commented 1 year ago

Maybe you can try another hosting provider. You can find our guides for all providers here.

shahednasser commented 1 year ago

You can also view the public demo we have of the Railway template. Maybe it will provide some idea to how to fix it or any differences compared to your project?

sradevski commented 5 months ago

Hey, thanks for the report! Since v2 brought a lot of architectural and API changes on the backend, we will be closing this ticket since it no longer applies to our new setup, or the issue has already been fixed. If you are still facing issues with v1, please open a new ticket and we will address it as soon as possible. Thanks! 🙏