From e822a0ff5a89216f14207f88146482fb20e7913a Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 26 May 2014 14:20:50 +1200 Subject: [PATCH] Always bind-mount pypi mirror if dir exists It may be desirable to specify file://tmp/pypi as one of the list of mirrors specified by PYPI_MIRROR_URL, so the local pypi mirror should be mounted as long as the directory exists. Even though the path is mounted, it is only used by pip if there is no specified PYPI_MIRROR_URL, or if one PYPI_MIRROR_URL entry specifies file://tmp/pypi. The pypi element previously assumed that a local mirror would be a complete offline mirror. This change allows for a mixture of local mirror plus remote mirrors. This means that the local mirror could (for example) contain a few locally built pip packages from arbitrary git checkouts for gate testing of those projects. In this scenario, most packages would be downloaded from the configured remote mirrors. This change is required for synchronous gating on the os-*-config tools. Change-Id: I0f6d153c06993ffd0d90bd8ca1717462e8b6b541 --- elements/pypi/README.md | 6 ++++-- elements/pypi/extra-data.d/00-mount-pypi-mirror | 13 +++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/elements/pypi/README.md b/elements/pypi/README.md index c32e2389..96e3085c 100644 --- a/elements/pypi/README.md +++ b/elements/pypi/README.md @@ -2,8 +2,9 @@ Inject a PyPI mirror ==================== 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. +~/.cache/image-create/pypi/mirror into the build environment as mirror URL +file:///tmp/pypi. The element temporarily overwrites /root/.pip.conf +and .pydistutils.cfg to use it. 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 @@ -23,6 +24,7 @@ you have more than 9 additional mirrors, some care will be needed. A typical use of this element is thus: export PYPI\_MIRROR\_URL=http://site/pypi/Ubuntu-13.10 export PYPI\_MIRROR\_URL\_1=http://site/pypi/ +export PYPI\_MIRROR\_URL\_2=file:///tmp/pypi [pypi-mirror](https://git.openstack.org/cgit/openstack-infra/pypi-mirror) can be useful in making a partial PyPI mirror suitable for building images. For diff --git a/elements/pypi/extra-data.d/00-mount-pypi-mirror b/elements/pypi/extra-data.d/00-mount-pypi-mirror index 709a11e8..0a3edd82 100755 --- a/elements/pypi/extra-data.d/00-mount-pypi-mirror +++ b/elements/pypi/extra-data.d/00-mount-pypi-mirror @@ -3,13 +3,10 @@ set -eu set -o pipefail -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 +if [ -d "$MIRROR_SOURCE" ]; then + MIRROR_TARGET=$TMP_MOUNT_PATH/tmp/pypi -sudo mkdir -p $MIRROR_SOURCE $MIRROR_TARGET -sudo mount --bind $MIRROR_SOURCE $TMP_MOUNT_PATH/tmp/pypi + sudo mkdir -p $MIRROR_SOURCE $MIRROR_TARGET + sudo mount --bind $MIRROR_SOURCE $MIRROR_TARGET +fi