mirror of
https://github.com/YunoHost-Apps/tandoor_ynh.git
synced 2024-09-03 20:35:56 +02:00
rework venv
This commit is contained in:
parent
33d6994d86
commit
9b43553088
2 changed files with 57 additions and 117 deletions
|
@ -6,95 +6,27 @@
|
|||
|
||||
nodejs_version=16
|
||||
|
||||
py_required_version=3.9.2
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Install specific python version
|
||||
# usage: myynh_install_python --python="3.8.6"
|
||||
# | arg: -p, --python= - the python version to install
|
||||
myynh_install_python () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
local -A args_array=( [p]=python= )
|
||||
local python
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
_tandoor_venv_install() {
|
||||
ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv"
|
||||
venvpy="$install_dir/venv/bin/python3"
|
||||
|
||||
# Check python version from APT
|
||||
local py_apt_version=$(python3 --version | cut -d ' ' -f 2)
|
||||
|
||||
# Check existing built version of python in /usr/local/bin
|
||||
if [ -e "/usr/local/bin/python${python:0:3}" ]
|
||||
then
|
||||
local py_built_version=$(/usr/local/bin/python${python:0:3} --version \
|
||||
| cut -d ' ' -f 2)
|
||||
else
|
||||
local py_built_version=0
|
||||
fi
|
||||
|
||||
# Compare version
|
||||
if $(dpkg --compare-versions $py_apt_version ge $python)
|
||||
then
|
||||
# APT >= Required
|
||||
ynh_print_info --message="Using provided python3..."
|
||||
|
||||
py_app_version="python3"
|
||||
|
||||
else
|
||||
# Either python already built or to build
|
||||
if $(dpkg --compare-versions $py_built_version ge $python)
|
||||
then
|
||||
# Built >= Required
|
||||
ynh_print_info --message="Using already used python3 built version..."
|
||||
|
||||
py_app_version="/usr/local/bin/python${py_built_version:0:3}"
|
||||
|
||||
else
|
||||
ynh_print_info --message="Installing additional dependencies to build python..."
|
||||
|
||||
#REMOVEME? pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar"
|
||||
#REMOVEME? ynh_install_app_dependencies "${pkg_dependencies}"
|
||||
|
||||
# APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin
|
||||
ynh_print_info --message="Building python (may take a while)..."
|
||||
|
||||
# Store current direcotry
|
||||
local MY_DIR=$(pwd)
|
||||
|
||||
# Create a temp direcotry
|
||||
tmpdir="$(mktemp --directory)"
|
||||
cd "$tmpdir"
|
||||
|
||||
# Download
|
||||
wget --output-document="Python-$python.tar.xz" \
|
||||
"https://www.python.org/ftp/python/$python/Python-$python.tar.xz" 2>&1
|
||||
|
||||
# Extract
|
||||
tar xf "Python-$python.tar.xz"
|
||||
|
||||
# Install
|
||||
cd "Python-$python"
|
||||
./configure --enable-optimizations
|
||||
ynh_exec_warn_less make -j4
|
||||
ynh_exec_warn_less make altinstall
|
||||
|
||||
# Go back to working directory
|
||||
cd "$MY_DIR"
|
||||
|
||||
# Clean
|
||||
ynh_secure_remove "$tmpdir"
|
||||
|
||||
# Set version
|
||||
py_app_version="/usr/local/bin/python${python:0:3}"
|
||||
fi
|
||||
fi
|
||||
# Save python version in settings
|
||||
ynh_app_setting_set --app=$app --key=python --value="$python"
|
||||
pushd "$install_dir/source"
|
||||
ynh_exec_as "$app" "$venvpy" -m pip install -r requirements.txt
|
||||
popd
|
||||
}
|
||||
|
||||
_tandoor_build_frontend() {
|
||||
pushd "$install_dir/source/vue"
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn build
|
||||
popd
|
||||
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
|
@ -103,3 +35,26 @@ myynh_install_python () {
|
|||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
_mopidy_install() {
|
||||
python3 -m venv --upgrade "$install_dir/venv"
|
||||
chown -R "$app" "$install_dir"
|
||||
|
||||
venvpy="$install_dir/venv/bin/python3"
|
||||
|
||||
ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip
|
||||
|
||||
ynh_exec_as "$app" "$venvpy" -m pip install PyGObject
|
||||
|
||||
# install essential packages
|
||||
ynh_exec_as "$app" "$venvpy" -m pip install --no-cache-dir \
|
||||
Mopidy=="$(ynh_app_upstream_version)" \
|
||||
Mopidy-local==3.2.1 \
|
||||
Mopidy-MusicBox-Webclient==3.1.0 \
|
||||
Mopidy-YouTube==3.7 \
|
||||
Mopidy-YTMusic==0.3.8 \
|
||||
Mopidy-RadioNet==0.2.2 \
|
||||
Mopidy-Podcast==3.0.1 \
|
||||
Mopidy-Podcast-iTunes==3.0.1 \
|
||||
Mopidy-SoundCloud==3.0.2 \
|
||||
Mopidy-MPD==3.3.0
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ ynh_psql_execute_as_root --sql="ALTER USER $db_name WITH SUPERUSER;"
|
|||
ynh_script_progression --message="Setting up source files..." --weight=1
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$install_dir"
|
||||
ynh_setup_source --dest_dir="$install_dir/source"
|
||||
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
|
@ -55,50 +55,36 @@ chown -R "$app:www-data" "$data_dir"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||
|
||||
ynh_add_config --template=".env.template" --destination="$install_dir/.env"
|
||||
ynh_add_config --template=".env.template" --destination="$install_dir/source/.env"
|
||||
|
||||
chmod 400 "$install_dir/.env"
|
||||
chown $app:$app "$install_dir/.env"
|
||||
chmod 400 "$install_dir/source/.env"
|
||||
chown "$app:$app" "$install_dir/source/.env"
|
||||
|
||||
version=$(ynh_app_upstream_version)
|
||||
|
||||
ynh_add_config --template="version.py" --destination="$install_dir/recipes/version.py"
|
||||
chmod 400 "$install_dir/recipes/version.py"
|
||||
chown $app:$app "$install_dir/recipes/version.py"
|
||||
ynh_add_config --template="version.py" --destination="$install_dir/source/recipes/version.py"
|
||||
chmod 400 "$install_dir/source/recipes/version.py"
|
||||
chown "$app:$app" "$install_dir/source/recipes/version.py"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up Tandoor venv..." --weight=1
|
||||
|
||||
if [[ $(ynh_get_debian_release) == "bullseye" ]]; then
|
||||
py_app_version="python3"
|
||||
else
|
||||
myynh_install_python --python="$py_required_version"
|
||||
fi
|
||||
|
||||
ynh_exec_as $app $py_app_version -m venv "$install_dir/venv"
|
||||
|
||||
ynh_script_progression --message="Installing dependencies via pip..." --weight=4
|
||||
pushd "$install_dir"
|
||||
ynh_exec_warn_less ynh_exec_as $app "$install_dir/venv/bin/pip3" install -r requirements.txt
|
||||
popd
|
||||
|
||||
ynh_script_progression --message="Building frontend..." --weight=5
|
||||
pushd "$install_dir/vue"
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less yarn install
|
||||
ynh_exec_warn_less yarn build
|
||||
popd
|
||||
_tandoor_build_frontend
|
||||
|
||||
ynh_script_progression --message="Installing Tandoor and its python dependencies..." --weight=1
|
||||
_tandoor_venv_install
|
||||
|
||||
ynh_script_progression --message="Running migrations and generating static files..." --weight=2
|
||||
pushd "$install_dir"
|
||||
# load environment variables
|
||||
export $(cat "/var/www/$app/.env" |grep "^[^#]" | xargs)
|
||||
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py migrate
|
||||
pushd "$install_dir/source"
|
||||
(
|
||||
source "$install_dir/source/.env"
|
||||
|
||||
ynh_exec_as "$app" "$venvpy" manage.py migrate
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $app WITH NOSUPERUSER;"
|
||||
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py collectstatic --no-input
|
||||
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py collectstatic_js_reverse
|
||||
ynh_exec_as "$app" "$venvpy" manage.py collectstatic --no-input
|
||||
ynh_exec_as "$app" "$venvpy" manage.py collectstatic_js_reverse
|
||||
)
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
|
@ -116,7 +102,6 @@ yunohost service add "$app" --description="Smart recipe management" --log="/var/
|
|||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate
|
||||
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue