Skip to content

Commit 7d54229

Browse files
author
Matthew Fisher
committed
Merge pull request #1076 from deis/1072-rollback
fix(controller): add source release version
2 parents 0a28d99 + 0470a38 commit 7d54229

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

controller/api/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ class Meta:
454454
def __str__(self):
455455
return "{0}-v{1}".format(self.app.id, self.version)
456456

457-
def new(self, user, config=None, build=None, summary=None):
457+
def new(self, user, config=None, build=None, summary=None, source_version=None):
458458
"""
459459
Create a new application release using the provided Build and Config
460460
on behalf of a user.
@@ -465,6 +465,10 @@ def new(self, user, config=None, build=None, summary=None):
465465
config = self.config
466466
if not build:
467467
build = self.build
468+
if not source_version:
469+
source_version = 'latest'
470+
else:
471+
source_version = 'v{}'.format(source_version)
468472
# prepare release tag
469473
new_version = self.version + 1
470474
tag = 'v{}'.format(new_version)
@@ -475,7 +479,10 @@ def new(self, user, config=None, build=None, summary=None):
475479
build=build, version=new_version, image=image, summary=summary)
476480
# publish release to registry as new docker image
477481
repository_path = self.app.id
478-
publish_release(repository_path, config.values, tag)
482+
publish_release(repository_path,
483+
config.values,
484+
tag,
485+
source_tag=source_version)
479486
return release
480487

481488
def previous(self):

controller/api/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ def rollback(self, request, *args, **kwargs):
424424
summary = "{} rolled back to v{}".format(request.user, version)
425425
prev = app.release_set.get(version=version)
426426
new_release = release.new(
427-
request.user, build=prev.build, config=prev.config, summary=summary)
427+
request.user,
428+
build=prev.build,
429+
config=prev.config,
430+
summary=summary,
431+
source_version=version)
428432
app.deploy(new_release)
429433
msg = "Rolled back to v{}".format(version)
430434
return Response(msg, status=status.HTTP_201_CREATED)

controller/registry/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
def publish_release(repository_path, config, tag):
2+
def publish_release(repository_path, config, tag, source_tag='latest'):
33
"""
44
Publish a new release as a Docker image
55

controller/registry/private.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@
99
from django.conf import settings
1010

1111

12-
def publish_release(repository_path, config, tag):
12+
def publish_release(repository_path, config, tag, source_tag='latest'):
1313
"""
1414
Publish a new release as a Docker image
1515
1616
Given a source repository path, a dictionary of environment variables
1717
and a target tag, create a new lightweight Docker image on the registry.
1818
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+
1923
For example, publish_release('gabrtv/myapp', {'ENVVAR': 'values'}, 'v23')
2024
results in a new Docker image at: <registry_url>/gabrtv/myapp:v23
2125
which contains the new configuration as ENV entries.
2226
"""
2327
try:
24-
image_id = _get_tag(repository_path, 'latest')
28+
image_id = _get_tag(repository_path, source_tag)
2529
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
2936
image = _get_image(image_id)
3037
# construct the new image
3138
image['parent'] = image['id']

0 commit comments

Comments
 (0)