twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
GNU Affero General Public License v3.0
16.03k stars 1.81k forks source link

docker -> local directory for volume db-data -> no user login #5880

Open patschwork opened 3 months ago

patschwork commented 3 months ago

Bug Description

When using a local directory for storing the db-data content, you can't login after fresh setup. The hint here doesn't work: https://twenty.com/developers/section/self-hosting/docker-compose#not-able-to-login

Example:

Excerpt from docker-compose.yml


  db:
    image: twentycrm/twenty-postgres:${TAG}
    volumes:
      - ./db-data:/bitnami/postgresql.  # local directory with file permissions for UID 1001
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
    healthcheck:
      test: pg_isready -U twenty -d default
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always

volumes:
  docker-data:
  # db-data:
  server-local-data:

Expected behavior

Login/signup is possible as if it would be a docker managed volume

Workaround

It will work, when set the parameter ENABLE_DB_MIGRATIONS: "true" in the worker section of docker-compose.yml

Example:

  worker:
    image: twentycrm/twenty:${TAG}
    command: ["yarn", "worker:prod"]
    environment:
      PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}

      ENABLE_DB_MIGRATIONS: "true" # it already runs on the server #--------> set this to "true"

      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}

      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
      TELEMETRY_ENABLED: false. # will this work?!
      EMAIL_SMTP_HOST: 192.168.178.99 # does not work :-( -> https://twenty.com/developers/section/self-hosting/self-hosting-var#email-smtp-server-configuration-examples / smtp4dev
      EMAIL_SMTP_PORT: 2525 # does not work :-(  / smtp4dev
    depends_on:
      db:
        condition: service_healthy
      server:
        condition: service_healthy
    restart: always
greptile-apps[bot] commented 3 months ago

To resolve the issue with user login when using a local directory for db-data, update the docker-compose.yml file as follows:

  1. In the db service, ensure the volume is correctly mapped:

    db:
    image: twentycrm/twenty-postgres:${TAG}
    volumes:
      - ./db-data:/bitnami/postgresql  # local directory with file permissions for UID 1001
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
    healthcheck:
      test: pg_isready -U twenty -d default
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always
  2. In the worker service, set ENABLE_DB_MIGRATIONS to true:

    worker:
    image: twentycrm/twenty:${TAG}
    command: ["yarn", "worker:prod"]
    environment:
      PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}
      ENABLE_DB_MIGRATIONS: "true"  # Set this to true
      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
    depends_on:
      db:
        condition: service_healthy
      server:
        condition: service_healthy
    restart: always

This should allow login/signup to work as expected.

References

/packages/twenty-docker/docker-compose.yml /packages/twenty-postgres/docker/docker-compose.yml /packages/twenty-docker/.env.example /packages/twenty-server/.env.example /packages/twenty-website/src/content/developers/self-hosting/docker-compose.mdx

Ask Greptile

Freebios commented 2 weeks ago

Hey there, that's odd, the migration should be running on the server container and worker is waiting for the server to be healthy. I could not reproduce on a fresh install on my end.

Did you get any logs that could help us pinpoint the issue ?

patschwork commented 2 weeks ago

Hey there, that's odd, the migration should be running on the server container and worker is waiting for the server to be healthy. I could not reproduce on a fresh install on my end.

Did you get any logs that could help us pinpoint the issue ?

Hi, I looked into my notes, but I didn't save any output or logs. 🤷‍♂️

If you can't reproduce the error, feel free to close this issue.

Thanks for looking at it.