You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.5 KiB

11 months ago
  1. # Run AnythingLLM in production without Docker
  2. > [!WARNING]
  3. > This method of deployment is **not supported** by the core-team and is to be used as a reference for your deployment.
  4. > You are fully responsible for securing your deployment and data in this mode.
  5. > **Any issues** experienced from bare-metal or non-containerized deployments will be **not** answered or supported.
  6. Here you can find the scripts and known working process to run AnythingLLM outside of a Docker container.
  7. ### Minimum Requirements
  8. > [!TIP]
  9. > You should aim for at least 2GB of RAM. Disk storage is proportional to however much data
  10. > you will be storing (documents, vectors, models, etc). Minimum 10GB recommended.
  11. - NodeJS v18
  12. - Yarn
  13. ## Getting started
  14. 1. Clone the repo into your server as the user who the application will run as.
  15. `git clone git@github.com:Mintplex-Labs/anything-llm.git`
  16. 2. `cd anything-llm` and run `yarn setup`. This will install all dependencies to run in production as well as debug the application.
  17. 3. `cp server/.env.example server/.env` to create the basic ENV file for where instance settings will be read from on service start.
  18. 4. Ensure that the `server/.env` file has _at least_ these keys to start. These values will persist and this file will be automatically written and managed after your first successful boot.
  19. ```
  20. STORAGE_DIR="/your/absolute/path/to/server/storage"
  21. ```
  22. 5. Edit the `frontend/.env` file for the `VITE_BASE_API` to now be set to `/api`. This is documented in the .env for which one you should use.
  23. ```
  24. # VITE_API_BASE='http://localhost:3001/api' # Use this URL when developing locally
  25. # VITE_API_BASE="https://$CODESPACE_NAME-3001.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN/api" # for GitHub Codespaces
  26. VITE_API_BASE='/api' # Use this URL deploying on non-localhost address OR in docker.
  27. ```
  28. ## To start the application
  29. AnythingLLM is comprised of three main sections. The `frontend`, `server`, and `collector`. When running in production you will be running `server` and `collector` on two different processes, with a build step for compilation of the frontend.
  30. 1. Build the frontend application.
  31. `cd frontend && yarn build` - this will produce a `frontend/dist` folder that will be used later.
  32. 2. Copy `frontend/dist` to `server/public` - `cp -R frontend/dist server/public`.
  33. This should create a folder in `server` named `public` which contains a top level `index.html` file and various other files/folders.
  34. 3. Migrate and prepare your database file.
  35. ```
  36. cd server && npx prisma generate --schema=./prisma/schema.prisma
  37. cd server && npx prisma migrate deploy --schema=./prisma/schema.prisma
  38. ```
  39. 4. Boot the server in production
  40. `cd server && NODE_ENV=production node index.js &`
  41. 5. Boot the collection in another process
  42. `cd collector && NODE_ENV=production node index.js &`
  43. AnythingLLM should now be running on `http://localhost:3001`!
  44. ## Updating AnythingLLM
  45. To update AnythingLLM with future updates you can `git pull origin master` to pull in the latest code and then repeat steps 2 - 5 to deploy with all changes fully.
  46. _note_ You should ensure that each folder runs `yarn` again to ensure packages are up to date in case any dependencies were added, changed, or removed.
  47. _note_ You should `pkill node` before running an update so that you are not running multiple AnythingLLM processes on the same instance as this can cause conflicts.
  48. ### Example update script
  49. ```shell
  50. #!/bin/bash
  51. cd $HOME/anything-llm &&\
  52. git checkout . &&\
  53. git pull origin master &&\
  54. echo "HEAD pulled to commit $(git log -1 --pretty=format:"%h" | tail -n 1)"
  55. echo "Freezing current ENVs"
  56. curl -I "http://localhost:3001/api/env-dump" | head -n 1|cut -d$' ' -f2
  57. echo "Rebuilding Frontend"
  58. cd $HOME/anything-llm/frontend && yarn && yarn build && cd $HOME/anything-llm
  59. echo "Copying to Sever Public"
  60. rm -rf server/public
  61. cp -r frontend/dist server/public
  62. echo "Killing node processes"
  63. pkill node
  64. echo "Installing collector dependencies"
  65. cd $HOME/anything-llm/collector && yarn
  66. echo "Installing server dependencies & running migrations"
  67. cd $HOME/anything-llm/server && yarn
  68. cd $HOME/anything-llm/server && npx prisma migrate deploy --schema=./prisma/schema.prisma
  69. cd $HOME/anything-llm/server && npx prisma generate
  70. echo "Booting up services."
  71. truncate -s 0 /logs/server.log # Or any other log file location.
  72. truncate -s 0 /logs/collector.log
  73. cd $HOME/anything-llm/server
  74. (NODE_ENV=production node index.js) &> /logs/server.log &
  75. cd $HOME/anything-llm/collector
  76. (NODE_ENV=production node index.js) &> /logs/collector.log &
  77. ```