Exemple #1
0
 def make_container_options(
         cls,
         temporary=None,
         name=None,
         options=(),
 ):
     return utils.Options(
         options,
         name=name,
         rm=temporary,
         tty=temporary,
         interactive=temporary,
         detach=temporary is not None and not temporary,
     )
Exemple #2
0
    def build(self,
              local=False,
              build_path='.',
              options=None,
              use_cache=False):
        if local:
            run = fabricio.local
            run_capture_output = partial(run, capture=True)
        else:
            run = run_capture_output = fabricio.run
        run = partial(run, use_cache=use_cache)
        run_capture_output = partial(run_capture_output, use_cache=use_cache)
        run_ignore_errors = partial(run, ignore_errors=True)

        image = six.text_type(self)
        options = options or utils.Options()
        options['tag'] = image

        # default options
        options.setdefault('pull', 1)
        options.setdefault('force-rm', 1)

        with utils.patch(fabricio, 'run', run_capture_output):
            try:
                old_parent_id = self.info['Parent']
            except ImageNotFoundError:
                old_parent_id = ''

        run_ignore_errors('docker tag {image} {tag} '
                          '&& docker rmi {image}'.format(image=image,
                                                         tag=self.temp_tag))
        run(
            'docker build {options} {build_path}'.format(
                options=options,
                build_path=build_path,
            ),
            quiet=False,
        )
        run_ignore_errors('docker rmi {tag} {old_parent}'.format(
            tag=self.temp_tag,
            old_parent=old_parent_id,
        ))