@@ -175,6 +175,8 @@ def _fetch_github_access_token(application):
175175 or application .github_app_installation_id
176176 ):
177177 try :
178+ if github_app .app_id is None :
179+ raise BuildError ("GitHub App ID not configured" )
178180 auth = GithubAppAuth (github_app .app_id , github_app .app_private_key_pem )
179181 gi = GithubIntegration (auth = auth )
180182 access_token = gi .get_access_token (
@@ -271,16 +273,16 @@ def file_path(filename):
271273 os .chdir (tempdir )
272274 try :
273275 dockerfile_object .content = dockerfile_body
276+ dockerfile_env_vars = list (dockerfile_object .envs .keys ())
274277 finally :
275278 os .chdir (previous_dir )
276- dockerfile_env_vars = list (dockerfile_object .envs .keys ())
277279 try :
278280 processes = procfile .loads (procfile_body )
279281 except ValueError as exc :
280282 raise BuildError (f"error parsing Procfile: { exc } " )
281283
282284 for process_name , process_def in processes .items ():
283- if re .search ("\s" , process_name ) is not None :
285+ if re .search (r "\s" , process_name ) is not None :
284286 raise BuildError (
285287 f'Invalid process name: "{ process_name } " in Procfile, '
286288 "may not contain whitespace."
@@ -613,9 +615,7 @@ def build_release_buildkit(release):
613615 "done\n "
614616 f'buildctl --addr={ sock_addr } "$@"\n '
615617 )
616- os .chmod (
617- wrapper , 0o755
618- ) # nosec B103 — wrapper script must be executable
618+ os .chmod (wrapper , 0o755 ) # nosec B103 — wrapper script must be executable
619619 buildctl_command = [wrapper ]
620620
621621 try :
@@ -669,6 +669,10 @@ def _fetch_github_file(
669669 g = Github (access_token )
670670 try :
671671 content_file = g .get_repo (github_repository ).get_contents (filename , ref = ref )
672+ if isinstance (content_file , list ):
673+ raise BuildError (
674+ f"Expected a file but got a directory listing for { filename } "
675+ )
672676 if content_file .encoding == "base64" :
673677 return b64decode (content_file .content ).decode ()
674678 return content_file .content
@@ -773,7 +777,7 @@ def fetch_image_build_cache_volume_claim(core_api_instance, buildable):
773777 return volume_claim
774778
775779
776- def build_image_buildkit (image = None ):
780+ def build_image_buildkit (image : Image ):
777781 bke = BuildkitEnv (image .repository_name )
778782 registry = bke .registry
779783 buildkit_image = bke .buildkit_image
@@ -1096,9 +1100,7 @@ def build_image_buildkit(image=None):
10961100 "done\n "
10971101 f'buildctl --addr={ sock_addr } "$@"\n '
10981102 )
1099- os .chmod (
1100- wrapper , 0o755
1101- ) # nosec B103 — wrapper script must be executable
1103+ os .chmod (wrapper , 0o755 ) # nosec B103 — wrapper script must be executable
11021104 buildctl_command = [wrapper ]
11031105
11041106 try :
@@ -1577,7 +1579,7 @@ def build_omnibus_buildkit(image, release):
15771579
15781580
15791581@shared_task ()
1580- def run_image_build (image_id = None , buildkit = False ):
1582+ def run_image_build (image_id : str , buildkit : bool = False ):
15811583 from cabotage .utils .config_templates import TemplateResolutionError
15821584
15831585 current_app .config ["REGISTRY_AUTH_SECRET" ]
@@ -1733,7 +1735,7 @@ def run_image_build(image_id=None, buildkit=False):
17331735 "user_id" : "automation" ,
17341736 "deployment_id" : image .image_metadata .get ("id" , None ),
17351737 "description" : image .image_metadata .get ("description" , None ),
1736- "timestamp" : datetime .datetime .utcnow ( ).isoformat (),
1738+ "timestamp" : datetime .datetime .now ( datetime . timezone . utc ).isoformat (),
17371739 },
17381740 )
17391741 db .session .add (activity )
@@ -1749,7 +1751,7 @@ def run_image_build(image_id=None, buildkit=False):
17491751
17501752
17511753@shared_task ()
1752- def run_release_build (release_id = None ):
1754+ def run_release_build (release_id : str ):
17531755 from cabotage .utils .config_templates import TemplateResolutionError
17541756
17551757 release = None
@@ -1897,7 +1899,9 @@ def run_release_build(release_id=None):
18971899 "user_id" : "automation" ,
18981900 "deployment_id" : release .release_metadata .get ("id" , None ),
18991901 "description" : release .release_metadata .get ("description" , None ),
1900- "timestamp" : datetime .datetime .utcnow ().isoformat (),
1902+ "timestamp" : datetime .datetime .now (
1903+ datetime .timezone .utc
1904+ ).isoformat (),
19011905 },
19021906 )
19031907 db .session .add (activity )
@@ -1932,7 +1936,7 @@ def run_release_build(release_id=None):
19321936
19331937
19341938@shared_task ()
1935- def run_omnibus_build (image_id = None ):
1939+ def run_omnibus_build (image_id : str ):
19361940 """Build image + release in a single K8s Job for auto-deploys.
19371941
19381942 Avoids mounting the build cache volume twice by combining both build
@@ -2028,7 +2032,9 @@ def run_omnibus_build(image_id=None):
20282032 "user_id" : "automation" ,
20292033 "deployment_id" : image .image_metadata .get ("id" , None ),
20302034 "description" : image .image_metadata .get ("description" , None ),
2031- "timestamp" : datetime .datetime .utcnow ().isoformat (),
2035+ "timestamp" : datetime .datetime .now (
2036+ datetime .timezone .utc
2037+ ).isoformat (),
20322038 },
20332039 )
20342040 db .session .add (activity )
@@ -2140,7 +2146,7 @@ def run_omnibus_build(image_id=None):
21402146 "user_id" : "automation" ,
21412147 "deployment_id" : image .image_metadata .get ("id" , None ),
21422148 "description" : image .image_metadata .get ("description" , None ),
2143- "timestamp" : datetime .datetime .utcnow ( ).isoformat (),
2149+ "timestamp" : datetime .datetime .now ( datetime . timezone . utc ).isoformat (),
21442150 },
21452151 )
21462152 db .session .add (activity )
0 commit comments