Virtual environment groundwork
Introduce the tooling to build virtual environments. * tools/build_venv.sh: build a venv * introduce lib/stack to house functionality extracted from stack.sh that is needed in other places, such as Grenade; start with stack_install_service to wrap the venv install mechanics * declare PROJECT_VENV array to track where project venvs should be installed * create a venv for each project defined in PROJECT_VENV in stack_install_service() Change-Id: I508588c0e2541b976dd94569d44b61dd2c35c01c
This commit is contained in:
parent
b1d8e8e274
commit
8c2ce6ea72
2
clean.sh
2
clean.sh
@ -120,7 +120,7 @@ if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up venvs
|
# Clean up venvs
|
||||||
DIRS_TO_CLEAN="$WHEELHOUSE"
|
DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]}"
|
||||||
rm -rf $DIRS_TO_CLEAN
|
rm -rf $DIRS_TO_CLEAN
|
||||||
|
|
||||||
# Clean up files
|
# Clean up files
|
||||||
|
@ -15,6 +15,13 @@ INC_PY_TRACE=$(set +o | grep xtrace)
|
|||||||
set +o xtrace
|
set +o xtrace
|
||||||
|
|
||||||
|
|
||||||
|
# Global Config Variables
|
||||||
|
|
||||||
|
# PROJECT_VENV contains the name of the virtual enviromnet for each
|
||||||
|
# project. A null value installs to the system Python directories.
|
||||||
|
declare -A PROJECT_VENV
|
||||||
|
|
||||||
|
|
||||||
# Python Functions
|
# Python Functions
|
||||||
# ================
|
# ================
|
||||||
|
|
||||||
@ -105,7 +112,6 @@ function pip_install {
|
|||||||
-r $test_req
|
-r $test_req
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
$xtrace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# get version of a package from global requirements file
|
# get version of a package from global requirements file
|
||||||
|
29
lib/stack
Normal file
29
lib/stack
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# lib/stack
|
||||||
|
#
|
||||||
|
# These functions are code snippets pulled out of stack.sh for easier
|
||||||
|
# re-use by Grenade. They can assume the same environment is available
|
||||||
|
# as in the lower part of stack.sh, namely a valid stackrc has been sourced
|
||||||
|
# as well as all of the lib/* files for the services have been sourced.
|
||||||
|
#
|
||||||
|
# For clarity, all functions declared here that came from ``stack.sh``
|
||||||
|
# shall be named with the prefix ``stack_``.
|
||||||
|
|
||||||
|
|
||||||
|
# Generic service install handles venv creation if confgured for service
|
||||||
|
# stack_install_service service
|
||||||
|
function stack_install_service {
|
||||||
|
local service=$1
|
||||||
|
if type install_${service} >/dev/null 2>&1; then
|
||||||
|
if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
|
||||||
|
rm -rf ${PROJECT_VENV[$service]}
|
||||||
|
source tools/build_venv.sh ${PROJECT_VENV[$service]}
|
||||||
|
export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-}
|
||||||
|
fi
|
||||||
|
install_${service}
|
||||||
|
if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
|
||||||
|
unset PIP_VIRTUAL_ENV
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
21
stack.sh
21
stack.sh
@ -94,6 +94,9 @@ source $TOP_DIR/functions
|
|||||||
# Import config functions
|
# Import config functions
|
||||||
source $TOP_DIR/lib/config
|
source $TOP_DIR/lib/config
|
||||||
|
|
||||||
|
# Import 'public' stack.sh functions
|
||||||
|
source $TOP_DIR/lib/stack
|
||||||
|
|
||||||
# Determine what system we are running on. This provides ``os_VENDOR``,
|
# Determine what system we are running on. This provides ``os_VENDOR``,
|
||||||
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
|
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
|
||||||
# and ``DISTRO``
|
# and ``DISTRO``
|
||||||
@ -742,13 +745,13 @@ fi
|
|||||||
|
|
||||||
if is_service_enabled keystone; then
|
if is_service_enabled keystone; then
|
||||||
if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
|
if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
|
||||||
install_keystone
|
stack_install_service keystone
|
||||||
configure_keystone
|
configure_keystone
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled s-proxy; then
|
if is_service_enabled s-proxy; then
|
||||||
install_swift
|
stack_install_service swift
|
||||||
configure_swift
|
configure_swift
|
||||||
|
|
||||||
# swift3 middleware to provide S3 emulation to Swift
|
# swift3 middleware to provide S3 emulation to Swift
|
||||||
@ -762,23 +765,23 @@ fi
|
|||||||
|
|
||||||
if is_service_enabled g-api n-api; then
|
if is_service_enabled g-api n-api; then
|
||||||
# image catalog service
|
# image catalog service
|
||||||
install_glance
|
stack_install_service glance
|
||||||
configure_glance
|
configure_glance
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled cinder; then
|
if is_service_enabled cinder; then
|
||||||
install_cinder
|
stack_install_service cinder
|
||||||
configure_cinder
|
configure_cinder
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled neutron; then
|
if is_service_enabled neutron; then
|
||||||
install_neutron
|
stack_install_service neutron
|
||||||
install_neutron_third_party
|
install_neutron_third_party
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled nova; then
|
if is_service_enabled nova; then
|
||||||
# compute service
|
# compute service
|
||||||
install_nova
|
stack_install_service nova
|
||||||
cleanup_nova
|
cleanup_nova
|
||||||
configure_nova
|
configure_nova
|
||||||
fi
|
fi
|
||||||
@ -787,19 +790,19 @@ if is_service_enabled horizon; then
|
|||||||
# django openstack_auth
|
# django openstack_auth
|
||||||
install_django_openstack_auth
|
install_django_openstack_auth
|
||||||
# dashboard
|
# dashboard
|
||||||
install_horizon
|
stack_install_service horizon
|
||||||
configure_horizon
|
configure_horizon
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled ceilometer; then
|
if is_service_enabled ceilometer; then
|
||||||
install_ceilometerclient
|
install_ceilometerclient
|
||||||
install_ceilometer
|
stack_install_service ceilometer
|
||||||
echo_summary "Configuring Ceilometer"
|
echo_summary "Configuring Ceilometer"
|
||||||
configure_ceilometer
|
configure_ceilometer
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_service_enabled heat; then
|
if is_service_enabled heat; then
|
||||||
install_heat
|
stack_install_service heat
|
||||||
install_heat_other
|
install_heat_other
|
||||||
cleanup_heat
|
cleanup_heat
|
||||||
configure_heat
|
configure_heat
|
||||||
|
59
tools/build_venv.sh
Executable file
59
tools/build_venv.sh
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# **tools/build_venv.sh** - Build a Python Virtual Envirnment
|
||||||
|
#
|
||||||
|
# build_venv.sh venv-path [package [...]]
|
||||||
|
#
|
||||||
|
# Assumes:
|
||||||
|
# - a useful pip is installed
|
||||||
|
# - virtualenv will be installed by pip
|
||||||
|
# - installs basic common prereq packages that require compilation
|
||||||
|
# to allow quick copying of resulting venv as a baseline
|
||||||
|
|
||||||
|
|
||||||
|
VENV_DEST=${1:-.venv}
|
||||||
|
shift
|
||||||
|
|
||||||
|
MORE_PACKAGES="$@"
|
||||||
|
|
||||||
|
# If TOP_DIR is set we're being sourced rather than running stand-alone
|
||||||
|
# or in a sub-shell
|
||||||
|
if [[ -z "$TOP_DIR" ]]; then
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
# Keep track of the devstack directory
|
||||||
|
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
|
||||||
|
FILES=$TOP_DIR/files
|
||||||
|
|
||||||
|
# Import common functions
|
||||||
|
source $TOP_DIR/functions
|
||||||
|
|
||||||
|
GetDistro
|
||||||
|
|
||||||
|
source $TOP_DIR/stackrc
|
||||||
|
|
||||||
|
trap err_trap ERR
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exit on any errors so that errors don't compound
|
||||||
|
function err_trap {
|
||||||
|
local r=$?
|
||||||
|
set +o xtrace
|
||||||
|
|
||||||
|
rm -rf $TMP_VENV_PATH
|
||||||
|
|
||||||
|
exit $r
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build new venv
|
||||||
|
virtualenv $VENV_DEST
|
||||||
|
|
||||||
|
# Install modern pip
|
||||||
|
$VENV_DEST/bin/pip install -U pip
|
||||||
|
|
||||||
|
for pkg in ${MORE_PACKAGES}; do
|
||||||
|
pip_install_venv $VENV_DEST $pkg
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user