From a875596ba2a0c37fff131ff6ea1f899732b0f5ce Mon Sep 17 00:00:00 2001 From: Steve Lewis Date: Thu, 8 Oct 2015 22:58:26 -0700 Subject: [PATCH] Use pip install --proxy when $HTTPS_PROXY is set During execution of our bootstrap scripts, we need to install some packages before we have constructed any of the infrastructure. In this case when installing behind a proxy we should respect that proxy. When $HTTPS_PROXY is not set but $HTTP_PROXY is, that will be used instead. The use of trusted-host or other pip configurations to enable this usage are out of scope and can be resolved separately. Change-Id: I3df5ef6a7d33a3357e8c00f138b019c06c6bc3d6 Closes-Bug: 1504405 --- scripts/bootstrap-aio.sh | 12 +++++++++++- scripts/bootstrap-ansible.sh | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/bootstrap-aio.sh b/scripts/bootstrap-aio.sh index ebee530b3b..1607ca4877 100755 --- a/scripts/bootstrap-aio.sh +++ b/scripts/bootstrap-aio.sh @@ -21,6 +21,8 @@ set -e -u -x ## Vars ---------------------------------------------------------------------- DEFAULT_PASSWORD=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 32) export BOOTSTRAP_AIO="yes" +export HTTP_PROXY=${HTTP_PROXY:-""} +export HTTPS_PROXY=${HTTPS_PROXY:-""} export ADMIN_PASSWORD=${ADMIN_PASSWORD:-$DEFAULT_PASSWORD} export SERVICE_REGION=${SERVICE_REGION:-"RegionOne"} export DEPLOY_OPENSTACK=${DEPLOY_OPENSTACK:-"yes"} @@ -151,9 +153,17 @@ fi # Install pip get_pip +# Ensure we use the HTTPS/HTTP proxy with pip if it is specified +PIP_OPTS="" +if [ -n "$HTTPS_PROXY" ]; then + PIP_OPTS="--proxy $HTTPS_PROXY" +elif [ -n "$HTTP_PROXY" ]; then + PIP_OPTS="--proxy $HTTP_PROXY" +fi + # Install requirements if there are any if [ -f "requirements.txt" ];then - pip2 install -r requirements.txt || pip install -r requirements.txt + pip2 install $PIP_OPTS -r requirements.txt || pip install $PIP_OPTS -r requirements.txt fi # Configure all disk space diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index 9507be074f..f5f343f80a 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -20,6 +20,8 @@ set -e -u -x ## Vars ---------------------------------------------------------------------- +export HTTP_PROXY=${HTTP_PROXY:-""} +export HTTPS_PROXY=${HTTPS_PROXY:-""} export ANSIBLE_GIT_RELEASE=${ANSIBLE_GIT_RELEASE:-"v1.9.3-1"} export ANSIBLE_GIT_REPO=${ANSIBLE_GIT_REPO:-"https://github.com/ansible/ansible"} export ANSIBLE_ROLE_FILE=${ANSIBLE_ROLE_FILE:-"ansible-role-requirements.yml"} @@ -65,13 +67,21 @@ popd # Install pip get_pip +# Ensure we use the HTTPS/HTTP proxy with pip if it is specified +PIP_OPTS="" +if [ -n "$HTTPS_PROXY" ]; then + PIP_OPTS="--proxy $HTTPS_PROXY" +elif [ -n "$HTTP_PROXY" ]; then + PIP_OPTS="--proxy $HTTP_PROXY" +fi + # Install requirements if there are any if [ -f "requirements.txt" ];then - pip2 install -r requirements.txt || pip install -r requirements.txt + pip2 install $PIP_OPTS -r requirements.txt || pip install $PIP_OPTS -r requirements.txt fi # Install ansible -pip2 install "${ANSIBLE_WORKING_DIR}" || pip install "${ANSIBLE_WORKING_DIR}" +pip2 install $PIP_OPTS "${ANSIBLE_WORKING_DIR}" || pip install $PIP_OPTS "${ANSIBLE_WORKING_DIR}" # Update dependent roles if [ -f "${ANSIBLE_ROLE_FILE}" ];then