30ac05c5b0
The installation of these packages are currently not constrained, resulting in inconsistent experiences at deploy time. This patch ensures that the venv preparation process properly constrains the installation so that results are consistent. Change-Id: I744e43d8a1b85d5bdaf7019a6420a39222911330 Partial-Bug: #1764470
123 lines
4.1 KiB
Django/Jinja
123 lines
4.1 KiB
Django/Jinja
#!/bin/bash
|
|
# Copyright 2017, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
## Shell Opts ----------------------------------------------------------------
|
|
set -e
|
|
|
|
## Variables -----------------------------------------------------------------
|
|
|
|
# The options file for the venv
|
|
ROLE_VENV_REQUIREMENTS_FILE="${1}"
|
|
|
|
## Functions -----------------------------------------------------------------
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
|
|
Usage:
|
|
${0} <path to configuration options file>
|
|
|
|
EOF
|
|
}
|
|
|
|
## Main ----------------------------------------------------------------------
|
|
|
|
# Validate that an options file as been provided
|
|
if [[ -z "${ROLE_VENV_REQUIREMENTS_FILE}" ]]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
# Source the options file
|
|
source "${ROLE_VENV_REQUIREMENTS_FILE}"
|
|
|
|
# Output the beginning of the build
|
|
echo -n "Building venv ${ROLE_VENV_FILE}..."
|
|
|
|
# Set the log file path
|
|
ROLE_VENV_LOG="/var/log/repo/venv_build_${ROLE_VENV_FILE}.log"
|
|
|
|
# Begin the venv build
|
|
pushd "{{ repo_build_venv_dir }}" &>/dev/null
|
|
|
|
# If the venv achive already exists, remove it
|
|
[[ -e "${ROLE_VENV_FILE}.tgz" ]] && rm -f "${ROLE_VENV_FILE}.tgz"
|
|
|
|
# If the venv checksum file already exists, remove it
|
|
[[ -e "${ROLE_VENV_FILE}.checksum" ]] && rm -f "${ROLE_VENV_FILE}.checksum"
|
|
|
|
# If the venv working directory already exists, remove it
|
|
[[ -d "${ROLE_VENV_PATH}" ]] && rm -rf "${ROLE_VENV_PATH}"
|
|
|
|
# If the pip build directory already exists, remove it
|
|
[[ -d "/tmp/${ROLE_VENV_FILE}" ]] && rm -rf "/tmp/${ROLE_VENV_FILE}"
|
|
|
|
# Create the virtualenv shell
|
|
${VENV_CREATE_COMMAND} "${ROLE_VENV_PATH}" &>${ROLE_VENV_LOG}
|
|
|
|
# Create the pip build directory
|
|
mkdir -p "/tmp/${ROLE_VENV_FILE}"
|
|
|
|
# Activate the python virtual environment for good measure
|
|
source "${ROLE_VENV_PATH}/bin/activate"
|
|
|
|
# Install pip, setuptools, wheel into it
|
|
# Rather than allow virtualenv to decide which version
|
|
# of pip/setuptools/wheel we use, we create the virtualenv
|
|
# without them and use get-pip.py later to install them
|
|
# into the venv. This prevents messy upgrade/downgrade
|
|
# failures when trying to install the versions we want.
|
|
# We also inform get-pip.py using the --find-links option
|
|
# that there are local wheels available so that it uses
|
|
# them instead of reaching out to the internet unnecessarily.
|
|
${ROLE_VENV_PATH}/bin/python {{ repo_build_release_path }}/get-pip.py \
|
|
pip setuptools wheel \
|
|
--find-links {{ repo_build_release_path }} \
|
|
${PIP_INSTALL_OPTIONS} \
|
|
--constraint {{ repo_build_release_path }}/requirements_constraints.txt \
|
|
&>${ROLE_VENV_LOG}
|
|
|
|
# Install the packages into the venv
|
|
${ROLE_VENV_PATH}/bin/pip install \
|
|
--disable-pip-version-check \
|
|
--quiet --quiet \
|
|
--build "/tmp/${ROLE_VENV_FILE}" \
|
|
${PIP_INSTALL_OPTIONS} \
|
|
${PIP_INDEX_OPTIONS} \
|
|
${ROLE_VENV_REQUIREMENTS} \
|
|
--log "${ROLE_VENV_LOG}"
|
|
|
|
# Deactivate the venv for good measure
|
|
deactivate
|
|
|
|
# Find and remove all of the python pyc files
|
|
find "${ROLE_VENV_PATH}" -type f -name '*.pyc' -delete 2>>${ROLE_VENV_LOG}
|
|
|
|
# Create the archive
|
|
tar czf "${ROLE_VENV_FILE}.tgz" -C "${ROLE_VENV_PATH}" . 2>>${ROLE_VENV_LOG}
|
|
|
|
# Create a checksum file for the archive
|
|
sha1sum "${ROLE_VENV_FILE}.tgz" | awk '{print $1}' > "${ROLE_VENV_FILE}.checksum" 2>>${ROLE_VENV_LOG}
|
|
|
|
# Delete working directories
|
|
rm -rf "${ROLE_VENV_PATH}"
|
|
rm -rf "/tmp/${ROLE_VENV_FILE}"
|
|
|
|
popd &>/dev/null
|
|
|
|
# Output the end of the build
|
|
echo "done"
|
|
|