WongSaang/chatgpt-ui

Can't add database

Closed this issue · 11 comments

hi, first off just wanted to say that I really like your project!. but I have 1 issue. when I'm trying to add a database. I constantly get a Server error. I don't really understand the documentation on adding a database. if you could guide me in the right direction on how to add a database then that would be nice. here's the docker-compose I have right now

version: '3'
services:
  client:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-client:latest
    environment:
      - SERVER_DOMAIN=http://backend-web-server
      - NUXT_PUBLIC_APP_NAME='Brams ChatGPT' # The name of the application
#      - NUXT_PUBLIC_TYPEWRITER=true # Whether to enable the typewriter effect, default false
#      - NUXT_PUBLIC_TYPEWRITER_DELAY=50 # The delay time of the typewriter effect, default 50ms
    depends_on:
      - backend-web-server
    ports:
      - '${CLIENT_PORT:-82}:80'
    networks:
      - chatgpt_ui_network
    restart: always
  backend-wsgi-server:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-wsgi-server:latest
    environment:
      - APP_DOMAIN=${APP_DOMAIN:-192.168.178.4:9000}
      - SERVER_WORKERS=3
      - WORKER_TIMEOUT=180
      - DB_URL=mysql://chatgpt:$password@localhost:3306/chatgpt 
      - DJANGO_SUPERUSER_USERNAME=admin 
      - DJANGO_SUPERUSER_PASSWORD=password
      - DJANGO_SUPERUSER_EMAIL=admin@example.com
      - ACCOUNT_EMAIL_VERIFICATION=${ACCOUNT_EMAIL_VERIFICATION:-none}
    ports:
      - '${WSGI_PORT:-8001}:8000'
    networks:
      - chatgpt_ui_network
    restart: always
  backend-web-server:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-web-server:latest
    environment:
      - BACKEND_URL=http://backend-wsgi-server:8000
    ports:
      - '${SERVER_PORT:-9000}:80'
    depends_on:
      - backend-wsgi-server
    networks:
      - chatgpt_ui_network
    restart: always
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: 'chatgpt'
      MYSQL_USER: 'chatgpt'
      MYSQL_PASSWORD: '$password'
      MYSQL_ROOT_PASSWORD: '$password'
    networks:
      - chatgpt_ui_network
    volumes:
      - my-db:/var/lib/mysql
volumes:
  my-db:

networks:
  chatgpt_ui_network:
    driver: bridge

In a Docker container, "localhost" refers to the container itself, not the host machine. Therefore, if an application within the container needs to access a service on the host machine, it needs to use the host machine's IP address or the special DNS name "host.docker.internal" provided by Docker.

Therefore, it is recommended that you modify the database url to:

DB_URL=mysql://chatgpt:$password@host.docker.internal:3306/chatgpt

Good luck to you!

hmm, I have been trying to find a solution for a couple of days now. but I just cant seem to figure it out.

wouldn't it be a good idea to create a docker-compose file with a database already connected. if you, or someone else already has one. please feel free to share them with me. because id love to use your project to share with my family and friends. but I just cant seem to adjust it for my needs

idonda commented

Hi, I tried and it connects to the mysql database, but when I try the login it does not find any data, missing tables, etc.
Does the app initialise the database or did I miss any configuration step?

Can you successfully log in to the admin panel?

idonda commented

no, it does not login because it does not find any table, so I switched back to sqlite with persistent config.
The mysql database is initialised at startup?

i got past the 500 (Server Error) with a connected database by using the following docker compose file. but everytime i try signing up. or logging in. i get an error. is there anyway i can debug the problem?
image

version: '3'
services:
  client:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-client:latest
    environment:
      - SERVER_DOMAIN=http://backend-web-server
      - DEFAULT_LOCALE=en
    depends_on:
      - backend-web-server
    ports:
      - '${CLIENT_PORT:-80}:80'
    networks:
      - chatgpt_ui_network
    restart: always

  backend-wsgi-server:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-wsgi-server:v2.3.8
    environment:
      - APP_DOMAIN=${APP_DOMAIN:-localhost:9000}
      - SERVER_WORKERS=3
      - DB_URL=postgres://postgres:postgrespw@db/chatgpt
      - DJANGO_SUPERUSER_USERNAME=admin
      - DJANGO_SUPERUSER_PASSWORD=password
      - DJANGO_SUPERUSER_EMAIL=admin@example.com
      - ACCOUNT_EMAIL_VERIFICATION=${ACCOUNT_EMAIL_VERIFICATION:-none}
      - EMAIL_HOST=smtp.gmail.com
      - EMAIL_PORT=587
      - EMAIL_HOST_USER=<your email>
      - EMAIL_HOST_PASSWORD=<your email password>
      - EMAIL_USE_TLS=True
      - EMAIL_FROM=no-reply@example.com
    ports:
      - '${WSGI_PORT:-8001}:8000'
    networks:
      - chatgpt_ui_network
    depends_on:
      - db
    restart: always

    backend-web-server:
    platform: linux/x86_64
    image: wongsaang/chatgpt-ui-web-server:latest
    environment:
      - BACKEND_URL=http://backend-wsgi-server:8001
    ports:
      - '${SERVER_PORT:-9000}:80'
    depends_on:
      - backend-wsgi-server
    networks:
      - chatgpt_ui_network
    restart: always

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgrespw
      - POSTGRES_DB=chatgpt
    volumes:
      - db_data:/var/lib/postgresql/data/
    networks:
      - chatgpt_ui_network
    restart: always

volumes:
  db_data:

networks:
  chatgpt_ui_network:
    driver: bridge

@BramSuurdje DB_URL is like DB_URL=postgres://{username}:{password}@{your server ip}:5432/chatgpt .

and you can use docker logs --tail 1000 -f {CONTAINER ID} to see the log.

@tangxinyuGit ok thank you. i coudnt find anything weird in the logs. but i have updated my DB_URL to DB_URL=postgres://postgres:postgrespw@db:5432/chatgpt but that doesnt seem like it fixes the issue. it would be nice to see a docker compose file with the db allready configured.

Unfortunately 'docker logs ' doesn't seem to actually have a log of the error messages - just a log of the HTTP requests.

172.22.0.3 - - [28/Apr/2023:01:34:08 +0000] "GET /api/chat/settings/ HTTP/1.0" 200 187 "http://<REDACTED>/account/signup" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
172.22.0.3 - - [28/Apr/2023:01:34:35 +0000] "POST /api/account/registration/ HTTP/1.0" 400 69 "http://<REDACTED>/account/signup" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"

I was able to get into the containers with docker exec -it <client-container> ash and docker exec -it <wsgi-container> bash, but wasn't able to find any useful log files that way either.

Any ideas on how to get the root-cause error message from somewhere? I suspect that would be more useful.

#192

I made these changes and it finally WORKED

Tazlad commented

Same issue here. tried every one's suggestion and still will not work with any database i try or even #192 solution did not work either. would be great if someone who has it working can add a compose file with working database. I love the project just disappointing I can't get it to a stage where I can deploy with database.