22"""Support the Deis workflow by manipulating and publishing Docker images."""
33
44from __future__ import unicode_literals
5- import io
65import logging
76
87from 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 {}\n ENV {}" .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 )
0 commit comments