-
Notifications
You must be signed in to change notification settings - Fork 325
/
assemble
executable file
·147 lines (126 loc) · 5.27 KB
/
assemble
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
function is_django_installed() {
python -c "import django" &>/dev/null
}
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 or micropipenv 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_tool() {
echo "---> Installing $1 packaging tool ..."
VENV_DIR=$HOME/.local/venvs/$1
virtualenv_bin "$VENV_DIR"
# First, try to install the tool without --isolated which means that if you
# have your own PyPI mirror, it will take it from there. If this try fails, try it
# again with --isolated which ignores external pip settings (env vars, config file)
# and installs the tool from PyPI (needs internet connetion).
# $1$2 combines package name with [extras] or version specifier if is defined as $2```
if ! $VENV_DIR/bin/pip install -U $1$2; then
echo "WARNING: Installation of $1 failed, trying again from official PyPI with pip --isolated install"
$VENV_DIR/bin/pip install --isolated -U $1$2 # Combines package name with [extras] or version specifier if is defined as $2```
fi
mkdir -p $HOME/.local/bin
ln -s $VENV_DIR/bin/$1 $HOME/.local/bin/$1
}
set -e
# First of all, check that we don't have disallowed combination of ENVs
if [[ ! -z "$ENABLE_PIPENV" && ! -z "$ENABLE_MICROPIPENV" ]]; then
echo "ERROR: Pipenv and micropipenv cannot be enabled at the same time!"
# podman/buildah does not relay this exit code but it will be fixed hopefuly
# https://github.com/containers/buildah/issues/2305
exit 3
fi
shopt -s dotglob
echo "---> Installing application source ..."
mv /tmp/src/* "$HOME"
# set permissions for any installed artifacts
fix-permissions /opt/app-root -P
# Python <3.7 only code, Python 3.7+ uses bundled wheel from Fedora
# We have to first upgrade pip to at least 19.3 because
# pip < 19.3 does not support manylinux2014 wheels. Only manylinux2014 (and later) wheels
# support platforms like ppc64le, aarch64 or armv7
echo "---> Upgrading pip to latest version supported for Python $PYTHON_VERSION ..."
if ! pip install -U "pip"; then
echo "WARNING: Installation of 'pip' failed, trying again from official PyPI with pip --isolated install"
pip install --isolated -U "pip"
fi
if [[ ! -z "$PIP_INDEX_URL" ]]; then
echo "---> Creating pip.ini config file"
echo "[global]
index-url = $PIP_INDEX_URL" >> /opt/app-root/src/pip.ini
fi
if [[ ! -z "$UPGRADE_PIP_TO_LATEST" ]]; then
echo "---> Upgrading pip, setuptools and wheel to latest version ..."
if ! pip install -U pip setuptools wheel; then
echo "WARNING: Installation of the latest pip, setuptools and wheel failed, trying again from official PyPI with pip --isolated install"
pip install --isolated -U pip setuptools wheel
fi
fi
if [[ ! -z "$ENABLE_PIPENV" ]]; then
if [[ ! -z "$PIN_PIPENV_VERSION" ]]; then
# Add == as a prefix to pipenv version, if defined
PIN_PIPENV_VERSION="==$PIN_PIPENV_VERSION"
fi
install_tool "pipenv" "$PIN_PIPENV_VERSION"
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 [[ ! -z "$ENABLE_MICROPIPENV" ]]; then
install_tool "micropipenv" "[toml]"
echo "---> Installing dependencies via micropipenv ..."
# micropipenv detects Pipfile.lock and requirements.txt in this order
micropipenv install --deploy
elif [[ -f requirements.txt ]]; then
echo "---> Installing dependencies ..."
pip install -r requirements.txt
fi
if [[ ( -f setup.py || -f setup.cfg ) && -z "$DISABLE_SETUP_PY_PROCESSING" ]]; then
echo "---> Installing application (via setup.{py,cfg})..."
pip install .
fi
if [[ -f pyproject.toml && -z "$DISABLE_PYPROJECT_TOML_PROCESSING" ]]; then
echo "---> Installing application (via pyproject.toml)..."
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"
# 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."
echo "'manage.py collectstatic' ignored."
exit
fi
if ! python $manage_file collectstatic --dry-run --noinput &> /dev/null; then
echo "WARNING: could not run 'manage.py collectstatic'. To debug, run:"
echo " $ python $manage_file collectstatic --noinput"
echo "Ignore this warning if you're not serving static files with Django."
exit
fi
python $manage_file collectstatic --noinput
)
fi
# set permissions for any installed artifacts
fix-permissions /opt/app-root -P