Esempio n. 1
0
 def remove(self):
     term.print_step('removing container {!r} ({})...'.format(
         self.name, self.id))
     try:
         self._docker_client.remove_container(self._docker_container_info)
     except docker.errors.APIError as error:
         term.print_error("couldn't remove container {!r} ({})".format(
             self.name, self.id), str(error))
Esempio n. 2
0
 def push(self, registry, allow_insecure=False):
     remote_image_name = '{}/{}'.format(registry, self.name)
     self._docker_client.tag(self.name, remote_image_name)
     term.print_step('pushing image {}...'.format(remote_image_name))
     stream = self._docker_client.push(
         remote_image_name,
         insecure_registry=allow_insecure,
         stream=True)
     consume_stream(stream)
     self._docker_client.remove_image(remote_image_name)
Esempio n. 3
0
 def _display_logs(self, attached, log_queue, term):
     current_container = None, None
     while attached:
         container, line = log_queue.get(timeout=60 * 60)
         if line is END_OF_STREAM:
             attached.remove(container)
             term.print_warning('{}: detached'.format(container))
         else:
             if container != current_container:
                 current_container = container
                 term.print_step(container)
             term.print_line(line.strip())
     term.print_warning('All containers detached')
Esempio n. 4
0
 def start(self, group=None):
     term.print_step('starting container {!r} ({})...'.format(
         self.name, self.id))
     volume_bindings = self._format_volume_bindings(
         self._get_group_modified_dict_attribute(group, 'volume_bindings'))
     self._docker_client.start(
         self._docker_container_info,
         binds=volume_bindings,
         links={
             container.name: alias for container, alias in
             self.dependencies.items()},
         port_bindings=self.port_bindings,
         privileged=self.privileged,
         network_mode=self.net)
Esempio n. 5
0
 def create(self, group=None):
     if self.created:
         term.print_step('{!r} is already created ({})'.format(
             self.name, self.id))
     else:
         term.print_step('creating container {!r}...'.format(self.name))
         environment = self._get_group_modified_dict_attribute(
             group, 'environment')
         environment = self._update_env_from_local_env(environment)
         self._docker_container_info = self._docker_client.create_container(
             self.image.name,
             name=self.name,
             environment=environment,
             ports=list(self.port_bindings.keys()))
         term.print_line('({})'.format(self.id))
Esempio n. 6
0
    def pull(self, registry=None, allow_insecure=False):
        if registry:
            remote_image_name = '{}/{}'.format(registry, self.name)
        else:
            remote_image_name = self.name

        term.print_step('pulling image {}...'.format(remote_image_name))
        stream = self._docker_client.pull(
            remote_image_name,
            insecure_registry=allow_insecure,
            stream=True)
        consume_stream(stream)

        if remote_image_name != self.name:
            self._docker_client.tag(remote_image_name, self.name, force=True)
            self._docker_client.remove_image(remote_image_name)
Esempio n. 7
0
 def status(self):
     if self.created:
         status = self._docker_container_info['Status']
         status_string = '{!r} ({}): {}'.format(
             self.name, self.id, status)
         if status.startswith('Up'):
             term.print_step(status_string)
         else:
             term.print_warning(status_string)
         for port in self._docker_container_info['Ports']:
             if 'IP' in port:
                 term.print_line('{} {} [{}=>{}]'.format(
                     port['Type'],
                     port['IP'],
                     port['PrivatePort'],
                     port['PublicPort']))
             else:
                 term.print_line('{} [{}]'.format(
                     port['Type'],
                     port['PrivatePort']))
     else:
         term.print_step("container {!r} isn't created".format(self.name))
Esempio n. 8
0
 def build(self):
     term.print_step('building image {!r}...'.format(self.name))
     stream = self._docker_client.build(
         self.path, tag=self.name, rm=True, forcerm=True)
     consume_stream(stream)
Esempio n. 9
0
 def stop(self):
     term.print_step('stopping container {!r} ({})...'.format(
         self.name, self.id))
     # timeout must be smaller than our client's socket read timeout:
     self._docker_client.stop(self._docker_container_info, timeout=8)