Repos / pytaku / 8440838cc8
commit 8440838cc8e0c3ae18b883fe3cf72b392e44c89b
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sat Aug 8 12:49:33 2020 +0700

    implement dev command, update README

diff --git a/README.md b/README.md
index 0abe6b0..6947d77 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,26 @@
+Live demo: https://dev.pytaku.com (db may be hosed any time, also expect bugs)
+
+Production instance coming When It's Ready (tm).
+
+Pytaku is a WIP web-based manga reader that keeps track of your reading
+progress and new chapter updates. Its design goals are:
+
+- Self-host friendly - if you have a UNIX-like server with python3.7+ and can
+  run `pip install`, you're good.
+
+- Optional javascript - it should work **well** without javascript, but
+  javascript enablers should still get extra UX goodies.
+
+- Phone/tablet friendly - although I hardly read any webtoons these days so the
+  phone experience may not be as polished.
+
+- KISSFFS, or **K**eep **I**t rea**S**onably **S**imple you **F**-ing
+  architecture **F**etishi**S**ts! Oftentimes I have enough practice on
+  industrial grade power tools at work so at home I want a change of pace.
+  Flask + raw SQL has been surprisingly comfy.
+
+# Development
+
 ```sh
 poetry install
 pip install --upgrade pip
@@ -5,7 +28,25 @@
       --global-option=fetch --global-option=--version --global-option=3.32.2 --global-option=--all \
       --global-option=build --global-option=--enable-all-extensions
 
-FLASK_ENV=development FLASK_APP=pytaku.main:app flask run
+pytaku-generate-config > pytaku.conf.json
+# fill stuff as needed
+
+# run migration script once
+pytaku-migrate
+
+# run 2 processes:
+pytaku-dev -p 8000  # development webserver
+pytaku-scheduler  # scheduled tasks e.g. update titles
+```
+
+# Production
+
+```sh
+pip install --user --upgrade pip
+pip install --user pytaku
+pip install https://github.com/rogerbinns/apsw/releases/download/3.32.2-r1/apsw-3.32.2-r1.zip \
+      --global-option=fetch --global-option=--version --global-option=3.32.2 --global-option=--all \
+      --global-option=build --global-option=--enable-all-extensions
 
 pytaku-generate-config > pytaku.conf.json
 # fill stuff as needed
@@ -14,6 +55,14 @@ # run migration script once
 pytaku-migrate
 
 # run 2 processes:
-pytaku -w 7 -b 0.0.0.0:5001  # web server
+pytaku -w 7  # production web server - args are passed as-is to gunicorn
 pytaku-scheduler  # scheduled tasks e.g. update titles
+
+# upgrades:
+pip install --user --upgrade pytaku
+pytaku-migrate
+# then restart `pytaku` & `pytaku-scheduler` processes
 ```
+
+I don't have to remind you to properly set up a firewall and a TLS-terminating
+reverse proxy e.g. nginx/caddy, right?
diff --git a/pyproject.toml b/pyproject.toml
index 7cbe9d7..aaee76d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -11,6 +11,7 @@ packages = [
 
 [tool.poetry.scripts]
 pytaku = "pytaku:serve"
+pytaku-dev = "pytaku:dev"
 pytaku-migrate = "pytaku:migrate"
 pytaku-generate-config = "pytaku:generate_config"
 pytaku-scheduler = "pytaku:scheduler"
diff --git a/src/pytaku/__init__.py b/src/pytaku/__init__.py
index 20ecd65..39751a3 100644
--- a/src/pytaku/__init__.py
+++ b/src/pytaku/__init__.py
@@ -19,6 +19,20 @@ def serve():
     subprocess.run(command)
 
 
+def dev():
+    import os
+    import subprocess
+    from sys import argv
+
+    command = ["flask", "run"] + argv[1:]
+    print("Running:", " ".join(command))
+
+    subprocess.run(
+        command,
+        env={"FLASK_ENV": "development", "FLASK_APP": "pytaku.main:app", **os.environ},
+    )
+
+
 def migrate():
     import argparse
     from .database.migrator import migrate