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

application file into install_dir folder, user's custom code into data_dir

This commit is contained in:
leonard 2023-12-01 16:50:49 +01:00 committed by Leonard
parent 7ced5e5806
commit 0696476457
4 changed files with 19 additions and 12 deletions

View file

@ -7,7 +7,7 @@ User=__APP__
Group=__APP__
WorkingDirectory=__DATA_DIR__/
ExecStart=__DATA_DIR__/venv/bin/gunicorn --config __DATA_DIR__/gunicorn.conf.py FastAPIAppFolder:app --worker-class uvicorn.workers.UvicornWorker
ExecStart=__INSTALL_DIR__/venv/bin/gunicorn --config __INSTALL_DIR__/gunicorn.conf.py FastAPIAppFolder:app --worker-class uvicorn.workers.UvicornWorker
StandardOutput=syslog
StandardError=syslog

View file

@ -41,6 +41,8 @@ ram.runtime = "50M"
[resources.system_user]
# This will provision/deprovision a unix system user
[resources.install_dir]
[resources.data_dir]
# This will create/remove the data dir as /home/yunohost.app/$app
# and store the corresponding setting $data_dir

View file

@ -22,8 +22,8 @@ log_level="WARNING"
# SET CONSTANTS
#=================================================
# e.g.: point pip cache to: /home/yunohost.app/$app/.cache/
XDG_CACHE_HOME="$data_dir/.cache/"
# e.g.: point pip cache to: /var/www/$app/.cache/
XDG_CACHE_HOME="$install_dir/.cache/"
log_path=/var/log/$app
log_file="${log_path}/${app}.log"
@ -34,22 +34,23 @@ log_file="${log_path}/${app}.log"
myynh_setup_python_venv() {
# Always recreate everything fresh with current python version
ynh_secure_remove "$data_dir/venv"
ynh_secure_remove "$install_dir/venv"
# Skip pip because of: https://github.com/YunoHost/issues/issues/1960
python3 -m venv --without-pip "$data_dir/venv"
python3 -m venv --without-pip "$install_dir/venv"
chown -c -R "$app:" "$data_dir"
chown -c -R "$app:" "$install_dir"
# run source in a 'sub shell'
(
set +o nounset
source "$data_dir/venv/bin/activate"
source "$install_dir/venv/bin/activate"
set -o nounset
set -x
ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
ynh_exec_as $app $data_dir/venv/bin/pip3 install -r "$data_dir/requirements.txt"
ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip
# using --no-cache-dir option because user doesn't have permission to write on cache directory (don't know if it's on purpose or not)
ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir --upgrade wheel pip setuptools
ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir -r "$install_dir/requirements.txt"
)
}
@ -72,5 +73,9 @@ myynh_fix_file_permissions() {
# /home/yunohost.app/$app/
chown -c -R "$app:" "$data_dir"
chmod -c o-rwx "$data_dir"
# /var/www/$app/
chown -c -R "$app:" "$install_dir"
chmod -c o-rwx "$install_dir"
)
}

View file

@ -55,7 +55,7 @@ ynh_use_logrotate --logfile="$log_file" --specific_user=$app
#=================================================
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
ynh_add_config --template="requirements.txt" --destination="$data_dir/requirements.txt"
ynh_add_config --template="requirements.txt" --destination="$install_dir/requirements.txt"
myynh_setup_python_venv
@ -64,7 +64,7 @@ myynh_setup_python_venv
# ================================================
ynh_script_progression --message="Create $app configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
mkdir -p "$data_dir/FastAPIAppFolder"
ynh_add_config --template="__init__.py" --destination="$data_dir/FastAPIAppFolder/__init__.py"