Skip to content

Commit

Permalink
Deployment docs (#121)
Browse files Browse the repository at this point in the history
* Add WEBSCOKET_URL and other env vars in readme

* Minor updates in nginx config as needed for SSL renewal

* Add a Readme for deployment with basic instructions
  • Loading branch information
kavitharaju authored Dec 5, 2023
1 parent 3b933f7 commit 897b163
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Environment variables and their default values,
* `DOMAIN=assistant.bible`
* `SUPABASE_URL`
* `SUPABASE_KEY`
* `SUPABASE_JWT_SECRET`
* `WEBSOCKET_URL=ws://localhost/chat`


If using default values, once started the app should be running at [http://localhost:8000](http://localhost:8000) and dev UI available at [http://localhost:8000/ui](http://localhost:8000/ui) and API docs at [http://localhost:8000/docs](http://localhost:8000/docs).
Expand Down Expand Up @@ -72,8 +74,10 @@ If using default values, once started the app should be running at [http://local
POSTGRES_DB_NAME=adotbcollection
POSTGRES_DB_USER=postgres
POSTGRES_DB_PASSWORD=secret
export SUPABASE_URL=https://<your_supabase_instance>.supabase.co
export SUPABASE_KEY=<your_supabase_key>
SUPABASE_URL=https://<your_supabase_instance>.supabase.co
SUPABASE_KEY=<your_supabase_key>
SUPABASE_JWT_SECRET=<from your account>
WEBSOCKET_URL=ws://localhost/chat
```
If you dont want to mess with the locally running postgres version, running it as a docker container is a safer alternative:
`docker run -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=adotbcollection -p 5432:5432 ankane/pgvector`
Expand Down
71 changes: 71 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## How to deploy

1. Log on to the server machine
`ssh <username>@<ipaddress>`

2. Clone the repo
`git clone https://github.com/BibleNLP/assistant.bible.git`

3. Environment Variables
`cd assistant.bible/deployment`

`touch .env`

`nano .env`

Add the following environment variables with appropriate values for your deployment

```
OPENAI_API_KEY=<sk-..>
WEBSOCKET_URL=ws://assistant.bible/chat
DOMAIN=assistant.bible
POSTGRES_DB_USER=adotbadmin
POSTGRES_DB_PASSWORD=<a strong password>
POSTGRES_DB_NAME=adotbcollection
MAX_COSINE_DISTANCE=0.2

SUPABASE_URL=<https://<your_supabase_instance>.supabase.co>
SUPABASE_KEY=<from your account>
SUPABASE_JWT_SECRET=<from your account>
```

These are the minimum set of values to be set. The full list is available in the main [README](../README.md)

4. Setup SSL cerificate
Follow the instructions [here](https://mindsers.blog/en/post/https-using-nginx-certbot-docker/).

The services "webserver"(nginx) and "certbot" are already inlcuded in our docker compose, those could be used to perform the steps in the article. Also the nginx configuration file is [here](./nginx/nginx.conf.template), which would need edits during the setting up process.

5. Start the app, with all services
`docker compose --env-file .env up -d`

## How to update code and redeploy

```
ssh <user>@<ipaddress>
cd assistant.bible
git pull origin <branch-name>
cd deployment
docker compose --env-file .env up --build --force-recreate -d
```


## How to renew the SSL certificate

```
ssh <user>@<ipaddress>
cd assistant.bible/deployment
docker compose run certbot renew
docker compose --env-file .env down
docker compose --env-file .env up -d
```

## How to connect to server database

We use postgres database. On the DBMS app that you use on your computer like PgAdmin, DBeaver etc, give the connection configuration as you have set us the DB here

* host = assistant.bible, dev.assistant.bible, the ip-address or the domain name you use for the deployment
* post = 5432, the default or the one you have given in ENV variable
* database name = what you have given in the ENV variable
* password = what you have given in the ENV variable

16 changes: 10 additions & 6 deletions deployment/nginx/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ server {
proxy_connect_timeout 300;
proxy_send_timeout 300;

# location /.well-known/acme-challenge/ {
# root /var/www/certbot;
# }
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://${CHAT_DOMAIN}$request_uri;
Expand All @@ -38,6 +38,10 @@ server {
ssl_certificate /etc/nginx/ssl/live/${CHAT_DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/${CHAT_DOMAIN}/privkey.pem;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location /chat {
proxy_pass http://chatbot:9000/chat;
proxy_http_version 1.1;
Expand Down Expand Up @@ -65,9 +69,9 @@ server {
server_name ${PROD_DOMAIN};
client_max_body_size 100M;

# location /.well-known/acme-challenge/ {
# root /var/www/certbot;
# }
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

proxy_read_timeout 300;
proxy_connect_timeout 300;
Expand Down

0 comments on commit 897b163

Please sign in to comment.