From bdebf878c367b2fefd870d74c049c2522bac08e7 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 27 May 2024 09:49:05 +0200 Subject: [PATCH] Fixes for installer (#7344) * - move reqs file to contrib - detect previously used python version - safe extra requirements to INSTALLER_EXTRA * add missing fi * move site setting --- .github/workflows/docker.yaml | 2 +- .github/workflows/qc_checks.yaml | 8 ++--- .github/workflows/release.yaml | 2 +- .pre-commit-config.yaml | 4 +-- {.github => contrib/dev_reqs}/requirements.in | 0 .../dev_reqs}/requirements.txt | 2 +- contrib/packager.io/functions.sh | 36 ++++++++++++++++++- contrib/packager.io/postinstall.sh | 2 ++ 8 files changed, 46 insertions(+), 10 deletions(-) rename {.github => contrib/dev_reqs}/requirements.in (100%) rename {.github => contrib/dev_reqs}/requirements.txt (99%) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 40437b413d..df945dc432 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -73,7 +73,7 @@ jobs: python-version: ${{ env.python_version }} - name: Version Check run: | - pip install --require-hashes -r .github/requirements.txt + pip install --require-hashes -r contrib/dev_reqs/requirements.txt python3 .github/scripts/version_check.py echo "git_commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_ENV echo "git_commit_date=$(git show -s --format=%ci)" >> $GITHUB_ENV diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index a6efc32d2b..e1ed0a7a0a 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -104,7 +104,7 @@ jobs: uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # pin@v3.0.1 - name: Check Version run: | - pip install --require-hashes -r .github/requirements.txt + pip install --require-hashes -r contrib/dev_reqs/requirements.txt python3 .github/scripts/version_check.py mkdocs: @@ -122,7 +122,7 @@ jobs: python-version: ${{ env.python_version }} - name: Check Config run: | - pip install --require-hashes -r .github/requirements.txt + pip install --require-hashes -r contrib/dev_reqs/requirements.txt pip install --require-hashes -r docs/requirements.txt python docs/ci/check_mkdocs_config.py - name: Check Links @@ -168,7 +168,7 @@ jobs: - name: Download public schema if: needs.paths-filter.outputs.api == 'false' run: | - pip install --require-hashes -r .github/requirements.txt >/dev/null 2>&1 + pip install --require-hashes -r contrib/dev_reqs/requirements.txt >/dev/null 2>&1 version="$(python3 .github/scripts/version_check.py only_version 2>&1)" echo "Version: $version" url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml" @@ -187,7 +187,7 @@ jobs: id: version if: github.ref == 'refs/heads/master' && needs.paths-filter.outputs.api == 'true' run: | - pip install --require-hashes -r .github/requirements.txt >/dev/null 2>&1 + pip install --require-hashes -r contrib/dev_reqs/requirements.txt >/dev/null 2>&1 version="$(python3 .github/scripts/version_check.py only_version 2>&1)" echo "Version: $version" echo "version=$version" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bc63b1a718..f93c99a1ec 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,7 +18,7 @@ jobs: uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # pin@v4.1.6 - name: Version Check run: | - pip install --require-hashes -r .github/requirements.txt + pip install --require-hashes -r contrib/dev_reqs/requirements.txt python3 .github/scripts/version_check.py - name: Push to Stable Branch uses: ad-m/github-push-action@d91a481090679876dfc4178fef17f286781251df # pin@v0.8.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6cace6d147..6c99a6f6d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,8 +39,8 @@ repos: files: src/backend/requirements\.(in|txt)$ - id: pip-compile name: pip-compile requirements.txt - args: [.github/requirements.in, -o, .github/requirements.txt,--python-version=3.9, --no-strip-extras, --generate-hashes] - files: .github/requirements\.(in|txt)$ + args: [contrib/dev_reqs/requirements.in, -o, contrib/dev_reqs/requirements.txt,--python-version=3.9, --no-strip-extras, --generate-hashes] + files: contrib/dev_reqs/requirements\.(in|txt)$ - id: pip-compile name: pip-compile requirements.txt args: [docs/requirements.in, -o, docs/requirements.txt,--python-version=3.9, --no-strip-extras, --generate-hashes] diff --git a/.github/requirements.in b/contrib/dev_reqs/requirements.in similarity index 100% rename from .github/requirements.in rename to contrib/dev_reqs/requirements.in diff --git a/.github/requirements.txt b/contrib/dev_reqs/requirements.txt similarity index 99% rename from .github/requirements.txt rename to contrib/dev_reqs/requirements.txt index 23393a4a95..c4099a325e 100644 --- a/.github/requirements.txt +++ b/contrib/dev_reqs/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile .github/requirements.in -o .github/requirements.txt --python-version=3.9 --no-strip-extras --generate-hashes +# uv pip compile contrib/dev_reqs/requirements.in -o contrib/dev_reqs/requirements.txt --python-version=3.9 --no-strip-extras --generate-hashes certifi==2024.2.2 \ --hash=sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f \ --hash=sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1 diff --git a/contrib/packager.io/functions.sh b/contrib/packager.io/functions.sh index 8f7f47cc66..bb236be77d 100755 --- a/contrib/packager.io/functions.sh +++ b/contrib/packager.io/functions.sh @@ -44,6 +44,18 @@ function detect_ip() { echo "IP address is ${INVENTREE_IP}" } +function detect_python() { + # Detect if there is already a python version installed in /opt/inventree/env/lib + if test -f "${APP_HOME}/env/bin/python"; then + echo "# Python environment already present" + # Extract earliest python version initialised from /opt/inventree/env/lib + SETUP_PYTHON=$(ls -1 ${APP_HOME}/env/bin/python* | sort | head -n 1) + echo "# Found earliest version: ${SETUP_PYTHON}" + else + echo "# No python environment found - using ${SETUP_PYTHON}" + fi +} + function get_env() { envname=$1 @@ -90,7 +102,7 @@ function detect_envs() { echo "# Using existing config file: ${INVENTREE_CONFIG_FILE}" # Install parser - pip install --require-hashes -r ${APP_HOME}/.github/requirements.txt -q + pip install --require-hashes -r ${APP_HOME}/contrib/dev_reqs/requirements.txt -q # Load config local CONF=$(cat ${INVENTREE_CONFIG_FILE} | jc --yaml) @@ -163,12 +175,20 @@ function create_initscripts() { sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && ${SETUP_PYTHON} -m venv env" sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && env/bin/pip install invoke wheel" + # Check INSTALLER_EXTRA exists and load it + if test -f "${APP_HOME}/INSTALLER_EXTRA"; then + echo "# Loading extra packages from INSTALLER_EXTRA" + source ${APP_HOME}/INSTALLER_EXTRA + fi + if [ -n "${SETUP_EXTRA_PIP}" ]; then echo "# Installing extra pip packages" if [ -n "${SETUP_DEBUG}" ]; then echo "# Extra pip packages: ${SETUP_EXTRA_PIP}" fi sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && env/bin/pip install ${SETUP_EXTRA_PIP}" + # Write extra packages to INSTALLER_EXTRA + echo "SETUP_EXTRA_PIP='${SETUP_EXTRA_PIP}'" >>${APP_HOME}/INSTALLER_EXTRA fi fi @@ -283,6 +303,20 @@ function set_env() { chown ${APP_USER}:${APP_GROUP} ${DATA_DIR} ${INVENTREE_CONFIG_FILE} } +function set_site() { + # Ensure IP is known + if [ -z "${INVENTREE_IP}" ]; then + echo "# No IP address found - skipping" + return + fi + + # Check if INVENTREE_SITE_URL in inventree config + if [ -z "$(inventree config:get INVENTREE_SITE_URL)" ]; then + echo "# Setting up InvenTree site URL" + inventree config:set INVENTREE_SITE_URL=http://${INVENTREE_IP} + fi +} + function final_message() { echo -e "####################################################################################" echo -e "This InvenTree install uses nginx, the settings for the webserver can be found in" diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh index 03230b955a..89c88833b1 100755 --- a/contrib/packager.io/postinstall.sh +++ b/contrib/packager.io/postinstall.sh @@ -33,6 +33,7 @@ detect_envs detect_docker detect_initcmd detect_ip +detect_python # create processes create_initscripts @@ -45,6 +46,7 @@ update_or_install if [ "${SETUP_CONF_LOADED}" = "true" ]; then set_env fi +set_site start_inventree # show info