|
9 | 9 | from django.conf import settings |
10 | 10 |
|
11 | 11 |
|
12 | | -def publish_release(repository_path, config, tag): |
| 12 | +def publish_release(repository_path, config, tag, source_tag='latest'): |
13 | 13 | """ |
14 | 14 | Publish a new release as a Docker image |
15 | 15 |
|
16 | 16 | Given a source repository path, a dictionary of environment variables |
17 | 17 | and a target tag, create a new lightweight Docker image on the registry. |
18 | 18 |
|
| 19 | + source_tag is the name of the previous older tag that this image should |
| 20 | + be a child of. In most cases, this should be 'latest', but for rollbacks |
| 21 | + this should be an older tag. |
| 22 | +
|
19 | 23 | For example, publish_release('gabrtv/myapp', {'ENVVAR': 'values'}, 'v23') |
20 | 24 | results in a new Docker image at: <registry_url>/gabrtv/myapp:v23 |
21 | 25 | which contains the new configuration as ENV entries. |
22 | 26 | """ |
23 | 27 | try: |
24 | | - image_id = _get_tag(repository_path, 'latest') |
| 28 | + image_id = _get_tag(repository_path, source_tag) |
25 | 29 | 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') |
| 30 | + if source_tag == 'latest': |
| 31 | + # no image exists yet, so let's build one! |
| 32 | + _put_first_image(repository_path) |
| 33 | + image_id = _get_tag(repository_path, 'latest') |
| 34 | + else: |
| 35 | + raise |
29 | 36 | image = _get_image(image_id) |
30 | 37 | # construct the new image |
31 | 38 | image['parent'] = image['id'] |
|
0 commit comments