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
This commit is contained in:
Monty Taylor 2018-07-13 11:25:43 -05:00
parent ea3d7cbf2a
commit 19463f937d
2 changed files with 16 additions and 0 deletions

View File

@ -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)

View File

@ -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()))