@@ -474,51 +474,31 @@ def new(self, user, config=None, build=None, summary=None):
474474 config = self .config
475475 if not build :
476476 build = self .build
477+ # construct fully-qualified build image
478+ if build .sha :
479+ source_image = '{}:{}' .format (build .image , build .sha )
480+ else :
481+ source_image = '{}:{}' .format (build .image , 'latest' )
477482 # construct fully-qualified target image
478483 new_version = self .version + 1
479484 tag = 'v{}' .format (new_version )
485+ release_image = '{}:{}' .format (self .app .id , tag )
480486 target_image = '{}:{}/{}' .format (
481487 settings .REGISTRY_HOST , settings .REGISTRY_PORT , self .app .id )
482488 # create new release and auto-increment version
483489 release = Release .objects .create (
484490 owner = user , app = self .app , config = config ,
485491 build = build , version = new_version , image = target_image , summary = summary )
486- # publish release to registry as new docker image
487- if build .sha :
488- publish_release (build .image ,
489- build .sha ,
490- config .values ,
491- self .app .id ,
492- tag )
493- else :
492+ # IOW, this image did not come from the builder
493+ if not build .sha :
494494 # we assume that the image is not present on our registry,
495495 # so shell out a task to pull in the repository
496- url = urlparse (build .image )
497- repository_name = url .path [1 :]
498- if url .hostname and url .port :
499- tasks .import_repository .delay (
500- '{}://{}:{}' .format (url .scheme , url .hostname , url .port ),
501- repository_name ,
502- self .app .id ,
503- ).get ()
504- elif url .hostname :
505- tasks .import_repository .delay (
506- '{}://{}' .format (url .scheme , url .hostname ),
507- repository_name ,
508- self .app .id ,
509- ).get ()
510- else :
511- # assume only the repository path is given, which means that
512- # it's on the public index
513- tasks .import_repository .delay (settings .PUBLIC_INDEX_URL ,
514- build .image ,
515- self .app .id ,
516- ).get ()
517- publish_release (self .app .id ,
518- 'latest' ,
519- config .values ,
520- self .app .id ,
521- tag )
496+ tasks .import_repository .delay (build .image , self .app .id ).get ()
497+ # update the source image to the repository we just imported
498+ source_image = '{}:{}' .format (self .app .id , 'latest' )
499+ publish_release (source_image ,
500+ config .values ,
501+ release_image ,)
522502 return release
523503
524504 def previous (self ):
0 commit comments