Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and automate deployment process #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from necsus import init_db

init_db()
11 changes: 11 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
poetry run python3 init_db.py
poetry run gunicorn --bind localhost:6277 server:app -w 1