Esempio n. 1
0
 def push_image(self, tag=None):
     image = self.image[self.registry:tag:self.account]
     fabricio.local(
         'docker push {image}'.format(image=image),
         quiet=False,
         use_cache=True,
     )
Esempio n. 2
0
 def push_image(self, tag=None):
     image = self.image[self.registry:tag:self.account]
     fabricio.local(
         'docker push {image}'.format(image=image),
         quiet=False,
         use_cache=True,
     )
Esempio n. 3
0
    def prepare(self, tag=None, **kwargs):
        """
        build Docker image (see 'docker build --help' for available options)
        """
        # default options
        kwargs.setdefault('pull', True)
        kwargs.setdefault('force-rm', True)

        for key, value in kwargs.items():
            try:
                kwargs[key] = utils.strtobool(value)
            except ValueError:
                pass

        options = utils.Options(tag=self.image[self.registry:tag:self.account],
                                **kwargs)
        fabricio.local(
            'docker build {options} {build_path}'.format(
                build_path=self.build_path,
                options=options,
            ),
            quiet=False,
            use_cache=True,
        )
        self.delete_dangling_images()
Esempio n. 4
0
 def prepare(self, tag=None):
     """
     prepare[:tag=None] - prepare Docker image
     """
     fabricio.local(
         'docker pull {image}'.format(image=self.image[tag]),
         quiet=False,
         use_cache=True,
     )
Esempio n. 5
0
 def delete_dangling_images(self):  # pragma: no cover
     warnings.warn(
         'delete_dangling_images() is deprecated and will be removed in v0.6',  # noqa
         DeprecationWarning,
     )
     warnings.warn(
         'delete_dangling_images() is deprecated and will be removed in v0.6',  # noqa
         RuntimeWarning, stacklevel=self._warnings_stacklevel,
     )
     fabricio.local(dangling_images_delete_command(), ignore_errors=True)
Esempio n. 6
0
 def prepare(self, tag=None):
     """
     prepare Docker image
     """
     fabricio.local(
         'docker pull {image}'.format(image=self.image[tag]),
         quiet=False,
         use_cache=True,
     )
     self.delete_dangling_images()
Esempio n. 7
0
 def delete_dangling_images(self):  # pragma: no cover
     warnings.warn(
         'delete_dangling_images() is deprecated and will be removed in v0.6',  # noqa
         DeprecationWarning,
     )
     warnings.warn(
         'delete_dangling_images() is deprecated and will be removed in v0.6',  # noqa
         RuntimeWarning,
         stacklevel=self._warnings_stacklevel,
     )
     fabricio.local(dangling_images_delete_command(), ignore_errors=True)
Esempio n. 8
0
 def prepare(self, tag=None):
     """
     download Docker image from the original registry
     """
     if self.registry is None and self.account is None:
         return
     fabricio.local(
         'docker pull {image}'.format(image=self.image[tag]),
         quiet=False,
         use_cache=True,
     )
     self.delete_dangling_images()
Esempio n. 9
0
 def prepare(self, tag=None):
     """
     prepare[:tag=None] - prepare Docker image
     """
     fabricio.local(
         'docker build --tag {tag} {build_path}'.format(
             tag=self.image[tag],
             build_path=self.build_path,
         ),
         quiet=False,
         use_cache=True,
     )
Esempio n. 10
0
 def delete_dangling_images():
     if os.name == 'posix':
         # macOS, Linux, etc.
         fabricio.local(
             'for img in $(docker images --filter "dangling=true" --quiet); '
             'do docker rmi "$img"; done'
         )
     elif os.name == 'nt':
         # Windows
         fabricio.local(
             "for /F %i in ('docker images --filter \"dangling=true\" "
             "--quiet') do @docker rmi %i"
         )
Esempio n. 11
0
 def prepare(self, tag=None, no_cache=False):
     """
     prepare Docker image
     """
     options = Options([
         ('tag', str(self.image[tag])),
         ('no-cache', strtobool(no_cache)),
         ('pull', True),
     ])
     fabricio.local(
         'docker build {options} {build_path}'.format(
             build_path=self.build_path,
             options=options,
         ),
         quiet=False,
         use_cache=True,
     )
     self.delete_dangling_images()
Esempio n. 12
0
 def prepare(self, tag=None, no_cache=False):
     """
     build Docker image
     """
     options = utils.Options([
         ('tag', self.image[self.registry:tag:self.account]),
         ('no-cache', utils.strtobool(no_cache)),
         ('pull', True),
     ])
     fabricio.local(
         'docker build {options} {build_path}'.format(
             build_path=self.build_path,
             options=options,
         ),
         quiet=False,
         use_cache=True,
     )
     self.delete_dangling_images()
