44from django .db import models
55from django .db .models import Q
66from django .contrib .auth import get_user_model
7- from api .utils import dict_diff
87from api .tasks import run_pipeline
98from api .exceptions import DryccException , AlreadyExists
109from scheduler import KubeHTTPException
@@ -61,43 +60,22 @@ def procfile_types(self):
6160 def version_name (self ):
6261 return f'v{ self .version } '
6362
64- def get_run_image (self ):
65- """
66- In the run phase of dryccfile
67- Return the kubernetes "container image" to be sent off to the scheduler.
68- """
69- image = self .build .dryccfile .get ('run' , {}).get (
70- 'image' , self .build .get_image ('run' ))
71- return self .build .get_image (image , default_image = image )
72-
73- def get_run_args (self ):
74- """
75- In the run phase of dryccfile
76- Return the kubernetes "container arguments" to be sent off to the scheduler.
77- """
78- return self .build .dryccfile .get ('run' , {}).get ('args' , [])
79-
80- def get_run_command (self ):
81- """
82- In the run phase of dryccfile
83- Return the kubernetes "container command" to be sent off to the scheduler.
84- """
85- return self .build .dryccfile .get ('run' , {}).get ('command' , [])
86-
87- def get_run_timeout (self ):
88- return int (self .build .dryccfile .get ('run' , {}).get (
89- 'timeout' , settings .DRYCC_PILELINE_RUN_TIMEOUT ))
90-
91- def get_run_trigger (self ):
92- if 'ptypes' not in self .build .dryccfile .get ('run' , {}).get ('when' , {}):
93- return True
94- procfile_types = self .diff_procfile_types ()
95- if procfile_types is None :
96- return True
97- for procfile_type in procfile_types :
98- if procfile_type in self .build .dryccfile ['run' ]['when' ]['ptypes' ]:
99- return True
100- return False
63+ def get_runners (self , procfile_types ):
64+ results = []
65+ procfile_types = self .procfile_types if not procfile_types else procfile_types
66+ for run in self .build .dryccfile .get ('run' , []):
67+ for container_type in procfile_types :
68+ when_ptypes = run .get ('when' , {}).get ('ptypes' , [])
69+ if not when_ptypes or container_type in when_ptypes :
70+ image = run .get ('image' , self .build .get_image (container_type ))
71+ results .append ({
72+ 'image' : self .build .get_image (image , default_image = image ),
73+ 'args' : run .get ('args' , []),
74+ 'command' : run .get ('command' , []),
75+ 'timeout' : run .get ('timeout' , settings .DRYCC_PILELINE_RUN_TIMEOUT ),
76+ })
77+ break
78+ return results
10179
10280 def get_deploy_image (self , container_type ):
10381 """
@@ -133,30 +111,6 @@ def get_deploy_command(self, container_type):
133111 return self .build .dryccfile .get (
134112 'deploy' , {}).get (container_type , {}).get ('command' , [])
135113
136- def diff_procfile_types (self ):
137- """
138- If returning None, it indicates that all procfile_types have changed.
139- """
140- def _get_full_deploy (release ):
141- deploy = {}
142- for procfile_type , value in release .build .dryccfile ['deploy' ].items ():
143- value ['image' ] = release .get_deploy_image (procfile_type )
144- value ['args' ] = release .get_deploy_args (procfile_type )
145- value ['command' ] = release .get_deploy_command (procfile_type )
146- deploy [procfile_type ] = value
147- return deploy
148-
149- pre_release = self .previous ()
150- if (pre_release and pre_release .build and
151- pre_release .build .dryccfile and self .build and self .build .dryccfile ):
152- deploy = _get_full_deploy (self )
153- pre_deploy = _get_full_deploy (pre_release )
154- procfile_types = set ()
155- for value in dict_diff (deploy , pre_deploy ).values ():
156- procfile_types = procfile_types .union (value .keys ())
157- return procfile_types
158- return None
159-
160114 def log (self , message , level = logging .INFO ):
161115 """Logs a message in the context of this application.
162116
@@ -217,7 +171,7 @@ def previous(self):
217171 prev_release = None
218172 return prev_release
219173
220- def rollback (self , user , version = None ):
174+ def rollback (self , user , procfile_types = None , version = None ):
221175 try :
222176 # if no version is provided then grab version from object
223177 version = (self .version - 1 ) if version is None else int (version )
@@ -237,7 +191,7 @@ def rollback(self, user, version=None):
237191 summary = "{} rolled back to v{}" .format (user , version ),
238192 )
239193 if self .build is not None :
240- run_pipeline .delay (new_release , force_deploy = True )
194+ run_pipeline .delay (new_release , procfile_types , force_deploy = True )
241195 return new_release
242196 except Exception as e :
243197 # check if the exception is during create or publish
0 commit comments