|
7 | 7 | from http.client import responses |
8 | 8 | import json |
9 | 9 | import string |
| 10 | +import re |
10 | 11 | import time |
11 | 12 | import escapism |
12 | 13 |
|
|
55 | 56 | LAUNCHES_INPROGRESS = Gauge('binderhub_inprogress_launches', 'Launches currently in progress') |
56 | 57 |
|
57 | 58 |
|
| 59 | +def _get_image_basename_and_tag(full_name): |
| 60 | + """Get a supposed image name and tag without the registry part |
| 61 | + :param full_name: full image specification, e.g. "gitlab.com/user/project:tag" |
| 62 | + :return: tuple of image name and tag, e.g. ("user/project", "tag") |
| 63 | + """ |
| 64 | + # the tag is either after the last (and only) colon, or not given at all, |
| 65 | + # in which case "latest" is implied |
| 66 | + tag_splits = full_name.rsplit(':', 1) |
| 67 | + if len(tag_splits) == 2: |
| 68 | + image_name = tag_splits[0] |
| 69 | + tag = tag_splits[1] |
| 70 | + else: |
| 71 | + image_name = full_name |
| 72 | + tag = 'latest' |
| 73 | + |
| 74 | + if re.fullmatch('[a-z0-9]{4,40}/[a-z0-9\._-]{2,255}', image_name): |
| 75 | + # if it looks like a Docker Hub image name, we're done |
| 76 | + return image_name, tag |
| 77 | + else: |
| 78 | + # if the image isn't implied to origin at Docker Hub, the first part has to be a registry |
| 79 | + image_basename = '/'.join(image_name.split('/')[1:]) |
| 80 | + return image_basename, tag |
| 81 | + |
| 82 | + |
58 | 83 | def _generate_build_name(build_slug, ref, prefix='', limit=63, ref_length=6): |
59 | 84 | """Generate a unique build name with a limited character length. |
60 | 85 |
|
@@ -310,7 +335,7 @@ async def get(self, provider_prefix, _unescaped_spec): |
310 | 335 | if self.settings['use_registry']: |
311 | 336 | for _ in range(3): |
312 | 337 | try: |
313 | | - image_manifest = await self.registry.get_image_manifest(*'/'.join(image_name.split('/')[-2:]).split(':', 1)) |
| 338 | + image_manifest = await self.registry.get_image_manifest(*_get_image_basename_and_tag(image_name)) |
314 | 339 | image_found = bool(image_manifest) |
315 | 340 | break |
316 | 341 | except HTTPClientError: |
|
0 commit comments