Kaydet (Commit) 5800c4ab authored tarafından Cameron Maske's avatar Cameron Maske

Allow pushing a single tag.

Closes #282
üst 710f3725
......@@ -201,7 +201,7 @@ c.pull(repository, tag=None, stream=False)
Identical to the `docker pull` command.
```python
c.push(repository, stream=False)
c.push(repository, tag=None, stream=False)
```
Identical to the `docker push` command.
......
......@@ -747,9 +747,14 @@ class Client(requests.Session):
else:
return self._result(response)
def push(self, repository, stream=False):
def push(self, repository, tag=None, stream=False):
if not tag:
repository, tag = utils.parse_repository_tag(repository)
registry, repo_name = auth.resolve_repository_name(repository)
u = self._url("/images/{0}/push".format(repository))
params = {
'tag': tag
}
headers = {}
if utils.compare_version('1.5', self._version) >= 0:
......@@ -765,9 +770,10 @@ class Client(requests.Session):
if authcfg:
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
response = self._post_json(u, None, headers=headers, stream=stream)
response = self._post_json(u, None, headers=headers,
stream=stream, params=params)
else:
response = self._post_json(u, None, stream=stream)
response = self._post_json(u, None, stream=stream, params=params)
return stream and self._stream_helper(response) \
or self._result(response)
......
......@@ -1306,6 +1306,28 @@ class DockerClientTest(Cleanup, unittest.TestCase):
fake_request.assert_called_with(
url_prefix + 'images/test_image/push',
params={
'tag': None
},
data='{}',
headers={'Content-Type': 'application/json'},
stream=False,
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
)
def test_push_image_with_tag(self):
try:
with mock.patch('docker.auth.auth.resolve_authconfig',
fake_resolve_authconfig):
self.client.push(fake_api.FAKE_IMAGE_NAME, tag=fake_api.FAKE_TAG_NAME)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with(
url_prefix + 'images/test_image/push',
params={
'tag': fake_api.FAKE_TAG_NAME,
},
data='{}',
headers={'Content-Type': 'application/json'},
stream=False,
......@@ -1322,6 +1344,9 @@ class DockerClientTest(Cleanup, unittest.TestCase):
fake_request.assert_called_with(
url_prefix + 'images/test_image/push',
params={
'tag': None
},
data='{}',
headers={'Content-Type': 'application/json'},
stream=True,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment