Skip to content

Commit

Permalink
Fix push command skipped services with existing imagees, but that wer…
Browse files Browse the repository at this point in the history
…en't pushed

Signed-off-by: Mykyta Usikov <mykyta.usikov@gmail.com>
  • Loading branch information
musikov committed May 5, 2020
1 parent 9c5351c commit a64973f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compose/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ def push(self, service_names=None, ignore_push_failures=False):
repo, tag, sep = parse_repository_tag(service.image_name)
service_image_name = sep.join((repo, tag)) if tag else sep.join((repo, 'latest'))

if service_image_name not in unique_images:
# Add service to unique if it's pushable
if (service_image_name not in unique_images and
service.can_be_pushed()):
service.push(ignore_push_failures)
unique_images.add(service_image_name)

Expand Down
10 changes: 8 additions & 2 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,12 @@ def get_cache_from(self, build_opts):
def can_be_built(self):
return 'build' in self.options

def can_be_pulled(self):
return 'image' in self.options

def can_be_pushed(self):
return 'build' in self.options and 'image' in self.options

def labels(self, one_off=False, legacy=False):
proj_name = self.project if not legacy else re.sub(r'[_-]', '', self.project)
return [
Expand Down Expand Up @@ -1227,7 +1233,7 @@ def _do_pull(self, repo, pull_kwargs, silent, ignore_pull_failures):
log.error(six.text_type(e))

def pull(self, ignore_pull_failures=False, silent=False, stream=False):
if 'image' not in self.options:
if not self.can_be_pulled():
return

repo, tag, separator = parse_repository_tag(self.options['image'])
Expand All @@ -1250,7 +1256,7 @@ def pull(self, ignore_pull_failures=False, silent=False, stream=False):
return progress_stream.get_digest_from_pull(event_stream)

def push(self, ignore_push_failures=False):
if 'image' not in self.options or 'build' not in self.options:
if not self.can_be_pushed():
return

repo, tag, separator = parse_repository_tag(self.options['image'])
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from .. import mock
from .. import unittest
from ..helpers import BUSYBOX_IMAGE_NAME
from ..helpers import BUSYBOX_DEFAULT_TAG
from ..helpers import BUSYBOX_IMAGE_WITH_TAG
from compose.config import ConfigurationError
from compose.config.config import Config
Expand Down Expand Up @@ -846,6 +848,23 @@ def test_avoid_multiple_push(self):
project.push()
assert fake_push.call_count == 2

def test_push_duplicate_image(self):
svc_no_build = Service(
'busy1', image=BUSYBOX_IMAGE_WITH_TAG,
client=self.mock_client)
svc_with_build = Service(
'busy2', image=BUSYBOX_IMAGE_WITH_TAG,
build='.',
client=self.mock_client)
project = Project(
'composetest', [svc_no_build, svc_with_build], self.mock_client
)
project.push()
self.mock_client.push.assert_called_once_with(
BUSYBOX_IMAGE_NAME,
tag=BUSYBOX_DEFAULT_TAG,
stream=True)

def test_get_secrets_no_secret_def(self):
service = 'foo'
secret_source = 'bar'
Expand Down

0 comments on commit a64973f

Please sign in to comment.