Skip to content

Commit df32775

Browse files
author
Matthew Fisher
committed
fix #542
This will try to retrieve the 'latest' tag. If that fails, we will attempt to create a 'v0' layer that acts as an empty placeholder for metadata. The initial config will still result as `v2` on the registry.
1 parent 5c2a849 commit df32775

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

api/docker.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,45 @@ def publish_release(repository_path, config, tag):
2020
results in a new Docker image at: <registry_url>/gabrtv/myapp:v23
2121
which contains the new configuration as ENV entries.
2222
"""
23-
image_id = _get_tag(repository_path, 'latest')
23+
try:
24+
image_id = _get_tag(repository_path, 'latest')
25+
except RuntimeError:
26+
# no image exists yet, so let's build one!
27+
_put_first_image(repository_path)
28+
image_id = _get_tag(repository_path, 'latest')
2429
image = _get_image(image_id)
2530
# construct the new image
2631
image['parent'] = image['id']
2732
image['id'] = _new_id()
2833
image['config']['Env'] = _construct_env(image['config']['Env'], config)
2934
# update and tag the new image
30-
_put_image(image)
31-
cookies = _put_layer(image['id'], _empty_tar_archive())
32-
_put_checksum(image, cookies)
33-
_put_tag(image['id'], repository_path, tag)
35+
_commit(repository_path, image, _empty_tar_archive(), tag)
3436

3537

3638
# registry access
3739

3840

41+
def _commit(repository_path, image, layer, tag):
42+
_put_image(image)
43+
cookies = _put_layer(image['id'], layer)
44+
_put_checksum(image, cookies)
45+
_put_tag(image['id'], repository_path, tag)
46+
# point latest to the new tag
47+
_put_tag(image['id'], repository_path, 'latest')
48+
49+
50+
def _put_first_image(repository_path):
51+
image = {
52+
'id': _new_id(),
53+
'parent': '',
54+
'config': {
55+
'Env': []
56+
}
57+
}
58+
# tag as v0 in the registry
59+
_commit(repository_path, image, _empty_tar_archive(), 'v0')
60+
61+
3962
def _get_tag(repository, tag):
4063
path = "/v1/repositories/{repository}/tags/{tag}".format(**locals())
4164
url = urlparse.urljoin(settings.REGISTRY_URL, path)

0 commit comments

Comments
 (0)