From 121927c51ea816cc8d8e3cd52aefdc37468f1f6f Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda Date: Wed, 14 Sep 2022 17:53:30 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Produk=C4=8Dn=C3=AD=20web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/README.md | 64 +++++++++++++----------------------------- server/bin/deploy | 6 ++++ server/constraints.txt | 1 + server/setup.py | 1 + 4 files changed, 28 insertions(+), 44 deletions(-) create mode 100755 server/bin/deploy diff --git a/server/README.md b/server/README.md index a15c6c3..93d2ba4 100644 --- a/server/README.md +++ b/server/README.md @@ -30,58 +30,34 @@ TODO: Upravit (momentálně pouze vykradeno) # Pro systém s jádrem < 5.4 zvýšit net.core.somaxconn (jako root) [ "`cat /proc/sys/net/core/somaxconn`" -lt 4096 ] && echo net.core.somaxconn=4096 >> /etc/sysctl.conf && sysctl -p - # Založit účet mo-web (jako root) - adduser --system mo-web --shell /bin/bash - loginctl enable-linger mo-web + # Založit účet (jako root) + useradd -m -s /usr/bin/bash ksp-strathra-web # Založit databázi (jako správce PostgreSQL) - psql -e 'CREATE ROLE mo_osmo' - psql -e 'CREATE ROLE "mo-web" LOGIN' - psql -e 'GRANT mo_osmo TO "mo-web"' # a případně dalším uživatelům - psql -e 'CREATE DATABASE mo_osmo_test WITH OWNER=mo_osmo' + psql -e -c 'CREATE ROLE ksp_strathra' + psql -e -c 'CREATE ROLE "ksp-strathra-web" LOGIN' + psql -e -c 'GRANT ksp_strathra TO "ksp-strathra-web"' # a případně dalším uživatelům + psql -e -c 'CREATE DATABASE ksp_strathra_pub WITH OWNER=ksp_strathra' - # Inicializovat databázi (už jako mo-web) - psql mo_osmo_test src + # Nastavit uživateli SSHčko (jako on) + mkdir .ssh + vi authorized_keys - # Vytvořit etc/config.py podle src/etc/config.py.example - # Vytvořit etc/uwsgi.ini podle src/etc/uwsgi.ini.example - cd src + # Pushnout data (jako svůj uživatel v složce s README) bin/deploy - # Zpřístupnit socket Nginxu - setfacl -m u:www-data:x /akce/mo/osmo-test /akce/mo/osmo-test/var - - # Inicializovat regiony v DB - # Obstarat si extra/ruian/ a extra/schools/parsed/ z jiné instance (nebo je znovu stáhnout) - . ../venv/bin/activate - bin/test-init # případně podmnožinu - - # Případně ručně otestovat, že uwsgi funguje - # uwsgi --ini etc/osmo.ini - - # Založit ~/.config/systemd/user/osmo_test.service podle etc/osmo.service.example - systemctl --user daemon-reload - systemctl --user enable osmo_test.service - systemctl --user start osmo_test.service - systemctl --user status osmo_test.service + # Nainstalovat venv + python3 -m venv venv + . venv/bin/activate + pip install wheel + pip install -c constraints.txt --editable . - # Nastavit nginx: - location /osmo-test { - include uwsgi_params; - uwsgi_pass unix:/akce/mo/osmo-test/var/osmo.sock; - } + # Inicializovat databázi (už jako mo-web) + bin/db_init - # Na instalaci nové verze pak stačí spustit bin/deploy + # Pustit web + uwsgi --http 127.0.0.1:8000 --master -p 4 -w hra.web:app ## Mražení závislostí - pip freeze | grep -v '^osmo=' >constraints.txt + pip freeze | grep -v '^hra=' >constraints.txt diff --git a/server/bin/deploy b/server/bin/deploy new file mode 100755 index 0000000..0e1e72a --- /dev/null +++ b/server/bin/deploy @@ -0,0 +1,6 @@ +#!/bin/bash + + +rsync static setup.py bin constraints.txt config.py.example ksp-strathra-web@localhost:web/ -LKr +rsync hra ksp-strathra-web@localhost:web/ -LKrm --exclude="config.py" --exclude '__pycache__' + diff --git a/server/constraints.txt b/server/constraints.txt index 6b2a165..05ce4c3 100644 --- a/server/constraints.txt +++ b/server/constraints.txt @@ -40,6 +40,7 @@ types-setuptools==65.3.0 types-SQLAlchemy==1.4.51 types-urllib3==1.26.24 typing_extensions==4.3.0 +uwsgi==2.0.20 uwsgidecorators==1.1.0 visitor==0.1.3 webencodings==0.5.1 diff --git a/server/setup.py b/server/setup.py index e785681..c5a75ae 100644 --- a/server/setup.py +++ b/server/setup.py @@ -33,6 +33,7 @@ setuptools.setup( 'psycopg2', 'pyzbar', 'sqlalchemy[mypy]', + 'uwsgi', 'uwsgidecorators', # Používáme pro vývoj, ale aby je pylsp našel, musí být ve stejném virtualenvu # jako ostatní knihovny.