More sonarqube fixes for Linux

This commit is contained in:
Dave Page 2022-08-10 11:34:40 +01:00
parent f6e7221359
commit 5e4d3cc535
3 changed files with 51 additions and 48 deletions

View File

@ -6,7 +6,7 @@ set -e
# Debugging shizz
trap 'ERRCODE=$? && if [ ${ERRCODE} -ne 0 ]; then echo "The command \"${BASH_COMMAND}\" failed in \"${FUNCNAME}\" with exit code ${ERRCODE}."; fi' EXIT
OS_VERSION=$(cat /etc/os-release | grep "^VERSION_ID=" | awk -F "=" '{ print $2 }' | sed 's/"//g')
OS_VERSION=$(grep "^VERSION_ID=" /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g')
OS_ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
# Stop creating pyc files.
@ -16,7 +16,7 @@ export PYTHONDONTWRITEBYTECODE=1
source pkg/linux/build-functions.sh
# Assemble the "standard" installation footprint
_setup_env $0 "debian"
_setup_env "$0" "debian"
_cleanup "deb"
_setup_dirs
_create_python_virtualenv "debian"
@ -121,7 +121,7 @@ EOF
fakeroot dpkg-deb --build "${METAROOT}" "${DISTROOT}/${APP_NAME}_${APP_LONG_VERSION}_all.deb"
# Get the libpq package
pushd ${DISTROOT} 1> /dev/null
pushd "${DISTROOT}" 1> /dev/null
apt-get download libpq5
popd 1> /dev/null

View File

@ -1,6 +1,8 @@
# shellcheck shell=bash
_setup_env() {
echo "Setting up the environment..."
WD=$(cd `dirname "$1"` && pwd)
WD=$(cd "$(dirname "$1")" && pwd)
SOURCEDIR=$(realpath "${WD}/../..")
BUILDROOT=$(realpath "${WD}/../../$2-build")
DESKTOPROOT=${BUILDROOT}/desktop
@ -8,11 +10,11 @@ _setup_env() {
SERVERROOT=${BUILDROOT}/server
WEBROOT=${BUILDROOT}/web
DISTROOT=$(realpath "${WD}/../../dist")
APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //' | sed 's/ //g' | tr '[:upper:]' '[:lower:]'`
APP_RELEASE=$(grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g')
APP_REVISION=$(grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g')
APP_NAME=$(grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //' | sed 's/ //g' | tr '[:upper:]' '[:lower:]')
APP_LONG_VERSION=${APP_RELEASE}.${APP_REVISION}
APP_SUFFIX=`grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g"`
APP_SUFFIX=$(grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g")
if [ ! -z ${APP_SUFFIX} ]; then
APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX}
fi
@ -20,36 +22,37 @@ _setup_env() {
_cleanup() {
echo "Cleaning up the old environment and app..."
if test -f ${SOURCEDIR}/runtime/pgAdmin4; then
rm -rf ${SOURCEDIR}/runtime/pgAdmin4
if test -f "${SOURCEDIR}/runtime/pgAdmin4"; then
rm -rf "${SOURCEDIR}/runtime/pgAdmin4"
fi
if test -d ${BUILDROOT}; then
rm -rf ${BUILDROOT}
if test -d "${BUILDROOT}"; then
rm -rf "${BUILDROOT}"
fi
rm -f ${DISTROOT}/pgadmin4*.$1
rm -f "${DISTROOT}/pgadmin4"*".$1"
}
_setup_dirs() {
echo "Creating output directories..."
test -d ${BUILDROOT} || mkdir ${BUILDROOT}
test -d ${DESKTOPROOT} || mkdir ${DESKTOPROOT}
test -d ${METAROOT} || mkdir ${METAROOT}
test -d ${SERVERROOT} || mkdir ${SERVERROOT}
test -d ${WEBROOT} || mkdir ${WEBROOT}
test -d ${DISTROOT} || mkdir ${DISTROOT}
test -d "${BUILDROOT}" || mkdir "${BUILDROOT}"
test -d "${DESKTOPROOT}" || mkdir "${DESKTOPROOT}"
test -d "${METAROOT}" || mkdir "${METAROOT}"
test -d "${SERVERROOT}" || mkdir "${SERVERROOT}"
test -d "${WEBROOT}" || mkdir "${WEBROOT}"
test -d "${DISTROOT}" || mkdir "${DISTROOT}"
}
_create_python_virtualenv() {
echo "Creating the virtual environment..."
cd ${SERVERROOT}
cd "${SERVERROOT}" || exit
# Create the required directories
mkdir -p "usr/${APP_NAME}"
cd "usr/${APP_NAME}"
cd "usr/${APP_NAME}" || exit
# Create the blank venv
python3 -m venv venv
# shellcheck disable=SC1091
source venv/bin/activate
# Make sure we have the wheel package present, as well as the latest pip
@ -57,7 +60,7 @@ _create_python_virtualenv() {
pip3 install wheel
# Install the requirements
pip3 install --no-cache-dir --no-binary psycopg2 -r ${SOURCEDIR}/requirements.txt
pip3 install --no-cache-dir --no-binary psycopg2 -r "${SOURCEDIR}/requirements.txt"
# Fixup the paths in the venv activation scripts
sed -i 's/VIRTUAL_ENV=.*/VIRTUAL_ENV="\/usr\/pgadmin4\/venv"/g' venv/bin/activate
@ -73,10 +76,10 @@ _create_python_virtualenv() {
# Figure out some paths for use when completing the venv
# Use "python3" here as we want the venv path
PYMODULES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
DIR_PYMODULES_PATH=`dirname ${PYMODULES_PATH}`
DIR_PYMODULES_PATH=$(dirname "${PYMODULES_PATH}")
# Use /usr/bin/python3 here as we want the system path
if [ $1 == "debian" ]; then
if [ "$1" == "debian" ]; then
PYSYSLIB_PATH=$(/usr/bin/python3 -c "import sys; print('%s/lib/python%d.%.d' % (sys.prefix, sys.version_info.major, sys.version_info.minor))")
else
PYSYSLIB_PATH=$(/usr/bin/python3 -c "import sys; print('%s/lib64/python%d.%.d' % (sys.prefix, sys.version_info.major, sys.version_info.minor))")
@ -85,33 +88,33 @@ _create_python_virtualenv() {
# Symlink in the rest of the Python libs. This is required because the runtime
# will clear PYTHONHOME for safety, which has the side-effect of preventing
# it from finding modules that are not explicitly included in the venv
cd ${DIR_PYMODULES_PATH}
cd "${DIR_PYMODULES_PATH}" || exit
# Files
for FULLPATH in ${PYSYSLIB_PATH}/*.py; do
for FULLPATH in "${PYSYSLIB_PATH}"/*.py; do
FILE=${FULLPATH##*/}
if [ ! -e ${FILE} ]; then
ln -s ${FULLPATH} ${FILE}
if [ ! -e "${FILE}" ]; then
ln -s "${FULLPATH}" "${FILE}"
fi
done
# Paths
for FULLPATH in ${PYSYSLIB_PATH}/*/; do
for FULLPATH in "${PYSYSLIB_PATH}"/*/; do
FULLPATH=${FULLPATH%*/}
FILE=${FULLPATH##*/}
if [ ! -e ${FILE} ]; then
ln -s ${FULLPATH} ${FILE}
if [ ! -e "${FILE}" ]; then
ln -s "${FULLPATH}" "${FILE}"
fi
done
# Remove tests
cd site-packages
cd site-packages || exit
find . -name "test" -type d -print0 | xargs -0 rm -rf
find . -name "tests" -type d -print0 | xargs -0 rm -rf
# Link the python<version> directory to python so that the private environment path is found by the application.
if test -d ${DIR_PYMODULES_PATH}; then
ln -s $(basename ${DIR_PYMODULES_PATH}) ${DIR_PYMODULES_PATH}/../python
if test -d "${DIR_PYMODULES_PATH}"; then
ln -s $(basename "${DIR_PYMODULES_PATH}") "${DIR_PYMODULES_PATH}/../python"
fi
}
@ -133,13 +136,13 @@ _build_runtime() {
# NW_VERSION=$(yarn info nw | grep latest | awk -F "'" '{ print $2}')
NW_VERSION="0.62.2"
pushd "${BUILDROOT}" > /dev/null
pushd "${BUILDROOT}" > /dev/null || exit
while true;do
wget https://dl.nwjs.io/v${NW_VERSION}/nwjs-v${NW_VERSION}-linux-x64.tar.gz && break
rm nwjs-v${NW_VERSION}-linux-x64.tar.gz
wget "https://dl.nwjs.io/v${NW_VERSION}/nwjs-v${NW_VERSION}-linux-x64.tar.gz" && break
rm "nwjs-v${NW_VERSION}-linux-x64.tar.gz"
done
tar -zxvf nwjs-v${NW_VERSION}-linux-x64.tar.gz
popd > /dev/null
tar -zxvf "nwjs-v${NW_VERSION}-linux-x64.tar.gz"
popd > /dev/null || exit
# WGET END
# Copy nwjs into the staging directory
@ -187,10 +190,10 @@ _build_runtime() {
_build_docs() {
echo "Building the documentation..."
cd "${SERVERROOT}" && mkdir -p "usr/${APP_NAME}/share/docs/en_US/html"
cd "${SOURCEDIR}/docs/en_US"
cd "${SOURCEDIR}/docs/en_US" || exit
python3 build_code_snippet.py
SYS_PYTHONPATH=$(/usr/bin/python3 -c "import sys; print(':'.join([p for p in sys.path if p]))")
if [ $1 == "redhat" -a "${OS_VERSION}" == "7" ]; then
if [ $1 == "redhat" ] && [ "${OS_VERSION}" == "7" ]; then
PYTHONPATH=$PYTHONPATH:${SYS_PYTHONPATH} python3 /usr/local/bin/sphinx-build . "${SERVERROOT}/usr/${APP_NAME}/share/docs/en_US/html"
else
PYTHONPATH=$PYTHONPATH:${SYS_PYTHONPATH} python3 -msphinx . "${SERVERROOT}/usr/${APP_NAME}/share/docs/en_US/html"
@ -203,15 +206,15 @@ _copy_code() {
# Remove any TCL-related files that may cause us problems
find "${SERVERROOT}/usr/${APP_NAME}/venv/" -name "_tkinter*" -print0 | xargs -0 rm -rf
pushd ${SOURCEDIR}/web > /dev/null
pushd "${SOURCEDIR}/web" > /dev/null || exit
yarn install
yarn run bundle
popd > /dev/null
popd > /dev/null || exit
# copy the web directory to the bundle as it is required by runtime
cp -r "${SOURCEDIR}/web" "${SERVERROOT}/usr/${APP_NAME}/web/"
cp "${SOURCEDIR}/pkg/linux/config_distro.py" "${SERVERROOT}/usr/${APP_NAME}/web/"
cd "${SERVERROOT}/usr/${APP_NAME}/web/"
cd "${SERVERROOT}/usr/${APP_NAME}/web/" || exit
rm -f pgadmin4.db config_local.*
rm -rf karma.conf.js package.json node_modules/ regression/ tools/ pgadmin/static/js/generated/.cache
find . -name "tests" -type d -print0 | xargs -0 rm -rf
@ -229,11 +232,11 @@ _copy_code() {
# Ensure our venv will use the correct Python interpreter, even if the
# user has configured an alternative default.
# DO THIS LAST!
cd "${SERVERROOT}/usr/${APP_NAME}/venv/bin"
cd "${SERVERROOT}/usr/${APP_NAME}/venv/bin" || exit
PYTHON_INTERPRETER=$(/usr/bin/python3 -c "import os, sys; print(os.path.realpath(sys.executable))")
PYTHON_VERSION=$(/usr/bin/python3 -c "import sys; print('%d.%d' % (sys.version_info.major, sys.version_info.minor))")
rm python && ln -s python3 python
rm python${PYTHON_VERSION} && ln -s python3 python${PYTHON_VERSION}
rm "python${PYTHON_VERSION}" && ln -s python3 "python${PYTHON_VERSION}"
rm python3 && ln -s "${PYTHON_INTERPRETER}" python3
}

View File

@ -6,7 +6,7 @@ set -e
# Debugging shizz
trap 'ERRCODE=$? && if [ ${ERRCODE} -ne 0 ]; then echo "The command \"${BASH_COMMAND}\" failed in \"${FUNCNAME}\" with exit code ${ERRCODE}."; fi' EXIT
OS_VERSION=$(cat /etc/os-release | grep "^VERSION_ID=" | awk -F "=" '{ print $2 }' | sed 's/"//g')
OS_VERSION=$(grep "^VERSION_ID=" /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g')
OS_ARCH=$(arch)
# Make sure we get the right libpq
@ -19,7 +19,7 @@ export PYTHONDONTWRITEBYTECODE=1
source pkg/linux/build-functions.sh
# Assemble the "standard" installation footprint
_setup_env $0 "redhat"
_setup_env "$0" "redhat"
_cleanup "rpm"
_setup_dirs
_create_python_virtualenv "redhat"