Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
fix(controller): add source release version
Browse files Browse the repository at this point in the history
When rolling back releases, the controller would publish a new
release, which meant that the app image would get a version
bump and a new tag on the registry would be created. However,
the tag that was created on the registry was based off the 'latest'
tag. This allows rollbacks to change the source tag to another
version so that the new tag will be based off the release requested.

fixes #1072
  • Loading branch information
Matthew Fisher committed May 30, 2014
1 parent 66c0da8 commit 0470a38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions controller/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class Meta:
def __str__(self):
return "{0}-v{1}".format(self.app.id, self.version)

def new(self, user, config=None, build=None, summary=None):
def new(self, user, config=None, build=None, summary=None, source_version=None):
"""
Create a new application release using the provided Build and Config
on behalf of a user.
Expand All @@ -465,6 +465,10 @@ def new(self, user, config=None, build=None, summary=None):
config = self.config
if not build:
build = self.build
if not source_version:
source_version = 'latest'
else:
source_version = 'v{}'.format(source_version)
# prepare release tag
new_version = self.version + 1
tag = 'v{}'.format(new_version)
Expand All @@ -475,7 +479,10 @@ def new(self, user, config=None, build=None, summary=None):
build=build, version=new_version, image=image, summary=summary)
# publish release to registry as new docker image
repository_path = self.app.id
publish_release(repository_path, config.values, tag)
publish_release(repository_path,
config.values,
tag,
source_tag=source_version)
return release

def previous(self):
Expand Down
6 changes: 5 additions & 1 deletion controller/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ def rollback(self, request, *args, **kwargs):
summary = "{} rolled back to v{}".format(request.user, version)
prev = app.release_set.get(version=version)
new_release = release.new(
request.user, build=prev.build, config=prev.config, summary=summary)
request.user,
build=prev.build,
config=prev.config,
summary=summary,
source_version=version)
app.deploy(new_release)
msg = "Rolled back to v{}".format(version)
return Response(msg, status=status.HTTP_201_CREATED)
Expand Down
2 changes: 1 addition & 1 deletion controller/registry/mock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

def publish_release(repository_path, config, tag):
def publish_release(repository_path, config, tag, source_tag='latest'):
"""
Publish a new release as a Docker image
Expand Down
17 changes: 12 additions & 5 deletions controller/registry/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@
from django.conf import settings


def publish_release(repository_path, config, tag):
def publish_release(repository_path, config, tag, source_tag='latest'):
"""
Publish a new release as a Docker image
Given a source repository path, a dictionary of environment variables
and a target tag, create a new lightweight Docker image on the registry.
source_tag is the name of the previous older tag that this image should
be a child of. In most cases, this should be 'latest', but for rollbacks
this should be an older tag.
For example, publish_release('gabrtv/myapp', {'ENVVAR': 'values'}, 'v23')
results in a new Docker image at: <registry_url>/gabrtv/myapp:v23
which contains the new configuration as ENV entries.
"""
try:
image_id = _get_tag(repository_path, 'latest')
image_id = _get_tag(repository_path, source_tag)
except RuntimeError:
# no image exists yet, so let's build one!
_put_first_image(repository_path)
image_id = _get_tag(repository_path, 'latest')
if source_tag == 'latest':
# no image exists yet, so let's build one!
_put_first_image(repository_path)
image_id = _get_tag(repository_path, 'latest')
else:
raise
image = _get_image(image_id)
# construct the new image
image['parent'] = image['id']
Expand Down

0 comments on commit 0470a38

Please sign in to comment.