Skip to content

Commit c76fd8d

Browse files
committed
Merge branch 'cameronmaske-push-tags'
2 parents 710f372 + 9999cb0 commit c76fd8d

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ c.pull(repository, tag=None, stream=False)
201201
Identical to the `docker pull` command.
202202

203203
```python
204-
c.push(repository, stream=False)
204+
c.push(repository, tag=None, stream=False)
205205
```
206206

207207
Identical to the `docker push` command.

docker/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,14 @@ def pull(self, repository, tag=None, stream=False):
747747
else:
748748
return self._result(response)
749749

750-
def push(self, repository, stream=False):
750+
def push(self, repository, tag=None, stream=False):
751+
if not tag:
752+
repository, tag = utils.parse_repository_tag(repository)
751753
registry, repo_name = auth.resolve_repository_name(repository)
752754
u = self._url("/images/{0}/push".format(repository))
755+
params = {
756+
'tag': tag
757+
}
753758
headers = {}
754759

755760
if utils.compare_version('1.5', self._version) >= 0:
@@ -765,9 +770,10 @@ def push(self, repository, stream=False):
765770
if authcfg:
766771
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
767772

768-
response = self._post_json(u, None, headers=headers, stream=stream)
773+
response = self._post_json(u, None, headers=headers,
774+
stream=stream, params=params)
769775
else:
770-
response = self._post_json(u, None, stream=stream)
776+
response = self._post_json(u, None, stream=stream, params=params)
771777

772778
return stream and self._stream_helper(response) \
773779
or self._result(response)

tests/test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,30 @@ def test_push_image(self):
13061306

13071307
fake_request.assert_called_with(
13081308
url_prefix + 'images/test_image/push',
1309+
params={
1310+
'tag': None
1311+
},
1312+
data='{}',
1313+
headers={'Content-Type': 'application/json'},
1314+
stream=False,
1315+
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
1316+
)
1317+
1318+
def test_push_image_with_tag(self):
1319+
try:
1320+
with mock.patch('docker.auth.auth.resolve_authconfig',
1321+
fake_resolve_authconfig):
1322+
self.client.push(
1323+
fake_api.FAKE_IMAGE_NAME, tag=fake_api.FAKE_TAG_NAME
1324+
)
1325+
except Exception as e:
1326+
self.fail('Command should not raise exception: {0}'.format(e))
1327+
1328+
fake_request.assert_called_with(
1329+
url_prefix + 'images/test_image/push',
1330+
params={
1331+
'tag': fake_api.FAKE_TAG_NAME,
1332+
},
13091333
data='{}',
13101334
headers={'Content-Type': 'application/json'},
13111335
stream=False,
@@ -1322,6 +1346,9 @@ def test_push_image_stream(self):
13221346

13231347
fake_request.assert_called_with(
13241348
url_prefix + 'images/test_image/push',
1349+
params={
1350+
'tag': None
1351+
},
13251352
data='{}',
13261353
headers={'Content-Type': 'application/json'},
13271354
stream=True,

0 commit comments

Comments
 (0)