Read about our upcoming Code of Conduct on this issue

Commit d47de7a7 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

WIP Heptapod PAAS Runner: service aliases

Changing the image name also changes the resulting default alias to
something like `foss.heptapod.net__heptapod__dependency_proxy__containers__redis`
so we need to add an explicit alias in this case.

branch : heptapod
parent 144109379aa8
......@@ -27,9 +27,8 @@ DOCKERFILE = (
def is_from_docker_hub(image_tag, job_vars):
expanded = expand_variables(image_tag, job_vars)
host = expanded.rsplit(':', 1)[0].split('/', 1)[0]
def is_from_docker_hub(image_tag):
host = image_tag.rsplit(':', 1)[0].split('/', 1)[0]
# TODO check that '.' is indeed forbidden in an image name or plainly
# check the official Docker pull implementation.
return '.' not in host
......@@ -100,7 +99,8 @@ class DockerBuildHelper:
main_image = job_data.get('image')
if main_image is not None:
main_image_name = main_image['name']
if is_from_docker_hub(main_image_name, job_vars):
expanded_main = expand_variables(main_image_name, job_vars)
if is_from_docker_hub(expanded_main):
main_image['name'] = '/'.join((proxy_url, main_image_name))
services = job_data.get('services')
......@@ -119,8 +119,30 @@ class DockerBuildHelper:
logger.warning("Job %d: did not understand image/tag "
"in service definition %r",
job_id, service)
elif is_from_docker_hub(srv_image_name, job_vars):
expanded_srv = expand_variables(srv_image_name, job_vars)
if is_from_docker_hub(expanded_srv):
service['name'] = '/'.join((proxy_url, srv_image_name))
# at this point we are sure we don't have a host part, hence
# the last ':' is guaranteed to be the separator between
# repo path (such as `postgres` or `octobus/heptapod`) and
# the tag name (deemed 'version' in GitLab Runner sources)
# Reference:
# (we can only put one alias, so we choose the one most
# encouraged by GitLab docs, which is compliant with valid DNS
# names, aka RFC 1123 section 2.1, relying itself on RFC 952)
# TODO make a general Docker image name parsing consistent
# with Go's `services.SplitNameAndVersion` and use it
# everywhere
if not service.get('alias'): # could be empty string
# presumably, if there is a user-defined alias, it must
# be in use. TODO mention in forthcoming doc
service['alias'] = (expanded_srv.rsplit(':', 1)[0]
.replace('/', '-'))
job_data['services'] = new_services
......@@ -18,21 +18,12 @@ from ..testing import (
def test_is_from_docker_hub():
assert not any(is_from_docker_hub(image, job_vars={}) for image in (
assert not any(is_from_docker_hub(image) for image in (
assert not any(is_from_docker_hub('$MY_VAR/group/proj$TAG',
for myvar in ('',
for tag in ('', ':testing')
def test_docker_git(tmpdir):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment