signalfx / maestro-ng

Orchestration of Docker-based, multi-host environments
https://signalfx.com
Apache License 2.0
683 stars 83 forks source link

Support for list-type of backend.images in tasks.py _create_and_start_container() to fetch RepoTags #188

Closed ac111 closed 7 years ago

ac111 commented 7 years ago

We're testing Nexus 3.2-hosted Docker registries (moving away from a legacy v0.6.8 registry), and found that while service image pulls worked correctly, service start failed with an error indicating a NoneType variable was being iterated. I traced the code down to the following code in tasks.py (_create_and_start_container):

not filter( lambda i: self.container.image in i['RepoTags'], self.container.ship.backend.images(image['repository']))

The issue appears to be i['RepoTags'] would resolve to None and cause the exception. When inspecting the data returned by self.container.ship.backend.images(image['repository']) was in fact a list of dicts (containing RepoTags). In order to accommodate the list, I'm proposing to change the code to something like this:

pull_image = True
backend_images = self.container.ship.backend.images(image['repository'])
if isinstance(backend_images, list):
    for image_repo in backend_images:
        if image_repo['RepoTags']:
           if self.container.image in image_repo['RepoTags']:
               pull_image = False
else:
  pull_image = not filter(
                    lambda i: self.container.image in i['RepoTags'],
                    self.container.ship.backend.images(image['repository']))

if self._refresh or pull_image:
    PullTask(self.o, self.container, self._registries,
                         standalone=False).run()

With this change, service start appears to work with both legacy and new repositories that we've tested.

mpetazzoni commented 7 years ago

Oh I believe I just fixed this very recently, it's just not released: https://github.com/signalfx/maestro-ng/commit/6fdb9b4b93ffed7b0b3bd5205389bb8f9fbbb9e5. Can you test with master and check that the fix I have works in your situation?

ac111 commented 7 years ago

Excellent -- this seems to work nicely!

mpetazzoni commented 7 years ago

Cool. I'll close this and do a release soon.