From 1adf3a377e1ed0d7aa3cce86951c48ca5b6f6cf5 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 19 Feb 2014 14:03:56 +1300 Subject: [PATCH] Permit using arbitrary PyPI urls. The pypi element is cool, but some folk have local network mirrors which we should permit them to use. Change-Id: Ie840ad1184e72b0e01966eee0298cfd6511b6c19 --- elements/pypi/README.md | 14 ++++++++------ elements/pypi/extra-data.d/00-mount-pypi-mirror | 5 +++++ .../pypi/pre-install.d/00-configure-pypi-mirror | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/elements/pypi/README.md b/elements/pypi/README.md index 10002fd2..f83ffc49 100644 --- a/elements/pypi/README.md +++ b/elements/pypi/README.md @@ -1,13 +1,15 @@ Inject a PyPI mirror ==================== -Bind mounts a PyPI mirror from ~/.cache/image-create/pypi/mirror into the build -environment and temporarily overwrites /root/.pip.conf and .pydistutils.cfg to -use it. +Use a custom PyPI mirror to build images. The default is to bind mount one from +~/.cache/image-create/pypi/mirror into the build environment. The element +temporarily overwrites /root/.pip.conf and .pydistutils.cfg to use it. -When online, the master pypi index is supplied as an extra-url, so uncached -dependencies will still be available. When offline, only the mirror is used - a -stale mirror will cause build failures. +When online, the official pypi.python.org pypi index is supplied as an +extra-url, so uncached dependencies will still be available. When offline, only +the mirror is used - be warned that a stale mirror will cause build failures. + +To use an arbitrary mirror set PYPI\_MIRROR\_URL=http[s]://somevalue/ [jeepyb](https://git.openstack.org/cgit/openstack-infra/jeepyb) can be useful in making a partial PyPI mirror suitable for building images. For instance: diff --git a/elements/pypi/extra-data.d/00-mount-pypi-mirror b/elements/pypi/extra-data.d/00-mount-pypi-mirror index 8aa01611..6cc12534 100755 --- a/elements/pypi/extra-data.d/00-mount-pypi-mirror +++ b/elements/pypi/extra-data.d/00-mount-pypi-mirror @@ -2,6 +2,11 @@ set -eu +PYPI_MIRROR_URL=${PYPI_MIRROR_URL:-''} +if [ -n "$PYPI_MIRROR_URL" ]; then + # External mirror URL being used - no need to bind mount anything. + exit 0 +fi MIRROR_SOURCE=~/.cache/image-create/pypi/mirror/ MIRROR_TARGET=$TMP_MOUNT_PATH/tmp/pypi diff --git a/elements/pypi/pre-install.d/00-configure-pypi-mirror b/elements/pypi/pre-install.d/00-configure-pypi-mirror index 402951c5..89c48ec3 100755 --- a/elements/pypi/pre-install.d/00-configure-pypi-mirror +++ b/elements/pypi/pre-install.d/00-configure-pypi-mirror @@ -2,7 +2,7 @@ set -eu -PYPIURL=file:///tmp/pypi +PYPIURL=${PYPI_MIRROR_URL:-'file:///tmp/pypi'} mkdir -p ~/.pip if [ -e ~/.pip/pip.conf ]; then