diff --git a/scripts/_common.sh b/scripts/_common.sh index c0f76ae..bfeba57 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -27,6 +27,31 @@ log_file="${log_path}/pyinventory.log" # dependencies used by the app pkg_dependencies="build-essential python3-dev python3-pip python3-venv git libpq-dev postgresql postgresql-contrib libjpeg-dev" +#================================================= +# PyInventory shared functions +#================================================= + +setup_venv() { + ynh_script_progression --message="Setup Python virtualenv..." --weight=15 + + # Always recreate everything fresh with current python version + ynh_secure_remove "${final_path}/venv" + + python3 -m venv --without-pip "${final_path}/venv" + + cp ../conf/requirements.txt "$final_path/requirements.txt" + chown -R "$app:" "$final_path" + ( + # Activate venv in sub shell + set +o nounset + source "${final_path}/venv/bin/activate" + set -o nounset + ynh_exec_as $app $final_path/venv/bin/python3 -m ensurepip + ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" + ) +} + #================================================= # Redis HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index 2b32057..872af64 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -38,7 +38,7 @@ redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=40 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=15 # Backup the current version of the app ynh_backup_before_upgrade diff --git a/scripts/install b/scripts/install index 5f2aede..ac5e51d 100755 --- a/scripts/install +++ b/scripts/install @@ -63,7 +63,7 @@ redis_db=$(ynh_redis_get_free_db) #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=40 +ynh_script_progression --message="Installing dependencies..." --weight=10 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" @@ -101,20 +101,7 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell #================================================= # PIP INSTALLATION #================================================= -ynh_script_progression --message="Install project via pip..." --weight=80 - -python3 -m venv "${final_path}/venv" -cp ../conf/requirements.txt "$final_path/requirements.txt" -chown -R "$app:" "$final_path" - -#run source in a 'sub shell' -( - set +o nounset - source "${final_path}/venv/bin/activate" - set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" -) +setup_venv # function defined in _common.sh #================================================= # copy config files diff --git a/scripts/restore b/scripts/restore index e4cbdfb..4cdd9a1 100755 --- a/scripts/restore +++ b/scripts/restore @@ -78,7 +78,7 @@ chown -R "$app:" "$final_path" #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=40 +ynh_script_progression --message="Reinstalling dependencies..." --weight=10 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" @@ -86,18 +86,7 @@ ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" # REINSTALL PYTHON VIRTUALENV # Maybe the backup contains a other Python version #================================================= -ynh_script_progression --message="Upgrade Python virtualenv..." --weight=10 - -python3 -m venv --upgrade "${final_path}/venv" - -#run source in a 'sub shell' -( - set +o nounset - source "${final_path}/venv/bin/activate" - set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" -) +setup_venv # function defined in _common.sh #================================================= # RESTORE THE PostgreSQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 5d21061..f8eedaa 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,7 +29,7 @@ redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=40 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=15 # Backup the current version of the app ynh_backup_before_upgrade @@ -85,20 +85,7 @@ ynh_add_systemd_config --service="$app" --template="pyinventory.service" #================================================= # UPGRADE VENV #================================================= -ynh_script_progression --message="Upgrade project via pip..." --weight=80 - -python3 -m venv --upgrade "${final_path}/venv" -cp ../conf/requirements.txt "$final_path/requirements.txt" -chown -R "$app:" "$final_path" - -#run source in a 'sub shell' -( - set +o nounset - source "${final_path}/venv/bin/activate" - set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" -) +setup_venv # function defined in _common.sh #================================================= # copy config files