Create HetznerUbuntuSetup.md (#492)

* Create HetznerUbuntuSetup.md

Step-by-step guide for someone who is starting from scratch on this project with a bare server.

* Updated Readme & Heroku

I submitted the original Heroku.md (to the discord) and they are way out of date. Just corrected them, moved the Hetzner file to the cloud deploy, and updated the readme to point to the file.

* Update HetznerUbuntuSetup.md

* Update README.md
This commit is contained in:
heathriel 2023-06-13 13:36:13 -05:00 committed by GitHub
parent bccd0cb3dd
commit 42583e7344
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 266 additions and 44 deletions

View file

@ -105,6 +105,7 @@ We apologize for any inconvenience caused by these changes. We hope you enjoy th
<details>
<summary><strong>Cloud Deployment</strong></summary>
* [Hetzner](docs/deployment/HetznerUbuntuSetup.md)
* [Heroku](docs/deployment/heroku.md)
</details>

View file

@ -0,0 +1,138 @@
*These instructions are designed for someone starting from scratch for a Ubuntu Installation. You can skip to any point that is useful for you.*
# Starting from Zero:
1. Login to Hetzner Cloud Console (https://console.hetzner.cloud/projects) and Create a new Ubuntu 20 Project with 4GB Ram. Do not worry about SSH keys *yet*.
Hetzner will email you the root password.
2. Once you have that, you can login with any SSH terminal with:
```
ssh root@<yourserverip>
```
3. Once you have logged in, immediately create a new, nonroot user:
```
adduser <yourusername>
usermod -aG sudo <yourusername>
```
4. Make sure you have done this correctly by double-checking you have sudo permissions:
```
getent group sudo | cut -d: -f4
```
Now, quit the terminal connection.
5. Create a local ssh key:
```
ssh-keygen -t ed25519
```
Copy the key from your local computer to the server:
```
ssh-copy-id -i <locationto>/id_rsa.pub <yourusername>@<yourserverip>
```
And then login to the server with that key:
```
ssh <yourusername>@<yourserverip>
```
When you login, now and going forward, it will ask you for the password for your ssh key now, not your user password. Sudo commands will always want your user password.
6. Add SSH to the universal server firewall and activate it.
- Run `sudo ufw allow OpenSSH`
- Run `sudo ufw enable`
7. Then, we need to install docker, update the system packages, and reboot the server:
```
sudo apt install docker
sudo apt install docker-compose
sudo apt update
sudo apt upgrade
sudo reboot
```
Ok, now that you have set up the SERVER, you will need to get all your tokens/apis/etc in order:
# PreReqs:
- Make sure you have all the needed variables for the following before moving forward
## [Get Your API keys and Tokens](../install/apis_and_tokens.md) (Required)
- You must set up at least one of these tokens or APIs to run the app.
## [User/Auth System](../features/user_auth_system.md) (Optional)
- How to set up the user/auth system and Google login.
## [Plugins](../features/plugins/introduction.md)
- Optional plugins available to enhance the application.
# Using Docker to Install the Service
1. **Recommended: [Docker Install](../install/docker_install.md)**
From the *server* commandline (as your user, not root):
```
git clone https://github.com/danny-avila/LibreChat.git
```
Edit your docker-compose.yml to endure you have the correct environment variables:
```
nano docker-compose.yml
```
```
VITE_APP_TITLE: LibreChat # default, change to your desired app >
VITE_SHOW_GOOGLE_LOGIN_OPTION: 'false' # default, change to true if you want to show google login
```
2. Create a global environment file and open it up to begin adding the tokens/keys you prepared in the PreReqs section.
```
cp .env.example .env
nano .env
```
3. In addition to adding all your api tokens and other tokens that you prepared above, change:
```
HOST=Localhost
```
to
```
HOST=<yourserverip>
```
4. Since you're using docker, you can also change the following:
```
SEARCH=true
MEILI_HOST=meilisearch
MEILI_HTTP_ADDR=meilisearch
```
5. After everything file has been updated, run `docker-compose build` then `docker-compose up`
**NOTE: You may need to run these commands with sudo permissions.**
# Once the app is running, you can access it at http://yourserverip:3080
It is safe to close the terminal -- the docker app will continue to run.
*To disable external signups, after you have created your admin account, make sure you set
```
ALLOW_REGISTRATION:False
```
### Note: If you're still having trouble, before creating a new issue, please search for similar ones on our [#issues thread on our discord](https://discord.gg/weqZFtD9C4) or our [troubleshooting discussion](https://github.com/danny-avila/LibreChat/discussions/new?category=troubleshooting) on our Discussions page. If you don't find a relevant issue, feel free to create a new one and provide as much detail as possible.
---
## [Go Back to ReadMe](../../README.md)

View file

@ -1,88 +1,164 @@
# Heroku Deployment
⚠️ If you have issues, see this discussion first: https://github.com/danny-avila/LibreChat/discussions/339
- To run LibreChat on a server, you can use cloud hosting platforms like Heroku, DigitalOcean, or AWS. In this response, I'll provide instructions for deploying the project on Heroku. Other platforms will have slightly different deployment processes.
- To run LibreChat on a server, you can use cloud hosting platforms like Heroku, DigitalOcean, or AWS. In this response, I'll provide instructions for deploying the project on Heroku. Other platforms will have slightly different deployment processes.
Heroku only supports running a single process within a Docker container. The Dockerfile for this project has two different processes - one is for serving your Node API and the other for serving your client with Nginx. In the context of Heroku, these should be considered two separate apps.
If you want to deploy both these services to Heroku, you will need to create two separate Dockerfiles: one for the API and one for the client. The heroku.yml should be configured separately for each app, and then you need to create and deploy two different Heroku apps.
- Sign up for a Heroku account: If you don't already have a Heroku account, sign up at https://signup.heroku.com/.
- Install the Heroku CLI: Download and install the Heroku CLI from https://devcenter.heroku.com/articles/heroku-cli.
- Login to Heroku: Open Terminal and run ***heroku login***. Follow the instructions to log in to your Heroku account.
- Prepare the repository: You need to create a Procfile in the root directory of LibreChat to specify the commands that will be executed to start the application. Create a new file named Procfile (without any file extension) and add the following line:
Here are the steps to deploy on Heroku:
1. **Create a new Dockerfile for your API named `Dockerfile-api`:**
```
web: npm start --prefix api
# Base node image
FROM node:19-alpine AS base
WORKDIR /api
COPY /api/package*.json /api/
WORKDIR /
COPY /package*.json /
RUN npm ci
# Node API setup
FROM base AS node-api
WORKDIR /api
COPY /api/ /api/
EXPOSE $PORT
ENV HOST=0.0.0.0
CMD ["npm", "start"]
```
- Commit your changes: Commit the Procfile and any other changes to your GitHub repository.
Create a new Heroku app: Run the following command in the Terminal to create a new Heroku app:
2. **Create a new Dockerfile for your Client named `Dockerfile-client`:**
```
heroku create your-app-name
# Base node image
FROM node:19-alpine AS base
WORKDIR /client
COPY /client/package*.json /client/
WORKDIR /
COPY /package*.json /
RUN npm ci
# React client build
FROM base AS react-client
WORKDIR /client
COPY /client/ /client/
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run build
# Nginx setup
FROM nginx:stable-alpine AS nginx-client
WORKDIR /usr/share/nginx/html
COPY --from=react-client /client/dist /usr/share/nginx/html
COPY client/nginx.conf /etc/nginx/conf.d/default.conf
ENTRYPOINT ["nginx", "-g", "daemon off;"]
```
- Replace your-app-name with a unique name for your app.
- Set environment variables: Configure the environment variables for your Heroku app. You can either use the Heroku CLI or the Heroku Dashboard.
3. **Build and deploy your apps using the Heroku CLI:**
**Using Heroku CLI:**
Login to Heroku:
```
heroku config:set KEY_NAME=KEY_VALUE --app your-app-name
heroku login
```
- Replace KEY_NAME and KEY_VALUE with the appropriate key names and values from your .env file. Repeat this command for each environment variable.
Login to the Heroku Container Registry:
```
heroku container:login
```
Create a Heroku app for your API:
```
heroku create your-api-app-name
```
Set environment variables for your API app:
```
heroku config:set HOST=0.0.0.0 --app your-api-app-name
```
Build and deploy your API app:
```
heroku container:push web --app your-api-app-name -f Dockerfile-api
heroku container:release web --app your-api-app-name
```
Create a Heroku app for your client:
```
heroku create your-client-app-name
```
Build and deploy your client app:
```
heroku container:push web --app your-client-app-name -f Dockerfile-client
heroku container:release web --app your-client-app-name
```
4. **Open your apps in a web browser:**
```
heroku open --app your-api-app-name
heroku open --app your-client-app-name
```
Remember to replace `your-api-app-name` and `your-client-app-name` with the actual names of your Heroku apps.
⚠️ If you have issues, see this discussion first: https://github.com/danny-avila/LibreChat/discussions/339
**Using Heroku Dashboard:**
- Go to your app's settings page in the Heroku Dashboard. Under the "Config Vars" section, add the required environment variables.
- Deploy the app to Heroku: Run the following commands to deploy LibreChat to Heroku:
```
git remote add heroku https://git.heroku.com/your-app-name.git
git push heroku main
```
- Replace your-app-name with the name of your Heroku app.
- Open the app: After the deployment is complete, you can open the app in your browser by running heroku open or by visiting the app's URL.
- Here are the instructions for setting up MongoDB Atlas and deploying MeiliSearch on Heroku:
*NOTE: If the heroku docker image process still needs an external mongodb/meilisearch, here are the instructions for setting up MongoDB Atlas and deploying MeiliSearch on Heroku:*
**Setting up MongoDB Atlas:**
**Setting up MongoDB Atlas:
- Sign up for a MongoDB Atlas account: If you don't have an account, sign up at https://www.mongodb.com/cloud/atlas/signup.
- Create a new cluster: After signing in, create a new cluster by following the on-screen instructions. For a free tier cluster, select the "Shared" option and choose the "M0 Sandbox" tier.
Sign up for a MongoDB Atlas account: If you don't have an account, sign up at https://www.mongodb.com/cloud/atlas/signup.
- Configure database access: Go to the "Database Access" section and create a new database user. Set a username and a strong password, and grant the user the "Read and Write to any database" privilege.
Create a new cluster: After signing in, create a new cluster by following the on-screen instructions. For a free tier cluster, select the "Shared" option and choose the "M0 Sandbox" tier.
- Configure network access: Go to the "Network Access" section and add a new IP address. For testing purposes, you can allow access from anywhere by entering 0.0.0.0/0. For better security, whitelist only the specific IP addresses that need access to the database.
- Get the connection string: Once the cluster is created, click the "Connect" button. Select the "Connect your application" option and choose "Node.js" as the driver. Copy the connection string and replace <username> and <password> with the credentials you created earlier.
Configure database access: Go to the "Database Access" section and create a new database user. Set a username and a strong password, and grant the user the "Read and Write to any database" privilege.
**Deploying MeiliSearch on Heroku:**
- Install the Heroku CLI: If you haven't already, download and install the Heroku CLI from https://devcenter.heroku.com/articles/heroku-cli.
- Login to Heroku: Open Terminal and run heroku login. Follow the instructions to log in to your Heroku account.
Configure network access: Go to the "Network Access" section and add a new IP address. For testing purposes, you can allow access from anywhere by entering 0.0.0.0/0. For better security, whitelist only the specific IP addresses that need access to the database.
**Create a new Heroku app for MeiliSearch:**
Get the connection string: Once the cluster is created, click the "Connect" button. Select the "Connect your application" option and choose "Node.js" as the driver. Copy the connection string and replace and with the credentials you created earlier.
**Deploying MeiliSearch on Heroku:
Install the Heroku CLI: If you haven't already, download and install the Heroku CLI from https://devcenter.heroku.com/articles/heroku-cli.
Login to Heroku: Open Terminal and run heroku login. Follow the instructions to log in to your Heroku account.
Create a new Heroku app for MeiliSearch:
```
heroku create your-meilisearch-app-name
```
Replace your-meilisearch-app-name with a unique name for your MeiliSearch app.
- Replace your-meilisearch-app-name with a unique name for your MeiliSearch app.
**Set the buildpack:**
Set the buildpack:
```
heroku buildpacks:set meilisearch/meilisearch-cloud-buildpack --app your-meilisearch-app-name
```
**Set the master key for MeiliSearch:**
Set the master key for MeiliSearch:
```
heroku config:set MEILI_MASTER_KEY=your-master-key --app your-meilisearch-app-name
Replace your-master-key with a secure master key.
```
**Deploy MeiliSearch:**
Replace your-master-key with a secure master key.
Deploy MeiliSearch:
```
git init
@ -91,8 +167,7 @@ git add .
git commit -m "Initial commit"
git push heroku master
```
- Get the MeiliSearch URL: After deployment, you can find the MeiliSearch URL by visiting your app's settings page in the Heroku Dashboard. The URL will be displayed under the "Domains" section.
Get the MeiliSearch URL: After deployment, you can find the MeiliSearch URL by visiting your app's settings page in the Heroku Dashboard. The URL will be displayed under the "Domains" section.
**Update environment variables in LibreChat:**
@ -105,6 +180,14 @@ git push heroku master
- Once you've updated the environment variables, LibreChat should be able to connect to MongoDB Atlas and MeiliSearch on Heroku.
```
heroku config:set KEY_NAME=KEY_VALUE --app your-app-name
```
- Replace KEY_NAME and KEY_VALUE with the appropriate key names and values from your .env file. Repeat this command for each environment variable.
### Note: If you're still having trouble, before creating a new issue, please search for similar ones on our [#issues thread on our discord](https://discord.gg/weqZFtD9C4) or our [troubleshooting discussion](https://github.com/danny-avila/LibreChat/discussions/new?category=troubleshooting) on our Discussions page. If you don't find a relevant issue, feel free to create a new one and provide as much detail as possible.
---
## [Go Back to ReadMe](../../README.md)