From 0837f9ad4187619fb24184c8c67186212f6bd9e1 Mon Sep 17 00:00:00 2001 From: Nathan Lam Date: Tue, 3 Jan 2023 22:50:45 +1100 Subject: [PATCH] Document and automate deployment process --- README.md | 34 +++++++++++++++++++++++++++++++--- init_db.py | 3 +++ install.sh | 11 +++++++++++ run.sh | 3 +++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 init_db.py create mode 100755 install.sh create mode 100755 run.sh diff --git a/README.md b/README.md index 4d4de6b..0723709 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,40 @@ Documentation on the API can be found on [the main NeCSuS server](https://chat.n ## Development -Run `python server.py` for the development server. This also inits the db if it +Run `python3 server.py` for the development server. This also inits the db if it isn't already. -Gunicorn is used for the production server (see the `Procfile`). `python -server.py` must still be run at least once beforehand to init the db. +## Deployment +This server has been most recently deployed on a Digital Ocean droplet. Theoretically, this should be easily ported +onto another VPS service on a different cloud provider such as AWS or Azure. + +Once you've SSH'd into the server, open a `tmux` session. This makes it easier to run multiple servers at once (i.e. gunicorn and caddy). + +Hint: If you need help with using tmux, use `Ctrl+b ?`. + +Run the following to install the necessary dependencies and start the server on localhost. + +``` +./install.sh && ./run.sh +``` + +Add the following to `/etc/caddy/Caddyfile` (remove/comment out the default config) + +``` +chat.ncss.cloud { + reverse_proxy localhost:6277 + encode gzip +} +``` + +Reload the caddy server to read the new config file. + +``` +systemctl reload caddy +``` + +The URL https://chat.ncss.cloud/ should now display a simple chat server! ## FAQ diff --git a/init_db.py b/init_db.py new file mode 100644 index 0000000..61e98e2 --- /dev/null +++ b/init_db.py @@ -0,0 +1,3 @@ +from necsus import init_db + +init_db() \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..87e3080 --- /dev/null +++ b/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Install dependencies including caddy to reverse proxy +sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https +curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg +curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list +sudo apt update +sudo apt install python3-pip python3-dev python3-cachecontrol python3-poetry caddy + +# Install dependencies +poetry install diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..3a97a4e --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +poetry run python3 init_db.py +poetry run gunicorn --bind localhost:6277 server:app -w 1