Esempio n. 13
0
 def push(self, tag=None):
     """
     push downloaded Docker image to the registry
     """
     if self.registry is None and self.account is None:
         return
     tag_with_registry = str(self.image[self.registry:tag:self.account])
     fabricio.local(
         'docker tag {image} {tag}'.format(
             image=self.image[tag],
             tag=tag_with_registry,
         ),
         use_cache=True,
     )
     self.push_image(tag=tag)
     fabricio.local(
         'docker rmi {tag}'.format(tag=tag_with_registry),
         use_cache=True,
     )
Esempio n. 14
0
 def push(self, tag=None):
     """
     push downloaded Docker image to intermediate registry
     """
     if self.registry is None and self.account is None:
         return
     image = self.image[tag]
     if not image:
         return
     proxy_tag = image[self.registry:tag:self.account]
     fabricio.local(
         'docker tag {image} {tag}'.format(
             image=image,
             tag=proxy_tag,
         ),
         use_cache=True,
     )
     self.push_image(tag=tag)
     fabricio.local(
         'docker rmi {tag}'.format(tag=proxy_tag),
         use_cache=True,
     )
Esempio n. 15
0
 def push(self, tag=None):
     """
     push downloaded Docker image to intermediate registry
     """
     if self.registry is None and self.account is None:
         return
     image = self.image[tag]
     if not image:
         return
     proxy_tag = image[self.registry:tag:self.account]
     fabricio.local(
         'docker tag {image} {tag}'.format(
             image=image,
             tag=proxy_tag,
         ),
         use_cache=True,
     )
     self.push_image(tag=tag)
     fabricio.local(
         'docker rmi {tag}'.format(tag=proxy_tag),
         use_cache=True,
     )
Esempio n. 16
0
 def push(self, tag=None):
     """
     push[:tag=None] - push Docker image to registry
     """
     local_tag = str(self.image[self.local_registry:tag])
     fabricio.local(
         'docker tag {image} {tag}'.format(
             image=self.image[tag],
             tag=local_tag,
         ),
         use_cache=True,
     )
     fabricio.local(
         'docker push {tag}'.format(tag=local_tag),
         quiet=False,
         use_cache=True,
     )
     fabricio.local(
         'docker rmi {tag}'.format(tag=local_tag),
         use_cache=True,
     )
Esempio n. 17
0
 def push(self, tag=None):
     """
     push Docker image to registry
     """
     local_tag = str(self.image[self.local_registry:tag])
     fabricio.local(
         'docker tag {image} {tag}'.format(
             image=self.image[tag],
             tag=local_tag,
         ),
         use_cache=True,
     )
     fabricio.local(
         'docker push {tag}'.format(tag=local_tag),
         quiet=False,
         use_cache=True,
     )
     fabricio.local(
         'docker rmi {tag}'.format(tag=local_tag),
         use_cache=True,
     )
Esempio n. 18
0
 def delete_dangling_images():
     fabricio.local(
         'for img in $(docker images --filter "dangling=true" --quiet); '
         'do docker rmi "$img"; done'
     )
Esempio n. 19
0
 def delete_dangling_images():
     fabricio.local(dangling_images_delete_command(), ignore_errors=True)
Esempio n. 20
0
    def test_local(self, local):
        local.__name__ = 'mock'

        try:
            fabricio.local('command', use_cache=True)
        except RuntimeError:
            pass
        try:
            fabricio.local('command', use_cache=True)
        except RuntimeError:
            pass
        local.assert_has_calls([
            mock.call('command'),
            mock.call('command'),
        ])
        self.assertEqual(2, local.call_count)
        local.reset_mock()

        fabricio.local('command', ignore_errors=True)
        fabricio.local('command', ignore_errors=True)
        local.assert_has_calls([
            mock.call('command'),
            mock.call('command'),
        ])
        self.assertEqual(2, local.call_count)
        local.reset_mock()

        fabricio.local('command', ignore_errors=True, use_cache=True)
        fabricio.local('command', ignore_errors=True, use_cache=True)
        local.assert_called_once_with('command')
        local.reset_mock()

        fabricio.local('command1', ignore_errors=True, use_cache=True)
        fabricio.local('command2', ignore_errors=True, use_cache=True)
        local.assert_has_calls([
            mock.call('command1'),
            mock.call('command2'),
        ])
        self.assertEqual(2, local.call_count)