@@ -462,7 +462,7 @@ class Meta:
462462 def __str__ (self ):
463463 return "{0}-v{1}" .format (self .app .id , self .version )
464464
465- def new (self , user , config = None , build = None , summary = None , source_version = None ):
465+ def new (self , user , config = None , build = None , summary = None , source_version = 'latest' ):
466466 """
467467 Create a new application release using the provided Build and Config
468468 on behalf of a user.
@@ -473,24 +473,28 @@ def new(self, user, config=None, build=None, summary=None, source_version=None):
473473 config = self .config
474474 if not build :
475475 build = self .build
476- if not source_version :
477- source_version = 'latest'
478- else :
479- source_version = 'v{}' .format (source_version )
480- # prepare release tag
476+ # always create a release off the latest image
477+ source_image = '{}:{}' .format (build .image , source_version )
478+ # construct fully-qualified target image
481479 new_version = self .version + 1
482480 tag = 'v{}' .format (new_version )
483- image = build .image + ':{tag}' .format (** locals ())
481+ release_image = '{}:{}' .format (self .app .id , tag )
482+ target_image = '{}:{}/{}' .format (
483+ settings .REGISTRY_HOST , settings .REGISTRY_PORT , self .app .id )
484484 # create new release and auto-increment version
485485 release = Release .objects .create (
486486 owner = user , app = self .app , config = config ,
487- build = build , version = new_version , image = image , summary = summary )
488- # publish release to registry as new docker image
489- repository_path = self .app .id
490- publish_release (repository_path ,
487+ build = build , version = new_version , image = target_image , summary = summary )
488+ # IOW, this image did not come from the builder
489+ if not build .sha :
490+ # we assume that the image is not present on our registry,
491+ # so shell out a task to pull in the repository
492+ tasks .import_repository .delay (build .image , self .app .id ).get ()
493+ # update the source image to the repository we just imported
494+ source_image = self .app .id
495+ publish_release (source_image ,
491496 config .values ,
492- tag ,
493- source_tag = source_version )
497+ release_image ,)
494498 return release
495499
496500 def previous (self ):
@@ -516,7 +520,9 @@ def save(self, *args, **kwargs):
516520 # compare this build to the previous build
517521 old_build = prev_release .build if prev_release else None
518522 # if the build changed, log it and who pushed it
519- if self .build != old_build :
523+ if self .version == 1 :
524+ self .summary += "{} created initial release" .format (self .app .owner )
525+ elif self .build != old_build :
520526 if self .build .sha :
521527 self .summary += "{} deployed {}" .format (self .build .owner , self .build .sha [:7 ])
522528 else :
0 commit comments