Twenty CRM

8 months ago

Description: Deploy v0.* of Twenty CRM

Category: Productivity

URL: https://railway.app/template/nAL3hA

Please check the following docs of Twenty as well when setting up this template:

Add a comment in this thread if you run into any issues with deploying

35 Replies

bullrichHOBBY

7 months ago

Does this template support the google auth features?


7 months ago

Yes it does, but you'd need to add the env variables yourself. I think this should help: https://twenty.com/developers/section/self-hosting/self-hosting-var check the "Auth" section


abdelrahmanahmed605TRIAL

7 months ago

I tried deploying the Twenty CRM template and provided the 4 email env variables but both my Twenty and Twenty Worker deployments crashed. The Deployment logs on both show the error
``` ERROR [ExceptionHandler] connect ECONNREFUSED 127.0.0.1:6379

Error: connect ECONNREFUSED 127.0.0.1:6379

at TCPConnectWrap.afterConnect [as oncomplete]```


abdelrahmanahmed605TRIAL

7 months ago

So after checking the github code, I noticed some recent changes from this week and last week that introduced Redis cache storage. To get everything working, I had to add a Redis database to the environment and set the REDIS_HOST and REDIS_PORT environment variables for both the Twenty server and the Twenty Worker. It might be helpful to include this setup in the template so future users can have everything working out of the box.


abdelrahmanahmed605TRIAL

7 months ago

Hi, so after I tried deploying with the redis server, I get the following error in my deploy logs:
```
Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
```

Any ideas how to fix this?


7 months ago

Hi, so after I tried deploying with the redis server, I get the following error in my deploy logs:
```
Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
```

Any ideas how to fix this?

Hi, thanks for the suggestion, I added Redis to the template.

I am however getting the same error as you. I tried adding sleep 3 && yarn start:prod as the start command as per: https://docs.railway.app/guides/private-networking#initialization-time but then the container does not start properly.

Did you manage to find a fix in the meantime?

It seems the services are unable to reach the Redis instance, I am unsure why though..


abdelrahmanahmed605TRIAL

7 months ago

Unfortunately I have not found a fix yet.

I tried adding the sleep 3 in the start command as well and also adding it in the twenty dockerfile and using my custom docker image instead for the server source image, but that did not work either.

I also saw that bullmq is being used in the message-queue.module-factory files and I found out that bullmq uses ioredis and I saw that the railway documentation mentions :ioredis is a Redis client for node.js, commonly used for connecting to Redis from a node application. When initializing a Redis client using ioredis, you must specify family=0 in the connection string to support connecting to both IPv6 and IPv4 connections

so I tried to add family: 0 in the code where the REDIS_HOST, REDIS_PORT environment variables are used and then using a custom docker image again, but that did not work either.

Maybe I configured it wrong when trying out these solutions and you have better luck!

I'll keep experimenting and will update here if I find a solution, but if you happen to discover something in the meantime, please let me know as I'm currently stuck and unable to deploy my services


7 months ago

I also saw that bullmq is being used in the message-queue.module-factory files and I found out that bullmq uses ioredis and I saw that the railway documentation mentions :ioredis is a Redis client for node.js, commonly used for connecting to Redis from a node application. When initializing a Redis client using ioredis, you must specify family=0 in the connection string to support connecting to both IPv6 and IPv4 connections

Thanks for pointing me to this! It seems that this is indeed what is causing the error. I added the MESSAGE_QUEUE_TYPE var and set it to pg-boss (default is bullmq) so it does not use bullmq and therefore also not ioredis, which seems to fix the redis connection issue. Not the ideal solution but at least the application works

Let me know if this works for you!


abdelrahmanahmed605TRIAL

7 months ago

Yes, that worked for me!

Another approach I tried successfully was deploying the Redis database in a separate environment and connecting to it using the public domain. When I updated the environment variables to point to the public URL, it worked as expected.

I’m still unsure why the internal Redis connection is failing. Do you think this is an issue with Twenty or Railway? If you manage to find the root cause, please let me know!


7 months ago

It's an issue with ioredis.

bullmq uses ioredis internally.

The private network is IPv6 only.

ioredis by default only works with IPv4.

https://docs.railway.app/guides/private-networking#ioredis


abdelrahmanahmed605TRIAL

7 months ago

I see! Thank you for the help!


abdelrahmanahmed605TRIAL

7 months ago

Hey @thomasmol! Quick question—after deploying the template, are you seeing a NOAUTH Authentication required error when you try to sign up, log in, or create a workspace? I’m having a bit of trouble getting anything to work on my end.

Any ideas on what might be causing this? Is it possibly also related to Redis? Thanks!


7 months ago

Hi Abdel, I don't think that is related to Redis, what are you seeing in your deploy logs? Did the db migrations run as well?


abdelrahmanahmed605TRIAL

7 months ago

The deploy logs are working fine but I get the following errors on the front-end when I try to do anything after deploying the app

Attachments


6 months ago

Opened a PR to fix the Redis connection issue: https://github.com/twentyhq/twenty/pull/7736

This will allow connecting to the redis instance with a connection url, so we can append ?family=0


3 months ago

Hello!

Looks like the template uses the outdated Postgres image from twenty, would you mind updating that when you get a chance?

Thanks!


brody

Hello!Looks like the template uses the outdated Postgres image from twenty, would you mind updating that when you get a chance?Thanks!

3 months ago

Done!


3 months ago

Perhaps the template page is still cached, but you've used the twenty-postgres-spilo image right?


brody

Perhaps the template page is still cached, but you've used the twenty-postgres-spilo image right?

3 months ago

yes i did!

Attachments


3 months ago

Perfect, thank you!


3 months ago

Noticed the Postgres service only has two variables, the password being set to a crazy insecure value of twenty, can you add a regular Postgres database into the template and then update its image, this is so that it will have all the proper variables configured.

Then you will need to update the URL reference variable on the twenty services.


brody

Noticed the Postgres service only has two variables, the password being set to a crazy insecure value of twenty, can you add a regular Postgres database into the template and then update its image, this is so that it will have all the proper variables configured.Then you will need to update the URL reference variable on the twenty services.

3 months ago

Thanks for noticing. Its updated


2 months ago

Deployment health of this template seems to be pretty low currently. Help me out and reply here with any issues you are encountering!


2 months ago

Have you tried deploying your template? I did that and can see clear crashes.


2 months ago

Fixed a few errors:

  • Added missing APP_SECRET env var for the worker service (auto gen secret of length 32)

  • Changed the DATABASE_URL and DATABSE_PUBLIC_URL env vars of the db service to start with postgres:// (previously postgreseql://, which caused a validation error)

However the db service seems to not start properly. I get /etc/runit/runsvdir/default/patroni: sleeping 90 seconds Config is empty message in the logs and then it shuts down. I am investigating this issue.


2 months ago

hi! did you got the solution?


moigamijunior

hi! did you got the solution?

2 months ago

I haven't yet unfortunately. Are you getting the same errors?


thomasmol

I haven't yet unfortunately. Are you getting the same errors?

2 months ago

Yes! Sounds like worker cannot connect to DB. I've fixed the envs, but I got the timeout.


thomasmol

I haven't yet unfortunately. Are you getting the same errors?

2 months ago

[Nest] 29 - 02/19/2025, 2:19:01 PM ERROR [TypeOrmModule] Unable to connect to the database (core). Retrying (4)...

Error: connect ECONNREFUSED fd12:e62c:e118::ac:6a89:25f5:5432

at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)


moigamijunior

[Nest] 29 - 02/19/2025, 2:19:01 PM ERROR [TypeOrmModule] Unable to connect to the database (core). Retrying (4)...Error: connect ECONNREFUSED fd12:e62c:e118::ac:6a89:25f5:5432at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)

2 months ago

Yes that is because the database service is not healthy actually. The service says 'Active', but check the deploy logs of the db and you'll see it is not live. Can you share the logs you see there?


thomasmol

Yes that is because the database service is not healthy actually. The service says 'Active', but check the deploy logs of the db and you'll see it is not live. Can you share the logs you see there?

2 months ago

PermissionError: [Errno 13] Permission denied: '/var/lib/postgresql/data/pgdata'


brody

Noticed the Postgres service only has two variables, the password being set to a crazy insecure value of twenty, can you add a regular Postgres database into the template and then update its image, this is so that it will have all the proper variables configured.Then you will need to update the URL reference variable on the twenty services.

2 months ago

Did not manage to get it working with this suggestion. Eventually removed the db service and built a new one directly from the twenty postgres spilo image, instead of creating a regular railway based postgres db and then manually changing the image.

That fixed the db connecting issue.

However, there is another problem, now in the twenty server service, which according to the official docker compose now uses 2 volumes. I can't seem to get it working yet and i get this error in the the deploy logs: touch: /app/docker-data/db_status: No such file or directory which makes sense because it is only mounted to /app/packages/twenty/data and you can't mount to two volumes. If you mount the volume to app/docker-data you'll get an error saying the entrypoint.sh is missing. Any ideas how to fix this issue?


thomasmol

Did not manage to get it working with this suggestion. Eventually removed the db service and built a new one directly from the twenty postgres spilo image, instead of creating a regular railway based postgres db and then manually changing the image.That fixed the db connecting issue.However, there is another problem, now in the twenty server service, which according to the official docker compose now uses 2 volumes. I can't seem to get it working yet and i get this error in the the deploy logs: touch: /app/docker-data/db_status: No such file or directory which makes sense because it is only mounted to /app/packages/twenty/data and you can't mount to two volumes. If you mount the volume to app/docker-data you'll get an error saying the entrypoint.sh is missing. Any ideas how to fix this issue?

2 months ago

I got something working but it is not ideal:

  • Updated the 'Twenty' to also include the APP_SECRET env var. The twenty worker now refers to the twenty service for this var.

  • Postgres service volume is now mounted on /home/postgres/pgdata and based on the twenty spilo image.

  • Added a few env vars to the Postgres service: SPILO_PROVIDER, ALLOW_NOSSL and PGUSER_SUPERUSER, PGPASSWORD_SUPERUSER and updated some var values like db name, so it is the same as in the official twenty docker compose

The template now seems to run, but the main 'Twenty' service still has the db_status error. It does run the db migrations properly.

So to get it working you first run the template as is. Then after in the 'Twenty' service you change the start command to yarn start:prod (db migrations are not run, regardless of the db migration env var), and redploy the service. This should now work.

Running yarn start:prod as a start command does not execute db migrations.


2 months ago

Can you please bake in migrations into the template, and then have it from start:prod, it's not something the user should need to do.


brody

Can you please bake in migrations into the template, and then have it from start:prod, it's not something the user should need to do.

2 months ago

Yes I understand that perfectly Brody. I have been trying different commands/deploy config and can't get it working yet, and this is the best I can do thus far. Any help is much appreciated.


Twenty CRM - Railway Help Station