Skip to content

Commit f29b72e

Browse files
committed
Merge pull request #248 from helgi/k8s_env
feat(registry): stop adding last mile ENV Vars into slugs as k8s handles that
2 parents aed2b2d + 4a6d880 commit f29b72e

4 files changed

Lines changed: 10 additions & 51 deletions

File tree

rootfs/api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def publish(self, source_version='latest'):
847847
# If the build has a SHA, assume it's from deis-builder and in the deis-registry already
848848
deis_registry = bool(self.build.sha)
849849
if not self.build.dockerfile and not self.build.sha:
850-
publish_release(source_image, self.config.values, self.image, deis_registry)
850+
publish_release(source_image, self.image, deis_registry)
851851

852852
def previous(self):
853853
"""

rootfs/registry/dockerclient.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Support the Deis workflow by manipulating and publishing Docker images."""
33

44
from __future__ import unicode_literals
5-
import io
65
import logging
76

87
from django.conf import settings
@@ -22,7 +21,7 @@ def __init__(self):
2221
self.client = docker.Client(version='auto')
2322
self.registry = settings.REGISTRY_HOST + ':' + str(settings.REGISTRY_PORT)
2423

25-
def publish_release(self, source, config, target, deis_registry):
24+
def publish_release(self, source, target, deis_registry):
2625
"""Update a source Docker image with environment config and publish it to deis-registry."""
2726
# get the source repository name and tag
2827
src_name, src_tag = docker.utils.parse_repository_tag(source)
@@ -42,29 +41,12 @@ def publish_release(self, source, config, target, deis_registry):
4241
self.pull(repo, src_tag)
4342

4443
# tag the image locally without the repository URL
45-
image = "{}:{}".format(repo, src_tag)
46-
self.tag(image, src_name, tag=src_tag)
47-
48-
# build a Docker image that adds a "last-mile" layer of environment
49-
config.update({'DEIS_APP': name, 'DEIS_RELEASE': tag})
50-
self.build(source, config, name, tag)
44+
image = "{}:{}".format(src_name, src_tag)
45+
self.tag(image, "{}/{}".format(self.registry, name), tag=tag)
5146

5247
# push the image to deis-registry
5348
self.push("{}/{}".format(self.registry, name), tag)
5449

55-
def build(self, source, config, repo, tag):
56-
"""Add a "last-mile" layer of environment config to a Docker image for deis-registry."""
57-
check_blacklist(repo)
58-
env = ' '.join("{}='{}'".format(
59-
k, v.encode('unicode-escape').replace("'", "\\'")) for k, v in config.viewitems())
60-
dockerfile = "FROM {}\nENV {}".format(source, env)
61-
f = io.BytesIO(dockerfile.encode('utf-8'))
62-
target_repo = "{}/{}:{}".format(self.registry, repo, tag)
63-
logger.info("Building Docker image {}".format(target_repo))
64-
with SimpleFlock(self.FLOCKFILE, timeout=1200):
65-
stream = self.client.build(fileobj=f, tag=target_repo, stream=True, rm=True)
66-
log_output(stream)
67-
6850
def pull(self, repo, tag):
6951
"""Pull a Docker image into the local storage graph."""
7052
check_blacklist(repo)
@@ -112,7 +94,6 @@ def strip_prefix(name):
11294
return '/'.join(p for p in paths if p and '.' not in p and ':' not in p)
11395

11496

115-
def publish_release(source, config, target, deis_registry):
116-
97+
def publish_release(source, target, deis_registry):
11798
client = DockerClient()
118-
return client.publish_release(source, config, target, deis_registry)
99+
return client.publish_release(source, target, deis_registry)

rootfs/registry/models.py

Whitespace-only changes.

rootfs/registry/tests.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,22 @@ def setUp(self):
2525

2626
def test_publish_release(self, mock_client):
2727
self.client = DockerClient()
28-
self.client.publish_release('ozzy/embryo:git-f2a8020',
29-
{'POWERED_BY': 'Deis'}, 'ozzy/embryo:v4', True)
28+
self.client.publish_release('ozzy/embryo:git-f2a8020', 'ozzy/embryo:v4', True)
3029
self.assertTrue(self.client.client.pull.called)
3130
self.assertTrue(self.client.client.tag.called)
32-
self.assertTrue(self.client.client.build.called)
3331
self.assertTrue(self.client.client.push.called)
3432
# Test that a registry host prefix is replaced with deis-registry for the target
35-
self.client.publish_release('ozzy/embryo:git-f2a8020',
36-
{'POWERED_BY': 'Deis'}, 'quay.io/ozzy/embryo:v4', True)
33+
self.client.publish_release('ozzy/embryo:git-f2a8020', 'quay.io/ozzy/embryo:v4', True)
3734
docker_push = self.client.client.push
3835
docker_push.assert_called_with(
3936
'localhost:5000/ozzy/embryo', tag='v4', insecure_registry=True, stream=True)
4037
# Test that blacklisted image names can't be published
4138
with self.assertRaises(PermissionDenied):
4239
self.client.publish_release(
43-
'deis/controller:v1.11.1', {}, 'deis/controller:v1.11.1', True)
40+
'deis/controller:v1.11.1', 'deis/controller:v1.11.1', True)
4441
with self.assertRaises(PermissionDenied):
4542
self.client.publish_release(
46-
'localhost:5000/deis/controller:v1.11.1', {}, 'deis/controller:v1.11.1', True)
47-
48-
def test_build(self, mock_client):
49-
# test that self.client.build was called with proper arguments
50-
self.client = DockerClient()
51-
self.client.build('ozzy/embryo:git-f3a8020', {'POWERED_BY': 'Deis'}, 'ozzy/embryo', 'v4')
52-
docker_build = self.client.client.build
53-
self.assertTrue(docker_build.called)
54-
args = {"rm": True, "tag": u'localhost:5000/ozzy/embryo:v4', "stream": True}
55-
kwargs = docker_build.call_args[1]
56-
self.assertDictContainsSubset(args, kwargs)
57-
# test that the fileobj arg to "docker build" contains a correct Dockerfile
58-
f = kwargs['fileobj']
59-
self.assertEqual(f.read(), "FROM ozzy/embryo:git-f3a8020\nENV POWERED_BY='Deis'")
60-
# Test that blacklisted image names can't be built
61-
with self.assertRaises(PermissionDenied):
62-
self.client.build('deis/controller:v1.11.1', {}, 'deis/controller', 'v1.11.1')
63-
with self.assertRaises(PermissionDenied):
64-
self.client.build(
65-
'localhost:5000/deis/controller:v1.11.1', {}, 'deis/controller', 'v1.11.1')
43+
'localhost:5000/deis/controller:v1.11.1', 'deis/controller:v1.11.1', True)
6644

6745
def test_pull(self, mock_client):
6846
self.client = DockerClient()

0 commit comments

Comments
 (0)