1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flohmarkt_ynh.git synced 2024-09-03 18:36:30 +02:00

Merge branch 'main' of codeberg.org:flohmarkt/flohmarkt_ynh

This commit is contained in:
Chris Vogel 2024-04-30 14:23:10 +02:00
commit 957577acf8
5 changed files with 39 additions and 28 deletions

View file

@ -6,10 +6,11 @@ After=network.target couchdb.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__INSTALL_DIR__/__APP__
Environment="VENV_DIR=__INSTALL_DIR__/venv/"
ExecStart=/bin/bash -c "/opt/flohmarkt/venv/bin/uvicorn --host 127.0.0.1 --port 8000 --reload flohmarkt.web:start 2>&1 | /usr/bin/ts '%%Y-%%m-%%d %%H:%%M:%%S'"
StandardOutput=append:/var/log/__APP__/__APP__.log
WorkingDirectory=__FLOHMARKT_INSTALL__
Environment="VENV_DIR=__FLOHMARKT_VENV_DIR__"
ExecStart=/bin/bash -c "__FLOHMARKT_VENV_DIR__/bin/uvicorn --host 127.0.0.1 --port 8000 --reload flohmarkt.web:start 2>&1 | /usr/bin/ts '%%Y-%%m-%%d %%H:%%M:%%S'"
# nicer logfile naming https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/38
StandardOutput=append:/var/log/__ID__/__APP__.log
StandardError=inherit
# Sandboxing options to harden security

View file

@ -54,13 +54,12 @@ ram.runtime = "100M"
# ask admin on which domain to run flohmarkt
type = "domain"
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/4
# [install.path]
# # ask admin under which path flohmarkt will be reachable
# # e.g. 'https://doma.in/path' - might not work, needs to be tested:
# # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/4
# type = "path"
# default = "/"
[install.path]
# ask admin under which path flohmarkt will be reachable
# e.g. 'https://doma.in/path' - might not work, needs to be tested:
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/4
type = "path"
default = "/"
[install.init_main_permission]
# who will be able to access the apps URL after installation?

View file

@ -4,6 +4,13 @@
# COMMON VARIABLES
#=================================================
# replace '/' by nothing for the path
if [ "$path" == '/' ]; then url_path=''; else url_path=$path; fi
# directory flohmarkts software is installed to
flohmarkt_install="/opt/${id}/${domain}${url_path}/src"
# diretory the venv for flohmarkt is installed to
flohmarkt_venv_dir="/opt/${id}/${domain}${url_path}/venv"
#=================================================
# PERSONAL HELPERS
#=================================================

View file

@ -6,7 +6,11 @@ source /usr/share/yunohost/helpers
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/9
# check if couchdb is already installed
if [[ -e /opt/couchdb ]] || pgrep epmd > /dev/null || pgrep beam.smp || dpkg-query -W couchdb > /dev/null 2>&1;
# if there's a couchdb configuration file for flohmarkt we'll assume that couchdb
# had been installed by flohmarkt and we thus can savely do whatever we want to it
# with the resulting damage hopefully only influencing flohmarkt instances
if [[ -e /opt/couchdb ]] || pgrep epmd > /dev/null || pgrep beam.smp || dpkg-query -W couchdb > /dev/null 2>&1 \
&& ![[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]];
then
ynh_die --message="CouchDB already installed on this host - will not proceed."
exit 1
@ -58,20 +62,20 @@ systemctl restart couchdb
systemctl status couchdb
# get flohmarkt
ynh_setup_source --dest_dir="$install_dir/$app/"
ynh_setup_source --dest_dir="$flohmarkt_install"
# setup python environment for flohmarkt
ynh_secure_remove "$install_dir/venv"
python3 -m venv --without-pip "$install_dir/venv"
ynh_secure_remove "$flohmarkt_venv_dir"
python3 -m venv --without-pip "$flohmarkt_venv_dir"
# install python dependencies
(
set +o nounset
source "$install_dir/venv/bin/activate"
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
set -x
$install_dir/venv/bin/python3 -m ensurepip
$install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
$flohmarkt_venv_dir/bin/python3 -m ensurepip
$flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_install/requirements.txt"
)
# JwtSecret
@ -83,14 +87,14 @@ password_couchdb_flohmarkt=$(ynh_string_random --length=31 --filter='A-Za-z0-9_.
ynh_app_setting_set --app=$app --key=password_couchdb_flohmarkt --value="$password_couchdb_flohmarkt"
# generate flohmarkt.conf
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_install/flohmarkt.conf"
# setup couchdb
(
set +o nounset
source "$install_dir/venv/bin/activate"
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
cd "$install_dir/$app"
cd "$flohmarkt_install"
# initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
# give it 45 seconds to finish and then fail
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13

View file

@ -46,30 +46,30 @@ systemctl status couchdb
# install upgrade for flohmarkt
ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
ynh_setup_source --dest_dir="$install_dir/$app/"
ynh_setup_source --dest_dir="$flohmarkt_install/"
ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=5
# upgrade python environment / install new dependencies
(
set +o nounset
source "$install_dir/venv/bin/activate"
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
set -x
$install_dir/venv/bin/python3 -m ensurepip
$install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
$flohmarkt_venv_dir/bin/python3 -m ensurepip
$flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_install/requirements.txt"
)
# upgrade flohmarkt.conf
ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_install/flohmarkt.conf"
ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
# run initialize_couchdb.py
(
set +o nounset
source "$install_dir/venv/bin/activate"
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
cd "$install_dir/$app"
cd "$flohmarkt_install"
# initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
# give it 45 seconds to finish and then fail
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13