[WIP] Debug image building
Change-Id: Icfe563f1a0f780cc2315c3107c62744141100a00
This commit is contained in:
parent
6aa92e029d
commit
5df99b4bbb
|
@ -20,6 +20,8 @@ ARG REGISTRY_PROTOCOL="detect"
|
|||
ARG REGISTRY_INSECURE="False"
|
||||
ARG KEEP_ALL_WHEELS="False"
|
||||
|
||||
ARG BUILDSET_REGISTRY_HOST=""
|
||||
|
||||
# NOTE: This option is only applicable to apt/dpkg systems. The value is noop
|
||||
# for rpm based systems. This will not show up in the final image regardless.
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
if ! grep -q zuul-jobs.buildset-registry /etc/hosts; then
|
||||
echo "$BUILDSET_REGISTRY_HOST zuul-jobs.buildset-registry" >> /etc/hosts
|
||||
fi
|
||||
|
||||
cat /etc/hosts
|
|
@ -5,6 +5,10 @@ import platform
|
|||
import re
|
||||
import ssl
|
||||
from urllib import request as urllib2
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
DOCKER_REGISTRY = 'registry.hub.docker.com'
|
||||
|
||||
|
@ -113,6 +117,7 @@ def protocol_detection(registry, protocol='http'):
|
|||
index = PROTOCOLS.index(protocol)
|
||||
try:
|
||||
url = "{}://{}".format(protocol, registry)
|
||||
logger.info("Trying to request: %s", url)
|
||||
r = urllib2.Request(url)
|
||||
urllib2.urlopen(r)
|
||||
except (urllib2.URLError, urllib2.HTTPError) as err:
|
||||
|
@ -137,15 +142,20 @@ def get_wheels(url):
|
|||
buf = e.partial
|
||||
return buf
|
||||
|
||||
def is_registry_defined(full_image):
|
||||
parts = full_image.split('/', 1)
|
||||
if parts[0].find('.') != -1 or parts[0].find(':') != -1:
|
||||
return True
|
||||
|
||||
def parse_image(full_image):
|
||||
slash_occurrences = len(re.findall('/', full_image))
|
||||
repo = None
|
||||
registry = DOCKER_REGISTRY
|
||||
if is_registry_defined(full_image):
|
||||
registry, full_image = full_image.split('/', 1)
|
||||
slash_occurrences = len(re.findall('/', full_image))
|
||||
if slash_occurrences > 1:
|
||||
full_image_list = full_image.split('/')
|
||||
registry = full_image_list[0]
|
||||
repo = '/'.join(full_image_list[1:-1])
|
||||
repo = '/'.join(full_image_list[0:-1])
|
||||
image = full_image_list[-1]
|
||||
elif slash_occurrences == 1:
|
||||
repo, image = full_image.split('/')
|
||||
|
@ -165,22 +175,32 @@ def main():
|
|||
with open('/opt/loci/wheels', 'r') as f:
|
||||
wheels = f.read()
|
||||
|
||||
logger.info("Fetching wheels from %s", wheels)
|
||||
|
||||
if wheels.startswith('/'):
|
||||
logger.info("Wheels seems to be a local file. Reading it.")
|
||||
with open(wheels, 'rb') as f:
|
||||
data = f.read()
|
||||
elif wheels.startswith('http'):
|
||||
logger.info("Wheels seems to be a HTTP URL. Fetching it.")
|
||||
data = get_wheels(wheels)
|
||||
else:
|
||||
logger.info("Wheels seems to be a docker image. Fetching it.")
|
||||
registry, image, tag = parse_image(wheels)
|
||||
logger.info("Fetching image %s:%s from registry %s", image, tag, registry)
|
||||
if os.environ.get('REGISTRY_PROTOCOL') in ['http', 'https']:
|
||||
logger.info("Using protocol %s from environment", os.environ.get('REGISTRY_PROTOCOL'))
|
||||
protocol = os.environ.get('REGISTRY_PROTOCOL')
|
||||
elif os.environ.get('REGISTRY_PROTOCOL') == 'detect':
|
||||
logger.info("Detecting protocol for registry %s", registry)
|
||||
protocol = protocol_detection(registry)
|
||||
logger.info("Detected protocol %s", protocol)
|
||||
else:
|
||||
raise ValueError("Unknown protocol given in argument")
|
||||
kwargs = dict()
|
||||
if registry:
|
||||
kwargs.update({'registry': registry})
|
||||
logger.info("Fetching image %s:%s from registry %s with protocol %s", image, tag, registry, protocol)
|
||||
data = get_blob(image, tag, protocol, **kwargs)
|
||||
|
||||
if 'WHEELS_DEST' in os.environ:
|
||||
|
|
|
@ -60,6 +60,10 @@ if [ "${KEEP_ALL_WHEELS}" != "False" ]; then
|
|||
NO_INDEX=--no-index
|
||||
fi
|
||||
|
||||
if [[ -n ${BUILDSET_REGISTRY_HOST} ]]; then
|
||||
$(dirname $0)/configure_resolv_conf.sh
|
||||
fi
|
||||
|
||||
$(dirname $0)/fetch_wheels.sh
|
||||
if [[ "${PROJECT}" == "infra" ]]; then
|
||||
$(dirname $0)/setup_pip.sh
|
||||
|
|
Loading…
Reference in New Issue