33from django .conf import settings
44from django .db import models
55
6- from registry import publish_release , get_port as docker_get_port , RegistryException # noqa
76from api .utils import dict_diff
87from api .models import UuidAuditedModel
98from api .exceptions import DryccException , AlreadyExists
@@ -66,7 +65,7 @@ def image(self):
6665 return '{}/{}:git-{}' .format (settings .REGISTRY_URL , self .app .id , str (self .build .sha ))
6766 elif self .build .type == 'image' :
6867 # Drycc Pull, docker image in local registry
69- return '{}/{}:v{}' . format ( settings . REGISTRY_URL , self .app . id , str ( self . version ))
68+ return self .build . image
7069 elif self .build .type == 'buildpack' :
7170 # Build Pack - Registry URL not prepended since slugrunner image will download slug
7271 return self .build .image
@@ -81,69 +80,18 @@ def new(self, user, config, build, summary=None, source_version='latest'):
8180 # construct fully-qualified target image
8281 new_version = self .app .release_set .latest ().version + 1
8382 # create new release and auto-increment version
84- release = Release .objects .create (
83+ return Release .objects .create (
8584 owner = user , app = self .app , config = config ,
8685 build = build , version = new_version , summary = summary
8786 )
8887
89- try :
90- release .publish ()
91- except DryccException as e :
92- # If we cannot publish this app, just log and carry on
93- self .app .log (e )
94- pass
95- except RegistryException as e :
96- self .app .log (e )
97- raise DryccException (str (e )) from e
98-
99- return release
100-
101- def publish (self ):
102- if self .build is None :
103- raise DryccException ('No build associated with this release to publish' )
104-
105- # If the build has a SHA, assume it's from drycc-builder and in the drycc-registry already
106- if self .build .source_based :
107- return
108-
109- # Builder pushes to internal registry, exclude SHA based images from being returned early
110- registry = self .config .registry
111- if (
112- registry .get ('username' , None ) and
113- registry .get ('password' , None ) and
114- # SHA means it came from a git push (builder)
115- not self .build .sha and
116- # hostname tells Builder where to push images
117- not registry .get ('hostname' , None )
118- ) or (settings .REGISTRY_LOCATION != 'on-cluster' ):
119- self .app .log ('{} exists in the target registry. Using image for release {} of app {}' .format (self .build .image , self .version , self .app )) # noqa
120- return
121-
122- # return image if it is already in the registry, test host and then host + port
123- if (
124- self .build .image .startswith (settings .REGISTRY_HOST ) or
125- self .build .image .startswith (settings .REGISTRY_URL )
126- ):
127- self .app .log ('{} exists in the target registry. Using image for release {} of app {}' .format (self .build .image , self .version , self .app )) # noqa
128- return
129-
130- # add tag if it was not provided
131- source_image = self .build .image
132- if ':' not in source_image :
133- source_image = "{}:{}" .format (source_image , self .build .version )
134-
135- # if build is source based then it was pushed into the drycc registry
136- drycc_registry = bool (self .build .source_based )
137- publish_release (source_image , self .image , drycc_registry , self .get_registry_auth ())
138-
13988 def get_port (self ):
14089 """
14190 Get application port for a given release. If pulling from private registry
14291 then use default port or read from ENV var, otherwise attempt to pull from
14392 the docker image
14493 """
14594 try :
146- drycc_registry = bool (self .build .source_based )
14795 envs = self .config .values
14896 creds = self .get_registry_auth ()
14997
@@ -165,17 +113,8 @@ def get_port(self):
165113 return int (envs .get ('PORT' ))
166114
167115 # If the user provides PORT
168- if envs .get ('PORT' , None ):
169- return int (envs .get ('PORT' ))
170-
171- # discover port from docker image
172- port = docker_get_port (self .image , drycc_registry , creds )
173- if port is None and self .app .appsettings_set .latest ().routable :
174- msg = "Expose a port or make the app non routable by changing the process type"
175- self .app .log (msg , logging .ERROR )
176- raise DryccException (msg )
116+ return int (envs .get ('PORT' , 5000 ))
177117
178- return port
179118 except Exception as e :
180119 raise DryccException (str (e )) from e
181120
0 commit comments