Blind update from upstream Github - Fedora 31, Python 3.7

This commit is contained in:
Lumir Balhar 2020-01-07 08:51:45 +01:00
commit c1cc83f38d
35 changed files with 2266 additions and 176 deletions

View file

@ -8,35 +8,74 @@ function should_collectstatic() {
is_django_installed && [[ -z "$DISABLE_COLLECTSTATIC" ]]
}
function virtualenv_bin() {
if head "/etc/redhat-release" | grep -q "^CentOS Linux release 7" || \
head "/etc/redhat-release" | grep -q "^Red Hat Enterprise Linux\( Server\)\? release 7" || \
head "/etc/redhat-release" | grep -q "^Fedora release"; then
virtualenv $1
else
virtualenv-${PYTHON_VERSION} $1
fi
}
# Install pipenv to the separate virtualenv to isolate it
# from system Python packages and packages in the main
# virtualenv. Executable is simlinked into ~/.local/bin
# to be accessible. This approach is inspired by pipsi
# (pip script installer).
function install_pipenv() {
echo "---> Installing pipenv packaging tool ..."
VENV_DIR=$HOME/.local/venvs/pipenv
virtualenv_bin "$VENV_DIR"
$VENV_DIR/bin/pip --isolated install -U pipenv
mkdir -p $HOME/.local/bin
ln -s $VENV_DIR/bin/pipenv $HOME/.local/bin/pipenv
}
set -e
shopt -s dotglob
echo "---> Installing application source ..."
mv /tmp/src/* ./
mv /tmp/src/* "$HOME"
# set permissions for any installed artifacts
fix-permissions /opt/app-root -P
if [[ ! -z "$UPGRADE_PIP_TO_LATEST" ]]; then
echo "---> Upgrading pip to latest version ..."
pip install -U pip
pip install -U pip setuptools wheel
fi
if [[ -f requirements.txt ]]; then
if [[ ! -z "$ENABLE_PIPENV" ]]; then
install_pipenv
echo "---> Installing dependencies via pipenv ..."
if [[ -f Pipfile ]]; then
pipenv install --deploy
elif [[ -f requirements.txt ]]; then
pipenv install -r requirements.txt
fi
# pipenv check
elif [[ -f requirements.txt ]]; then
echo "---> Installing dependencies ..."
pip install -r requirements.txt
fi
if [[ -f setup.py ]]; then
if [[ -f setup.py && -z "$DISABLE_SETUP_PY_PROCESSING" ]]; then
echo "---> Installing application ..."
python setup.py develop
pip install .
fi
if should_collectstatic; then
(
echo "---> Collecting Django static files ..."
APP_HOME=$(readlink -f "${APP_HOME:-.}")
# Change the working directory to APP_HOME
PYTHONPATH="$(pwd)${PYTHONPATH:+:$PYTHONPATH}"
cd "$APP_HOME"
APP_HOME=${APP_HOME:-.}
# Look for 'manage.py' in the directory specified by APP_HOME, or the current directory
manage_file=$APP_HOME/manage.py
# Look for 'manage.py' in the current directory
manage_file=./manage.py
if [[ ! -f "$manage_file" ]]; then
echo "WARNING: seems that you're using Django, but we could not find a 'manage.py' file."
@ -56,4 +95,4 @@ if should_collectstatic; then
fi
# set permissions for any installed artifacts
fix-permissions /opt/app-root
fix-permissions /opt/app-root -P

18
s2i/bin/init-wrapper Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
# Overview of how this script works: http://veithen.io/2014/11/16/sigterm-propagation.html
# Set a trap to kill the main app process when this
# init script receives SIGTERM or SIGINT
trap 'kill -s TERM $PID' TERM INT
# Execute the main application in the background
"$@" &
PID=$!
# wait command always terminates when trap is caught, even if the process hasn't finished yet
wait $PID
# Remove the trap and wait till the app process finishes completely
trap - TERM INT
# We wait again, since the first wait terminates when trap is caught
wait $PID
# Exit with the exit code of the app process
STATUS=$?
exit $STATUS

View file

@ -29,9 +29,25 @@ function get_default_web_concurrency() {
local default=$(((${MEMORY_LIMIT_IN_BYTES:-MAX_MEMORY_LIMIT_IN_BYTES}/1024/1024 - 43) / 40))
default=$((default > max ? max : default))
default=$((default < 1 ? 1 : default))
# According to http://docs.gunicorn.org/en/stable/design.html#how-many-workers,
# 12 workers should be enough to handle hundreds or thousands requests per second
default=$((default > 12 ? 12 : default))
echo $default
}
function maybe_run_in_init_wrapper() {
if [[ -z "$ENABLE_INIT_WRAPPER" ]]; then
exec "$@"
else
exec $STI_SCRIPTS_PATH/init-wrapper "$@"
fi
}
APP_HOME=$(readlink -f "${APP_HOME:-.}")
# Change the working directory to APP_HOME
PYTHONPATH="$(pwd)${PYTHONPATH:+:$PYTHONPATH}"
cd "$APP_HOME"
app_script_check="${APP_SCRIPT-}"
APP_SCRIPT="${APP_SCRIPT-app.sh}"
if [[ -f "$APP_SCRIPT" ]]; then
@ -39,7 +55,7 @@ if [[ -f "$APP_SCRIPT" ]]; then
if [[ "$APP_SCRIPT" != /* ]]; then
APP_SCRIPT="./$APP_SCRIPT"
fi
exec "$APP_SCRIPT"
maybe_run_in_init_wrapper "$APP_SCRIPT"
else
test -n "$app_script_check" && (>&2 echo "ERROR: file '$app_script_check' not found.") && exit 1
fi
@ -48,14 +64,13 @@ app_file_check="${APP_FILE-}"
APP_FILE="${APP_FILE-app.py}"
if [[ -f "$APP_FILE" ]]; then
echo "---> Running application from Python script ($APP_FILE) ..."
exec python "$APP_FILE"
maybe_run_in_init_wrapper python "$APP_FILE"
else
test -n "$app_file_check" && (>&2 echo "ERROR: file '$app_file_check' not found.") && exit 1
fi
APP_HOME=${APP_HOME:-.}
# Look for 'manage.py' in the directory specified by APP_HOME, or the current direcotry
manage_file=$APP_HOME/manage.py
# Look for 'manage.py' in the current directory
manage_file=./manage.py
if should_migrate; then
if [[ -f "$manage_file" ]]; then
@ -68,14 +83,12 @@ if should_migrate; then
fi
if is_gunicorn_installed; then
if [[ -z "$APP_MODULE" ]]; then
# Look only in the directory specified by APP_HOME, or the current directory
# replace all "/" with ".", remove leading "." and ".py" suffix
APP_MODULE=$(find $APP_HOME -maxdepth 1 -type f -name 'wsgi.py' | sed 's:/:.:g;s:^\.\+::;s:\.py$::')
fi
if [[ -z "$APP_MODULE" && -f setup.py ]]; then
APP_MODULE="$(python setup.py --name)"
setup_py=$(find "$HOME" -maxdepth 2 -type f -name 'setup.py' -print -quit)
# Look for wsgi module in the current directory
if [[ -z "$APP_MODULE" && -f "./wsgi.py" ]]; then
APP_MODULE=wsgi
elif [[ -z "$APP_MODULE" && -f "$setup_py" ]]; then
APP_MODULE="$(python "$setup_py" --name)"
fi
if [[ "$APP_MODULE" ]]; then
@ -91,7 +104,7 @@ if is_django_installed; then
echo "---> Serving application with 'manage.py runserver' ..."
echo "WARNING: this is NOT a recommended way to run you application in production!"
echo "Consider using gunicorn or some other production web server."
exec python "$manage_file" runserver 0.0.0.0:8080
maybe_run_in_init_wrapper python "$manage_file" runserver 0.0.0.0:8080
else
echo "WARNING: seems that you're using Django, but we could not find a 'manage.py' file."
echo "Skipped 'python manage.py runserver'."

View file

@ -5,14 +5,14 @@ NAMESPACE=centos
[[ $DISTRO =~ rhel* ]] && NAMESPACE=rhscl
cat <<EOF
This is a S2I python-3.6 ${DISTRO} base image:
This is a S2I python-3.7 ${DISTRO} base image:
To use it, install S2I: https://github.com/openshift/source-to-image
Sample invocation:
s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.6/test/setup-test-app/ ${NAMESPACE}/python-36-${DISTRO}7 python-sample-app
s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.7/test/setup-test-app/ ${NAMESPACE}/python-37-${DISTRO}7 python-sample-app
You can then run the resulting image via:
docker run -p 8080:8080 python-sample-app
podman run -p 8080:8080 python-sample-app
EOF