Example #1
0
    def pull(self, repository, tag=None, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        if repo_name.count(":") == 1:
            repository, tag = repository.rsplit(":", 1)

        params = {
            'tag': tag,
            'fromImage': repository
        }
        headers = {}

        if utils.compare_version('1.5', self._version) >= 0:
            if getattr(self, '_cfg', None) is None:
                self._cfg = auth.load_config()
            authcfg = auth.resolve_authconfig(self._cfg, registry)
            # do not fail if no atuhentication exists
            # for this specific registry as we can have a readonly pull
            if authcfg:
                headers['X-Registry-Auth'] = auth.encode_header(authcfg)
        u = self._url("/images/create")
        response = self._post(u, params=params, headers=headers, stream=stream,
                              timeout=None)

        if stream:
            return self._stream_helper(response)
        else:
            return self._result(response)
Example #2
0
    def pull(self, repository, tag=None, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        if repo_name.count(":") == 1:
            repository, tag = repository.rsplit(":", 1)

        params = {'tag': tag, 'fromImage': repository}
        headers = {}

        if utils.compare_version('1.5', self._version) >= 0:
            if getattr(self, '_cfg', None) is None:
                self._cfg = auth.load_config()
            authcfg = auth.resolve_authconfig(self._cfg, registry)
            # do not fail if no atuhentication exists
            # for this specific registry as we can have a readonly pull
            if authcfg:
                headers['X-Registry-Auth'] = auth.encode_header(authcfg)
        u = self._url("/images/create")
        response = self._post(u,
                              params=params,
                              headers=headers,
                              stream=stream,
                              timeout=None)

        if stream:
            return self._stream_helper(response)
        else:
            return self._result(response)
Example #3
0
def use_host_config(client):
    """
    Checks whether the client should pass the HostConfig options when creating containers, or use the older behavior
    of passing the keyword arguments to the start method of the client.

    :param client: Client object.
    :type client: docker.client.Client
    :return: ``True`` if the newer behavior should be used.
    :rtype: bool
    """
    return compare_version('1.15', client.api_version) >= 0
Example #4
0
def use_host_config(client):
    """
    Checks whether the client should pass the HostConfig options when creating containers, or use the older behavior
    of passing the keyword arguments to the start method of the client.

    :param client: Client object.
    :type client: docker.client.Client
    :return: ``True`` if the newer behavior should be used.
    :rtype: bool
    """
    return compare_version('1.15', client.api_version) >= 0
Example #5
0
 def push(self, repository):
     registry, repo_name = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if getattr(self, '_cfg', None) is None:
         self._cfg = auth.load_config()
     authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         return self._result(self._post_json(u, None, headers=headers))
     return self._result(self._post_json(u, authcfg))
Example #6
0
 def push(self, repository):
     registry, repo_name = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if getattr(self, '_cfg', None) is None:
         self._cfg = auth.load_config()
     authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         return self._result(self._post_json(u, None, headers=headers))
     return self._result(self._post_json(u, authcfg))
Example #7
0
    def logs(self, container, stdout=True, stderr=True, stream=False):
        if isinstance(container, dict):
            container = container.get("Id")
        params = {"logs": 1, "stdout": stdout and 1 or 0, "stderr": stderr and 1 or 0, "stream": stream and 1 or 0}
        u = self._url("/containers/{0}/attach".format(container))
        response = self._post(u, params=params, stream=stream)

        # Stream multi-plexing was introduced in API v1.6.
        if utils.compare_version("1.6", self._version) < 0:
            return stream and self._stream_result(response) or self._result(response, binary=True)

        return (
            stream
            and self._multiplexed_socket_stream_helper(response)
            or "".join([x for x in self._multiplexed_buffer_helper(response)])
        )
Example #8
0
 def tag(self):
     template_kwargs = template_args.tag_template_args()
     for push_mode, repo, tag_template in self.pushes:
         need_push = self.need_push(push_mode)
         try:
             tag_name = tag_template.format(**template_kwargs)
             kwargs = {}
             if docker_utils.compare_version('1.22',
                                             self.docker._version) < 0:
                 kwargs['force'] = True
             self.docker.tag(self.final_image, repo, tag_name, **kwargs)
             self._update_progress("tag added: %s:%s" % (repo, tag_name))
         except KeyError as e:
             if need_push:
                 LOG.warn('invalid tag_template for this build: %s',
                          e.message)
 def tag(self):
     template_kwargs = template_args.tag_template_args()
     for push_mode, repo, tag_template in self.pushes:
         need_push = self.need_push(push_mode)
         try:
             tag_name = tag_template.format(**template_kwargs)
             kwargs = {}
             if docker_utils.compare_version('1.22',
                                             self.docker._version) < 0:
                 kwargs['force'] = True
             self.docker.tag(self.final_image, repo, tag_name, **kwargs)
             self._update_progress("tag added: %s:%s" % (repo, tag_name))
         except KeyError as e:
             if need_push:
                 LOG.warn('invalid tag_template for this build: %s',
                          e.message)
Example #10
0
 def push(self, repository, authcfg=None):
     registry, _ = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if authcfg is None:
         if getattr(self, '_cfg', None) is None:
             self._cfg = auth.load_config()
         authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         response = self._post_json(u, None, headers=headers,
                                    stream=True)
     else:
         response = self._post_json(u, authcfg, stream=True)
     response.raise_for_status()
     return response.iter_content(1)
Example #11
0
    def logs(self, container, stdout=True, stderr=True, stream=False):
        if isinstance(container, dict):
            container = container.get('Id')
        params = {
            'logs': 1,
            'stdout': stdout and 1 or 0,
            'stderr': stderr and 1 or 0,
            'stream': stream and 1 or 0,
        }
        u = self._url("/containers/{0}/attach".format(container))
        response = self._post(u, params=params, stream=stream)

        # Stream multi-plexing was introduced in API v1.6.
        if utils.compare_version('1.6', self._version) < 0:
            return stream and self._stream_result(response) or \
                self._result(response, binary=True)

        return stream and self._multiplexed_socket_stream_helper(response) or \
            ''.join([x for x in self._multiplexed_buffer_helper(response)])
Example #12
0
    def logs(self, container, stdout=True, stderr=True, stream=False):
        if isinstance(container, dict):
            container = container.get('Id')
        params = {
            'logs': 1,
            'stdout': stdout and 1 or 0,
            'stderr': stderr and 1 or 0,
            'stream': stream and 1 or 0,
        }
        u = self._url("/containers/{0}/attach".format(container))
        response = self._post(u, params=params, stream=stream)

        # Stream multi-plexing was introduced in API v1.6.
        if utils.compare_version('1.6', self._version) < 0:
            return stream and self._stream_result(response) or \
                self._result(response, binary=True)

        return stream and self._multiplexed_socket_stream_helper(response) or \
            ''.join([x for x in self._multiplexed_buffer_helper(response)])
Example #13
0
 def logs(self, container):
     if isinstance(container, dict):
         container = container.get('Id')
     params = {'logs': 1, 'stdout': 1, 'stderr': 1}
     u = self._url("/containers/{0}/attach".format(container))
     if utils.compare_version('1.6', self._version) < 0:
         return self._result(self._post(u, params=params))
     res = ''
     response = self._result(self._post(u, params=params))
     walker = 0
     while walker < len(response):
         header = response[walker:walker + 8]
         walker += 8
         # we don't care about the type of stream since we want both
         # stdout and stderr
         length = struct.unpack(">L", header[4:].encode())[0]
         res += response[walker:walker + length]
         walker += length
     return res
Example #14
0
    def push(self, repository, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        u = self._url("/images/{0}/push".format(repository))
        headers = {}
        if getattr(self, "_cfg", None) is None:
            self._cfg = auth.load_config()
        authcfg = auth.resolve_authconfig(self._cfg, registry)
        if utils.compare_version("1.5", self._version) >= 0:
            # do not fail if no atuhentication exists
            # for this specific registry as we can have an anon push
            if authcfg:
                headers["X-Registry-Auth"] = auth.encode_header(authcfg)

            if stream:
                return self._stream_helper(self._post_json(u, None, headers=headers, stream=True))
            else:
                return self._result(self._post_json(u, None, headers=headers, stream=False))
        if stream:
            return self._stream_helper(self._post_json(u, authcfg, stream=True))
        else:
            return self._result(self._post_json(u, authcfg, stream=False))
Example #15
0
 def logs(self, container):
     if isinstance(container, dict):
         container = container.get('Id')
     params = {
         'logs': 1,
         'stdout': 1,
         'stderr': 1
     }
     u = self._url("/containers/{0}/attach".format(container))
     if utils.compare_version('1.6', self._version) < 0:
         return self._result(self._post(u, params=params))
     res = ''
     response = self._result(self._post(u, params=params))
     walker = 0
     while walker < len(response):
         header = response[walker:walker+8]
         walker += 8
         # we don't care about the type of stream since we want both
         # stdout and stderr
         length = struct.unpack(">L", header[4:].encode())[0]
         res += response[walker:walker+length]
         walker += length
     return res
Example #16
0
def newer_than(version):
    client = docker_client()
    ver = client.version()['ApiVersion']
    return compare_version(version, ver) >= 0
Example #17
0
 def rev_cmp(a, b):
     return -1 * compare_version(a, b)
Example #18
0
def newer_than(version):
    client = docker_client()
    ver = client.version()['ApiVersion']
    return compare_version(version, ver) >= 0
Example #19
0
 def rev_cmp(a, b):
     return -1 * compare_version(a, b)