Skip to content

Commit f1f5c8b

Browse files
author
Matthew Fisher
committed
fix(controller): import image from remote registry
This change allows us to import an image from a remote repository, thanks to a new feature implemented in https://github.com/deis/docker-registry/compare/repository-import. Though the infrastructure in place allows us to import an image from the public index, the endpoints are closed-source and therefore are not implmented in the upstream repository-import branch.
1 parent e9d1487 commit f1f5c8b

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

controller/api/models.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111
import os
1212
import subprocess
13+
from urlparse import urlparse
1314

1415
from celery.canvas import group
1516
from django.conf import settings
@@ -483,14 +484,37 @@ def new(self, user, config=None, build=None, summary=None):
483484
owner=user, app=self.app, config=config,
484485
build=build, version=new_version, image=target_image, summary=summary)
485486
# publish release to registry as new docker image
486-
if self.build.sha:
487-
publish_release(self.build.image,
488-
self.build.sha,
487+
if build.sha:
488+
publish_release(build.image,
489+
build.sha,
489490
config.values,
490491
self.app.id,
491492
tag)
492493
else:
493-
publish_release(self.build.image,
494+
# we assume that the image is not present on our registry,
495+
# so shell out a task to pull in the repository
496+
url = urlparse(build.image)
497+
repository_name = url.path[1:]
498+
if url.hostname and url.port:
499+
tasks.import_repository.delay(
500+
'{}://{}:{}'.format(url.scheme, url.hostname, url.port),
501+
repository_name,
502+
self.app.id,
503+
).get()
504+
elif url.hostname:
505+
tasks.import_repository.delay(
506+
'{}://{}'.format(url.scheme, url.hostname),
507+
repository_name,
508+
self.app.id,
509+
).get()
510+
else:
511+
# assume only the repository path is given, which means that
512+
# it's on the public index
513+
tasks.import_repository.delay(settings.PUBLIC_INDEX_URL,
514+
build.image,
515+
self.app.id,
516+
).get()
517+
publish_release(self.app.id,
494518
'latest',
495519
config.values,
496520
self.app.id,

controller/api/tasks.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
from __future__ import unicode_literals
99

10+
import requests
1011
import threading
1112

1213
from celery import task
14+
from django.conf import settings
1315

1416

1517
@task
@@ -34,6 +36,21 @@ def deploy_release(app, release):
3436
[t.join() for t in threads]
3537

3638

39+
@task
40+
def import_repository(src_index, src_repository, target_repository):
41+
"""Imports an image from a remote into our own private registry"""
42+
43+
data = {
44+
'src_index': src_index,
45+
'src_repository': src_repository,
46+
}
47+
response = requests.post(
48+
'{}/v1/repositories/{}/tags'.format(settings.REGISTRY_URL,
49+
target_repository),
50+
data=data,
51+
)
52+
53+
3754
@task
3855
def start_containers(containers):
3956
create_threads = []

0 commit comments

Comments
 (0)