T
Twenty11mo ago
thilles

Frontend - Server communication

Hi, I´m trying to self host the docker hub images in Azure Container Apps, and I´m nearly there, but struggeling with some frontend <-> server communications (I think). The server -> db communication is functioning, i.e. I can run yarn database:reset from the server, and it runs through it´s loop ok. I also connect to the frontend url and get greeted with the login modal, but when I try to write something an error ApolloError appers in the upper right hand. Is this error related to connectivity issues? And is there some way to test from within the containers? Running the latest docker images.
No description
71 Replies
charles
charles11mo ago
It looks so! Your frontend (executed by your browser) should reach out to your server url. You can set the REACT_APP_SERVER_BASE_URL at build time (if you pass it as env variable) or at runtime (it's handled by inject-runtime-env .sh script) make sure this is the command used to run your FE in your Dockerfile: CMD ["/bin/sh", "-c", "./scripts/inject-runtime-env.sh && serve build"]
thilles
thillesOP11mo ago
From what I can debug it´s open from the twenty-frontend to twenty-backend:3000, and the REACT_APP_SERVER_BASE_URL is set at build time as an env variable correctly. I think the problem lies from the other side, that the FRONT_BASE_URL env in the server don´t route correctly.
charles
charles11mo ago
twenty-backend:3000 is unlikely to work this is your local dns in case you are transitting from docker to docker the frontend is executed on the client side (in your user browser) so it needs a public DNS for example for Twenty cloud it's api.twenty.com
thilles
thillesOP11mo ago
aha.. That makes sense. I´ll try some more later and hopefully succeed. If interested I could clean up the terraform code afterwards and share it.
charles
charles11mo ago
Would love it!
thilles
thillesOP11mo ago
Success! Thanks! one more question though. How do I initialize the server and db tabels for a production environment? Is it start:prod or something, ref https://github.com/twentyhq/twenty/blob/d016e5ff03555fcc49884ea3479df230d2fffc26/packages/twenty-server/package.json Running yarn database:reset runs ok. But trying to login with [email protected] gives error
2024-02-12T19:30:08.060903238Z '}',
2024-02-12T19:30:08.060907506Z user: undefined
2024-02-12T19:30:08.060912786Z }
2024-02-12T19:30:08.061581282Z [
2024-02-12T19:30:08.061617991Z QueryFailedError: relation "core.user" does not exist
2024-02-12T19:30:08.061627289Z at PostgresQueryRunner.query (/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:219:19)
2024-02-12T19:30:08.061633160Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-02-12T19:30:08.061638159Z at async SelectQueryBuilder.loadRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2192:25)
2024-02-12T19:30:08.061642968Z at async SelectQueryBuilder.executeEntitiesAndRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2040:26)
2024-02-12T19:30:08.061648148Z at async SelectQueryBuilder.getRawAndEntities (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:684:29)
2024-02-12T19:30:08.061652456Z at async SelectQueryBuilder.getOne (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:711:25)
2024-02-12T19:30:08.061657285Z at async AuthService.checkUserExists (/app/packages/twenty-server/dist/src/core/auth/services/auth.service.js:125:22)
2024-02-12T19:30:08.061662604Z at async AuthResolver.checkUserExists (/app/packages/twenty-server/dist/src/core/auth/auth.resolver.js:45:28)
2024-02-12T19:30:08.061667263Z at async target (/app/node_modules/@nestjs/core/helpers/external-context-creator.js:74:28)
2024-02-12T19:30:08.061671942Z at async Object.checkUserExists (/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24) {
2024-02-12T19:30:08.061676841Z path: [ 'checkUserExists' ],
2024-02-12T19:30:08.061683253Z locations: [ [Object] ],
2024-02-12T19:30:08.061687611Z extensions: [Object: null prototype]
2024-02-12T19:30:08.060903238Z '}',
2024-02-12T19:30:08.060907506Z user: undefined
2024-02-12T19:30:08.060912786Z }
2024-02-12T19:30:08.061581282Z [
2024-02-12T19:30:08.061617991Z QueryFailedError: relation "core.user" does not exist
2024-02-12T19:30:08.061627289Z at PostgresQueryRunner.query (/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:219:19)
2024-02-12T19:30:08.061633160Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-02-12T19:30:08.061638159Z at async SelectQueryBuilder.loadRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2192:25)
2024-02-12T19:30:08.061642968Z at async SelectQueryBuilder.executeEntitiesAndRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2040:26)
2024-02-12T19:30:08.061648148Z at async SelectQueryBuilder.getRawAndEntities (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:684:29)
2024-02-12T19:30:08.061652456Z at async SelectQueryBuilder.getOne (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:711:25)
2024-02-12T19:30:08.061657285Z at async AuthService.checkUserExists (/app/packages/twenty-server/dist/src/core/auth/services/auth.service.js:125:22)
2024-02-12T19:30:08.061662604Z at async AuthResolver.checkUserExists (/app/packages/twenty-server/dist/src/core/auth/auth.resolver.js:45:28)
2024-02-12T19:30:08.061667263Z at async target (/app/node_modules/@nestjs/core/helpers/external-context-creator.js:74:28)
2024-02-12T19:30:08.061671942Z at async Object.checkUserExists (/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24) {
2024-02-12T19:30:08.061676841Z path: [ 'checkUserExists' ],
2024-02-12T19:30:08.061683253Z locations: [ [Object] ],
2024-02-12T19:30:08.061687611Z extensions: [Object: null prototype]
charles
charles11mo ago
looks like something is broken while initializing your database what does yarn database:reset gives as an output?
thilles
thillesOP11mo ago
got it working using yarn nx database:setup:prod
thilles
thillesOP11mo ago
though something is iffy, got lots of 500 errors from time to time. Page refresh sort of fixes it for a small time
No description
paulyili
paulyili11mo ago
I was getting the same errors as you when trying to self host it on docker. did you resolve it and get it working? Im super keen to try this CRM out.
charles
charles11mo ago
Your server is throwing 500, what do you see in your server logs?
thilles
thillesOP11mo ago
Sorry about the late response, time zone issues.. Error logs complains about
2024-02-13T20:51:10.454699368Z query failed: SELECT "Workspace"."id" AS "Workspace_id", "Workspace"."domainName" AS "Workspace_domainName", "Workspace"."displayName" AS "Workspace_displayName", "Workspace"."logo" AS "Workspace_logo", "Workspace"."inviteHash" AS "Workspace_inviteHash", "Workspace"."deletedAt" AS "Workspace_deletedAt", "Workspace"."createdAt" AS "Workspace_createdAt", "Workspace"."updatedAt" AS "Workspace_updatedAt", "Workspace"."allowImpersonation" AS "Workspace_allowImpersonation", "Workspace"."subscriptionStatus" AS "Workspace_subscriptionStatus" FROM "core"."workspace" "Workspace" WHERE ("Workspace"."id" = $1) LIMIT 1 -- PARAMETERS: ["20202020-1c25-4d02-bf25-6aeccf7ea419"]
2024-02-13T20:51:10.455208891Z error: error: relation "core.workspace" does not exist
2024-02-13T20:51:10.454699368Z query failed: SELECT "Workspace"."id" AS "Workspace_id", "Workspace"."domainName" AS "Workspace_domainName", "Workspace"."displayName" AS "Workspace_displayName", "Workspace"."logo" AS "Workspace_logo", "Workspace"."inviteHash" AS "Workspace_inviteHash", "Workspace"."deletedAt" AS "Workspace_deletedAt", "Workspace"."createdAt" AS "Workspace_createdAt", "Workspace"."updatedAt" AS "Workspace_updatedAt", "Workspace"."allowImpersonation" AS "Workspace_allowImpersonation", "Workspace"."subscriptionStatus" AS "Workspace_subscriptionStatus" FROM "core"."workspace" "Workspace" WHERE ("Workspace"."id" = $1) LIMIT 1 -- PARAMETERS: ["20202020-1c25-4d02-bf25-6aeccf7ea419"]
2024-02-13T20:51:10.455208891Z error: error: relation "core.workspace" does not exist
thilles
thillesOP11mo ago
But doing yarn command command workspace:health -w 20202020-1c25-4d02-bf25-6aeccf7ea419 gives "Workspace is healhty" 🤔
charles
charles11mo ago
your database does not looks to be initialized. What are you using to host your postgres database? twenty-postgres container?
thilles
thillesOP11mo ago
yes, twenty-postgres:0.3.0. Just did a yarn database:reset just before this
charles
charles11mo ago
ok, could you post the output of yarn database:reset?
thilles
thillesOP11mo ago
/app/packages/twenty-server # yarn database:reset Performed 'Dropping all schemas...' successfully Performed 'create schema "public"' successfully Performed 'create schema "metadata"' successfully Performed 'create schema "core"' successfully Performed 'create extension pg_graphql' successfully Performed 'create extension "uuid-ossp"' successfully Performed 'create extension "postgres_fdw"' successfully Performed 'create extension "wrappers"' successfully Performed 'create extension "mysql_fdw"' successfully Performed 'create airtable "wrappers"' successfully Performed 'create bigQuery "wrappers"' successfully Performed 'create clickHouse "wrappers"' successfully Performed 'create firebase "wrappers"' successfully Performed 'create logflare "wrappers"' successfully Performed 'create s3 "wrappers"' successfully Performed 'create stripe "wrappers"' successfully Performed 'inflect names for graphql' successfully Performed 'create function graphql' successfully
charles
charles11mo ago
and then?
thilles
thillesOP11mo ago
still thinking
charles
charles11mo ago
😄
thilles
thillesOP11mo ago
are there some reference specs to the containers? currently at 1vcpu/2Gi
charles
charles11mo ago
this should be good enough 🙂
thilles
thillesOP11mo ago
charles
charles11mo ago
and it should become better and better with time, we are way underestimate currently Ok, looks perfect is your server up?
thilles
thillesOP11mo ago
yes
charles
charles11mo ago
is it still complaining about missing core.workspace being missing?
thilles
thillesOP11mo ago
Not workspace, but get some error: relation "metadata.dataSource" does not exist when trying to create an api token
charles
charles11mo ago
that's weird, can you connect to your database through psql or a postgresql UI and check what you have? maybe you don't use the right database?
thilles
thillesOP11mo ago
When it first fails, it then just starts a domino effect and nearly all calls get a 500 yeah got access using psql
charles
charles11mo ago
do you see a default database with core and metadata schema and these schema shoul have tables
charles
charles11mo ago
No description
charles
charles11mo ago
it should look like this
thilles
thillesOP11mo ago
$ psql -U twenty -d default
Password for user twenty:
psql (15.5)
Type "help" for help.

default=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+--------
public | wrappers_fdw_stats | table | twenty
(1 row)

default=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
default | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
(5 rows)
$ psql -U twenty -d default
Password for user twenty:
psql (15.5)
Type "help" for help.

default=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+--------
public | wrappers_fdw_stats | table | twenty
(1 row)

default=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
default | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
(5 rows)
not that fluent in psql, do you have some commands?
charles
charles11mo ago
ok, it looks like your default database is not initialized you only have public schema I don't get it :p
thilles
thillesOP11mo ago
default=# \dn
List of schemas
Name | Owner
-------------------------------------+--------
core | twenty
graphql | twenty
metadata | twenty
public | twenty
workspace_1wgvd1injqtife6y4rvfbu3h5 | twenty
(5 rows)
default=# \dn
List of schemas
Name | Owner
-------------------------------------+--------
core | twenty
graphql | twenty
metadata | twenty
public | twenty
workspace_1wgvd1injqtife6y4rvfbu3h5 | twenty
(5 rows)
charles
charles11mo ago
oh ok! makes more sense
thilles
thillesOP11mo ago
good
charles
charles11mo ago
can you check what you have in metadata
thilles
thillesOP11mo ago
default=# \dt metadata.* List of relations Schema | Name | Type | Owner
----------+-----------------------+-------+-------- metadata | _typeorm_migrations | table | twenty metadata | dataSource | table | twenty metadata | fieldMetadata | table | twenty metadata | objectMetadata | table | twenty metadata | relationMetadata | table | twenty metadata | workspaceCacheVersion | table | twenty metadata | workspaceMigration | table | twenty (7 rows)
charles
charles11mo ago
so it's there
thilles
thillesOP11mo ago
yeah
charles
charles11mo ago
could you share your PG_DATABASE_URL? is the user twenty?
thilles
thillesOP11mo ago
probably worth mentioning this is hosted in azure container apps, not locally somewhere PG_DATABASE_URL=postgres://twenty:twenty@sens-twenty-db:5432/default
charles
charles11mo ago
looks good too would it be possible that you have multiple replicas? several postgres container running?
thilles
thillesOP11mo ago
No other postgres containers. Yeah, I´ve been searching through others issues and not found any potential config errors I´ve missed
charles
charles11mo ago
I'm running out of ideas, this should work. How is Azure interfering with application level stuff Could you share your Azure config? is server container always failing the same way? do you feel that some database queries are working? does yarn command command workspace:health -w 20202020-1c25-4d02-bf25-6aeccf7ea419 consistently returns healthy? that's so weird
thilles
thillesOP11mo ago
thilles
thillesOP11mo ago
# Variables
locals {
tag = "latest"
db_user = "twenty"
db_password = "twenty"
backend_app_name = "sens-twenty-server"
frontend_app_name = "sens-twenty-frontend"
database_app_name = "sens-twenty-db"
storage_mount_db_name = "twentydbstoragemount"
storage_mount_server_name = "twentyserverstoragemount"
cpu = 1.0
memory = "2Gi"
}
# Variables
locals {
tag = "latest"
db_user = "twenty"
db_password = "twenty"
backend_app_name = "sens-twenty-server"
frontend_app_name = "sens-twenty-frontend"
database_app_name = "sens-twenty-db"
storage_mount_db_name = "twentydbstoragemount"
storage_mount_server_name = "twentyserverstoragemount"
cpu = 1.0
memory = "2Gi"
}
workspace:health gives success each time
thilles
thillesOP11mo ago
Configure CORS in the Azure portal for Azure Container Apps
Learn how to configure your static web app to allow cross origin resource sharing (CORS) for Azure Container Apps
charles
charles11mo ago
mmmmh, ok, so the logs you provided for the server are actually old bugs! all right, it MAKES sense to check it, can you go to your server url on /graphql Do you have an error in the browser console regarding cors?
thilles
thillesOP11mo ago
reaching /graphql. Should I run something specific? No cors errors
charles
charles11mo ago
Can you show me your network tab while you reload the frontend?
thilles
thillesOP11mo ago
No description
charles
charles11mo ago
oh so it's running!
thilles
thillesOP11mo ago
As soon as I try moving an opportunity this happens. Each time
No description
charles
charles11mo ago
the "An error occured" is a known bug, it should not impact the app We have a PR open to fix this, just ignore it for now so it seems to be working 🙂
thilles
thillesOP11mo ago
wait a sec. there some references to strict-origin-when-cross-origin when graphql gets a 500
No description
thilles
thillesOP11mo ago
I was unclear. When I try moving an opportunity I get apolloerrors, and the opportunity moves back to its original placement Have to try more tomorrow, thanks for the help so far
charles
charles11mo ago
what do you have in your server logs when you generate this 500?
thilles
thillesOP11mo ago
I tinkered some with Azure routing settings, and it got somewhat better. But I still get some intermittent 500 errors.
charles
charles11mo ago
Hi @thilles, did you manage to get it working?
thilles
thillesOP11mo ago
Yeah, late last night I had a breakthrough. The FRONT_BASE_URL and REACT_APP_SERVER_BASE_URL were referring to old revisions of the docker containers. And each time I tried a bugfix, a new revision was created. Once I changed the variables to reference a fqdn without the container revision part things have been much smoother. Only thing I've seen so far is that when trying to remove a profile picture, i get an error. But I believe this is a bug more than connected. Btw, what's the correct way of setting up the db for production use? It's still somewhat hard to tell from the self hosting docs. After even more debugging I found that the db keeps shutting down and restarting. That´s probably why all those 500 errors and complaints that different tables don´t exist. Using image twenty-postgres:0.3.1. Heard about that before?
charles
charles11mo ago
It restarts without any warning? Have you tried increasing the memory / cpu of the postgres instance to see if it solves the problem? I don't see any reason why the database container itself would restart or maybe it's a health check issue? twenty-postgres is made for production (it's the one we use on our cloud) so that's the correct way to host a db in production right now. (You can also use your own postgres instance on a server and configure it the same way we do in the Dockerfile)
thilles
thillesOP11mo ago
thinking it´s a health check issue. Seeing messages received smart shutdown request and Type":"Warning","ContainerAppName":"twenty-postgres","RevisionName":"twenty-postgres--cmhqnjb","ReplicaName":"twenty-postgres--cmhqnjb-cd88778c-svbc2","Msg":"readiness probe failed: connection refused","Reason":"ReplicaUnhealthy","EventSource":"ContainerAppController","Count":3}
charles
charles11mo ago
this might be it! What is your health check configuration? If it's configured to get 200 like a web server, this might be the issue
thilles
thillesOP10mo ago
Think I finally figured it out! The postgres container auto-scaled and made multiple replicas, but they didn´t replicate the schemas. The solution was setting a max=1 option on number of replicas. @charles any tips on how to get a new icon for the self-host docs? Making a PR for this. Thinking using the IconBrandAzure, but don´t know how that will render
---
title: Azure Container Apps
sidebar_position: 2
sidebar_custom_props:
icon: IconBrandAzure
---
---
title: Azure Container Apps
sidebar_position: 2
sidebar_custom_props:
icon: IconBrandAzure
---
charles
charles10mo ago
@thilles sorry about the slow answer, we've merged your work today a big thank you!
thilles
thillesOP10mo ago
Might want to revert that @charles Found out the postgres container used ephemeral storage, i.e. the default database is wiped between restarts😬 I'll have to figure out a solution. Will post a new PR when it's fixed
charles
charles10mo ago
Haha indeed, it might be an issue 😄
charles
charles10mo ago
can we easily shift to a permanent storage?
Want results from more Discord servers?
Add your server