From 6f15abccbea6a3426f35c8da96a296580a349ac6 Mon Sep 17 00:00:00 2001 From: Runzhi He <46741383+12f23eddde@users.noreply.github.com> Date: Thu, 13 Oct 2022 02:23:04 +0800 Subject: [PATCH] doc: align deployment guides with code --- development/README.md | 51 +++++++++++++++++++++++++++ production/README.md | 81 ++++++++++++++++++++++--------------------- 2 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 development/README.md diff --git a/development/README.md b/development/README.md new file mode 100644 index 0000000..bfd326c --- /dev/null +++ b/development/README.md @@ -0,0 +1,51 @@ +### GFI-Bot Development Setup + +> **The dev setup is pretty alpha-stage, it's only tested on the production machine (Ubuntu 20.04) with one user.** + +#### Development Setup Explained + +`gfidev.sh` starts a MongoDB instance `gfidev_xxx_mongo`, a caddy webserver, and 2 screen sessions: + +**gfidev_xxx_vite** runs a vite dev server (with hmr, the dev frontend refreshes within 1 sec on code changes) + +**gfidev_xxx_backend** runs a FastAPI backend (automatically reloads on backend code changes; to avoid wasting rate limits, the background scheduler is disabled by default) + +#### Initial Setup + +##### Building the dataset + +The most effortless way to build the dev dataset is to copy it from the production server. (stop the production database before copying) + +```bash +cp -r +``` + +Alternatively, you may build the dataset from scratch. (this will take a while) + +```bash +GFIBOT_ENV=dev python3 -m gfibot.backend.scheduled_tasks --init +``` + +##### Starting the dev setup + +First, rename `example.env` to `.env` and set deployment configurations: + +**Note each GFI-Bot instance needs unique ports and a unique GFIBOT_DATA_DIR to avoid conflicts.** + +```ini +# MongoDB port (exposed to the host machine) +GFIBOT_MONGO_PORT=127.0.0.1:27021 # <- check pyproject.toml +# Backend port +GFIBOT_BACKEND_PORT=127.0.0.1:8123 +# Frontend https / http port +GFIBOT_HTTPS_PORT=80 +GFIBOT_HTTPS_PORT=443 +GFIBOT_DATA_DIR= +``` + +Then, run the dev setup: + +```bash +cd development/ +./gfidev.sh up +``` diff --git a/production/README.md b/production/README.md index 44f89b6..0d48be1 100644 --- a/production/README.md +++ b/production/README.md @@ -1,49 +1,50 @@ -### GFI-Bot Production Build - -> **Notice: Do not make the docker image public after building.** - -**Preliminary**, we're using docker-compose to build a production instance of GFI-Bot, which includes a Flask backend, a Mongo database, RecGFI and data retrieving modules. - -You should initially create a `production_secrets.json` file in this directory in order to register your GitHub APP id and secrets, as well as information of a g-mail account (if you want to send emails to users). The file should be laid out as below: - -```json -{ - "web_client": { - "id": "$web_client_id", - "secret": "$web_client_secret" - }, - "git_app": { - "id": "$github_app_id", - "secret": "$github_app_secret" - }, - "mail": { - "email": "$gmail_address", - "password": "$gmail_service_password" - } -} +### GFI-Bot Development Setup + +> **The dev setup is pretty alpha-stage, it's only tested on the production machine (Ubuntu 20.04) with one user.** + +#### Development Setup Explained + +`gfidev.sh` starts a MongoDB instance `gfidev_xxx_mongo`, a caddy webserver (the CORS walkaround), and 2 screen sessions: + +**gfidev_xxx_vite** runs a vite dev server (with hmr, the dev frontend refreshes within 1 sec on code changes) + +**gfidev_xxx_backend** runs a FastAPI backend (automatically reloads on backend code changes; to avoid wasting rate limits, the background scheduler is disabled by default) + +#### Building the dataset + +The most effortless way to build the dev dataset is to copy it from the production server. (stop the production database before copying) + +```bash +cp -r ``` -Then, try executing +Alternatively, you may build the dataset from scratch. (this will take a while) ```bash -cd production -./gfibot.sh up +GFIBOT_ENV=dev python3 -m gfibot.backend.scheduled_tasks --init ``` -to start your GFI-Bot service. +#### Starting the dev setup -The docker image been built doesn't consist a web server, so it's up to you to choose which kind of web server to use. Currently, we're using [caddy](https://caddyserver.com/) as our web server. A Caddy file as below would be capable for development environment: +First, rename `example.env` to `.env` and set deployment configurations: +**Note each GFI-Bot instance needs unique ports and a unique GFIBOT_DATA_DIR to avoid conflicts.** + +```ini +# MongoDB port (exposed to the host machine) +# NEVER expose the production database to internet +GFIBOT_MONGO_PORT=127.0.0.1:27021 # <- check pyproject.toml +# Backend port +GFIBOT_BACKEND_PORT=127.0.0.1:8123 +# Frontend https / http port +GFIBOT_HTTP_PORT=80 +GFIBOT_HTTPS_PORT=443 +GFIBOT_DATA_DIR= +``` + +Then, run the dev setup: + +```bash +cd production/ +./gfidev.sh up ``` -$your_web_domain { - route { - reverse_proxy /api/* $your_server_url { - header_down +Access-Control-Allow-Origin "*" - header_down +Access-Control-Allow-Methods "OPTIONS, DELETE, GET, HEAD, POST, PUT" - } - root * $frontend_builds_location - try_files {path} /index.html - file_server - } -} -``` \ No newline at end of file