@@ -598,6 +598,7 @@ def _start_service_container(self, name, service: Service):
598598 )
599599 self ._service_runners [name ] = service_runner
600600 cont_name = self .step_runner .id + "-" + name
601+ systemd = self .is_systemd (service , _image )
601602 service_container_id = service_runner .start (
602603 name = cont_name ,
603604 volumes = _volumes ,
@@ -614,7 +615,8 @@ def _start_service_container(self, name, service: Service):
614615 extra_hosts = _extra_hosts ,
615616 working_dir = _cwd ,
616617 containers = _containers ,
617- systemd = self .is_systemd (service , _image , service_logger ),
618+ systemd = systemd ,
619+ systemd_v248 = self .is_systemd_v248 (systemd , service , _image ),
618620 )
619621 self ._service_links [cont_name ] = name
620622
@@ -1022,8 +1024,9 @@ def run(self, context: dict): # pylint: disable=too-many-statements,too-many-br
10221024 log = self .step_runner .log ,
10231025 )
10241026 # Figure out if we should be running systemd. Has to happen after docker pull
1025- container_args ["systemd" ] = self .is_systemd (
1026- self .step , _run_image , self .step_runner .log
1027+ container_args ["systemd" ] = self .is_systemd (self .step , _run_image )
1028+ container_args ["systemd_v248" ] = self .is_systemd_v248 (
1029+ container_args ["systemd" ], self .step , _run_image
10271030 )
10281031
10291032 container_id = self .runner .start (
@@ -1143,22 +1146,34 @@ def cleanup(self, context): # pylint: disable=unused-argument
11431146 for image in self .images_to_remove :
11441147 python_on_whales .docker .image .remove (image , force = True )
11451148
1146- def is_systemd (self , run_service : RunAndServicesBase , image , logger ):
1147- """Check if an image runs systemd"""
1148- # Unused argument
1149- _ = logger
1149+ def _get_label_is_truthy (self , image , label_name : str ) -> bool :
1150+ labels = (
1151+ self ._docker_client .inspect_image (image ).get ("Config" , {}).get ("Labels" , {})
1152+ )
1153+ if not labels or label_name not in labels :
1154+ return False
1155+ # Labels will be set as the string value. Make sure we handle '0' and 'False'
1156+ value = labels .get (label_name , False )
1157+ return bool (value and value != "0" and value != "False" )
11501158
1151- rval = False
1152- if run_service .systemd :
1153- rval = run_service .systemd
1154- else :
1155- labels = (
1156- self ._docker_client .inspect_image (image )
1157- .get ("Config" , {})
1158- .get ("Labels" , {})
1159- )
1160- if labels and "BUILDRUNNER_SYSTEMD" in labels :
1161- rval = labels .get ("BUILDRUNNER_SYSTEMD" , False )
1159+ def is_systemd (self , run_service : RunAndServicesBase , image : str ) -> bool :
1160+ """
1161+ Check if an image runs systemd
1162+ """
1163+ if run_service .systemd is not None :
1164+ return run_service .systemd
1165+ return self ._get_label_is_truthy (image , "BUILDRUNNER_SYSTEMD" )
11621166
1163- # Labels will be set as the string value. Make sure we handle '0' and 'False'
1164- return bool (rval and rval != "0" and rval != "False" )
1167+ def is_systemd_v248 (
1168+ self , systemd : bool , run_service : RunAndServicesBase , image : str
1169+ ) -> bool :
1170+ """
1171+ Check if an image needs the changes for systemd v248+
1172+ """
1173+ if not systemd :
1174+ # Do not run any other checks if we are not using systemd at all
1175+ return False
1176+
1177+ if run_service .systemd_v248 is not None :
1178+ return run_service .systemd_v248
1179+ return self ._get_label_is_truthy (image , "BUILDRUNNER_SYSTEMD_V248" )
0 commit comments