Repos / pytaku / cb2a624528
commit cb2a624528aa83dad10446888346c2b0d4ca0113
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sat Sep 18 23:45:28 2021 +0700

    migrate to new debian 11 server
    
    Deploy pipeline went from 6 minutes to 50 seconds.
    Not bad at all.

diff --git a/.builds/ubuntu.yml b/.builds/debian.yml
similarity index 59%
rename from .builds/ubuntu.yml
rename to .builds/debian.yml
index 1d3bae4..cd955dd 100644
--- a/.builds/ubuntu.yml
+++ b/.builds/debian.yml
@@ -1,9 +1,9 @@
-image: ubuntu/bionic
+image: debian/bullseye
 
 secrets:
   # PyPI token for pytaku:
   - 8c42b8a6-d1b7-4af7-82f2-b8f1b6e085e2
-  # ssh key for dev.pytaku.com:
+  # ssh key for pytaku.imnhan.com:
   - 2d6e3246-5adc-41c2-bebe-01dacda9d0c8
   # ~/pytaku.conf.json:
   - d18b6657-ac13-4413-8349-8ef262142545
@@ -16,20 +16,17 @@ environment:
 
 packages:
   - curl
-  - python3.7-dev
-  - python3.7-venv
   - python3-pip
-  - npm
+  - python3-apsw
+  - python3-venv
+  - esbuild
 
 tasks:
   - setup: |
-      python3.7 -m pip install pipx
-      python3.7 -m pipx install poetry==1.1.6
-      cd pytaku
-      poetry install --no-dev
-      poetry run 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
+      pip3 install pipx
+      python3 -m pipx install poetry==1.1.6
+      #cd pytaku
+      #poetry install --no-dev
 
   #- test: |
       #cd pytaku
@@ -38,8 +35,7 @@ tasks:
 
   - build: |
       cd pytaku
-      npm install -g --prefix ~/.node_modules esbuild
-      ~/.node_modules/bin/esbuild \
+      esbuild \
         src/pytaku/js-src/main.js \
         --bundle --sourcemap --minify \
         --outfile=src/pytaku/static/js/main.min.js
@@ -58,24 +54,22 @@ tasks:
 
   - deploy-dev: |
       cd pytaku
-      echo "dev.pytaku.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAQ1jWerB3GUGRhaZZzgpRyCSwo7PRi1cPbokaAwwsAKts1dkXSdCtR9xoTXKdvhASX5xafdzHZqbyFzpc0RleM=" >> ~/.ssh/known_hosts
+      echo "pytaku.imnhan.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBpDNzSaWLPXnb2XaGNgvlNnEcVbdrUUWHfBcuzJ1DyDU2fa+f1ojSFddfNMBrSRpU0GAPfpDoky6en866WH4gw=" >> ~/.ssh/known_hosts
+
       # Clean up old stuff just in case
-      ssh -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 pytaku@dev.pytaku.com 'rm -f /home/pytaku/pytaku*.whl'
+      ssh -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 pytaku@pytaku.imnhan.com 'rm -f /home/pytaku/pytaku*.whl'
       # Copy wheel & systemd service files over.
       # I'm not installing pytaku from pypi here because it may
       # take a loooong time for the new version to appear.
-      scp -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 dist/pytaku*.whl pytaku@dev.pytaku.com:/home/pytaku/
-      scp -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 contrib/systemd/*.service pytaku@dev.pytaku.com:/home/pytaku/.config/systemd/user/
+      scp -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 dist/pytaku*.whl pytaku@pytaku.imnhan.com:/home/pytaku/
       # Install & restart serivces
-      ssh -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 pytaku@dev.pytaku.com "
-        ~/.local/bin/pip install --user --force-reinstall pytaku*.whl &&
+      ssh -i ~/.ssh/2d6e3246-5adc-41c2-bebe-01dacda9d0c8 pytaku@pytaku.imnhan.com "
+        pip3 install --user --force-reinstall pytaku*.whl &&
         cd ~/pytaku &&
         ~/.local/bin/pytaku-migrate &&
         rm -r static &&
-        cp -r ~/.local/lib/python3.7/site-packages/pytaku/static ./ &&
-        systemctl --user daemon-reload &&
-        systemctl --user restart pytaku &&
-        systemctl --user restart pytaku-scheduler &&
+        cp -r ~/.local/lib/python3.9/site-packages/pytaku/static ./ &&
+        sudo systemctl restart pytaku pytaku-scheduler &&
         echo 'All done.'
       "
 
diff --git a/contrib/caddy/pytaku.caddy b/contrib/caddy/pytaku.caddy
index b8c547a..2a8976a 100644
--- a/contrib/caddy/pytaku.caddy
+++ b/contrib/caddy/pytaku.caddy
@@ -1,12 +1,12 @@
-dev.pytaku.com
-
-route {
-    # Assumes static dir has been synced to /home/pytaku/pytaku/static
-    # and the caddy user has permission to read it
-    file_server /static/* {
-        root /home/pytaku/pytaku
-        #browse
+pytaku.imnhan.com {
+    route {
+        # Assumes static dir has been synced to /home/pytaku/pytaku/static
+        # and the caddy user has permission to read it
+        file_server /static/* {
+            root /home/pytaku/pytaku
+            #browse
+        }
+        reverse_proxy /* localhost:5001
+        encode zstd gzip
     }
-    reverse_proxy /* localhost:5001
-    encode zstd gzip
 }
diff --git a/contrib/systemd/pytaku-scheduler.service b/contrib/systemd/pytaku-scheduler.service
index 5f8b9cf..6f3435d 100644
--- a/contrib/systemd/pytaku-scheduler.service
+++ b/contrib/systemd/pytaku-scheduler.service
@@ -1,18 +1,15 @@
-# this goes in ~/.config/systemd/user/pytaku-scheduler.service
-
-# systemctl --user daemon-reload
-# systemctl --user enable pytaku-scheduler
-# systemctl --user restart pytaku-scheduler
-# loginctl enable-linger <username>
-
 [Unit]
 Description=Pytaku scheduler
+After=network-online.target
+Wants=network-online.target systemd-networkd-wait-online.service
 
 [Service]
 Environment="PYTHONUNBUFFERED=1"
-ExecStart=/home/pytaku/.local/bin/pytaku-scheduler
+Restart=on-abnormal
+User=pytaku
+Group=pytaku
 WorkingDirectory=/home/pytaku/pytaku
-Restart=always
+ExecStart=/home/pytaku/.local/bin/pytaku-scheduler
 
 [Install]
-WantedBy=default.target
+WantedBy=multi-user.target
diff --git a/contrib/systemd/pytaku.service b/contrib/systemd/pytaku.service
index d369e16..b102be8 100644
--- a/contrib/systemd/pytaku.service
+++ b/contrib/systemd/pytaku.service
@@ -1,18 +1,15 @@
-# this goes in ~/.config/systemd/user/pytaku.service
-
-# systemctl --user daemon-reload
-# systemctl --user enable pytaku
-# systemctl --user restart pytaku
-# loginctl enable-linger <username>
-
+# this goes in /etc/systemd/system/pytaku.service
 [Unit]
 Description=Pytaku server
+After=network-online.target
+Wants=network-online.target systemd-networkd-wait-online.service
 
 [Service]
-Environment="PYTHONUNBUFFERED=1"
-ExecStart=/bin/bash -c 'export PATH=$PATH:$HOME/.local/bin; pytaku -w 10 -b 0.0.0.0:5001'
+Restart=on-abnormal
+User=pytaku
+Group=pytaku
 WorkingDirectory=/home/pytaku/pytaku
-Restart=always
+ExecStart=/bin/bash -c 'export PATH=$PATH:$HOME/.local/bin; pytaku -w 10 -b 0.0.0.0:5001'
 
 [Install]
-WantedBy=default.target
+WantedBy=multi-user.target
diff --git a/pyproject.toml b/pyproject.toml
index 53dfe02..410ef49 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "pytaku"
-version = "0.5.1"
+version = "0.5.2"
 description = "Self-hostable web-based manga reader"
 authors = ["Bùi Thành Nhân <hi@imnhan.com>"]
 license = "AGPL-3.0-only"