From 19463f937d547c0ec6d9d2872c04b42bdb9ab431 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 13 Jul 2018 11:25:43 -0500 Subject: [PATCH] Add support for supplying alpine mirror url In order to build images and use a local mirror, add an option which updates the built-in alpine mirror. It puts it back at the end because someone might otherwise use the output as a base image and it would point to a random location. Change-Id: I32cd19f79f1d474b0c011e39d139a78e196ce563 --- pbrx/cmd/main.py | 6 ++++++ pbrx/container_images.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/pbrx/cmd/main.py b/pbrx/cmd/main.py index aa36593..c893680 100644 --- a/pbrx/cmd/main.py +++ b/pbrx/cmd/main.py @@ -108,6 +108,12 @@ def main(): "--prefix", help="Organization prefix container images will be published to" ) + cmd_images.add_argument( + "--mirror", + help=( + "Base url for an alpine mirror to use. Will be used to replace" + " http://dl-cdn.alpinelinux.org/alpine"), + ) args = parser.parse_args() setup_logging(args.log_config, args.debug) diff --git a/pbrx/container_images.py b/pbrx/container_images.py index 3168294..9f75a3a 100755 --- a/pbrx/container_images.py +++ b/pbrx/container_images.py @@ -20,6 +20,7 @@ import tempfile import sh +ALPINE_MIRROR_BASE = "http://dl-cdn.alpinelinux.org/alpine" log = logging.getLogger("pbrx.container_images") @@ -119,6 +120,10 @@ def build(args): log.info("Building base python container") # Create base python container which has distro packages updated with docker_container("python:alpine", tag="python-base") as cont: + if args.mirror: + cont.run("sed -i 's,{old},{new}' /etc/apk/repositories".format( + old=ALPINE_MIRROR_BASE, + new=args.mirror)) cont.run("apk update") log.info("Building bindep container") @@ -216,6 +221,11 @@ def build(args): "pip install" " $(echo /root/.cache/pip/*.whl)[{base}]".format( base=info.base_container.replace('-', '_'))) + if args.mirror: + cont.run( + "sed -i 's,{old},{new}' /etc/apk/repositories".format( + old=args.mirror, + new=ALPINE_MIRROR_BASE)) # chown wheel cache back so the temp dir can delete it cont.run("chown -R {uid} /root/.cache/pip".format( uid=os.getuid()))