mirror of https://github.com/docker/compose.git
Tag built images and use them when starting
A basic measure to get round the fact that adding isn't cached. Once Docker supports cached adds, this is probably redundant.
This commit is contained in:
parent
76b6354173
commit
507940535f
|
@ -139,14 +139,20 @@ class Service(object):
|
|||
container_options['volumes'] = dict((v.split(':')[1], {}) for v in container_options['volumes'])
|
||||
|
||||
if 'build' in self.options:
|
||||
container_options['image'] = self.build()
|
||||
if len(self.client.images(name=self._build_tag_name())) == 0:
|
||||
self.build()
|
||||
container_options['image'] = self._build_tag_name()
|
||||
|
||||
return container_options
|
||||
|
||||
def build(self):
|
||||
log.info('Building %s...' % self.name)
|
||||
|
||||
build_output = self.client.build(self.options['build'], stream=True)
|
||||
build_output = self.client.build(
|
||||
self.options['build'],
|
||||
tag=self._build_tag_name(),
|
||||
stream=True
|
||||
)
|
||||
|
||||
image_id = None
|
||||
|
||||
|
@ -162,6 +168,12 @@ class Service(object):
|
|||
|
||||
return image_id
|
||||
|
||||
def _build_tag_name(self):
|
||||
"""
|
||||
The tag to give to images built for this service.
|
||||
"""
|
||||
return '%s_%s' % (self.project, self.name)
|
||||
|
||||
|
||||
NAME_RE = re.compile(r'^([^_]+)_([^_]+)_(run_)?(\d+)$')
|
||||
|
||||
|
|
|
@ -113,6 +113,18 @@ class ServiceTest(DockerClientTestCase):
|
|||
container = service.start()
|
||||
container.wait()
|
||||
self.assertIn('success', container.logs())
|
||||
self.assertEqual(len(self.client.images(name='default_test')), 1)
|
||||
|
||||
def test_start_container_uses_tagged_image_if_it_exists(self):
|
||||
self.client.build('tests/fixtures/simple-dockerfile', tag='default_test')
|
||||
service = Service(
|
||||
name='test',
|
||||
client=self.client,
|
||||
build='this/does/not/exist/and/will/throw/error',
|
||||
)
|
||||
container = service.start()
|
||||
container.wait()
|
||||
self.assertIn('success', container.logs())
|
||||
|
||||
def test_start_container_creates_ports(self):
|
||||
service = self.create_service('web', ports=[8000])
|
||||
|
|
Loading…
Reference in New Issue