@@ -253,6 +253,7 @@ def create_operator(file_path: str,
253253 platform = 'linux/amd64' ,
254254 dockerfile = 'Dockerfile.generated' ,
255255 image_version = 'python3.12' ,
256+ skip_docker_build = False ,
256257 ):
257258 logging .info ('Parameters: ' )
258259 logging .info ('file_path: ' + file_path )
@@ -375,60 +376,61 @@ def create_operator(file_path: str,
375376 local_mode = True
376377 repository = 'local'
377378
378- if subprocess .run ('docker buildx' , shell = True , stdout = subprocess .PIPE ).returncode == 0 :
379- # Using docker buildx
380- logging .debug ('Using docker buildx' )
381- build_command = f'docker buildx build -f { dockerfile } '
382- else :
383- logging .debug ('Using docker build. Consider installing docker-buildx.' )
384- build_command = f'docker build -f { dockerfile } '
385-
386- logging .info (f'Building container image claimed-{ name } :{ version } ' )
387- try :
388- # Run docker build
389- subprocess .run (
390- f"{ build_command } --platform { platform } -t claimed-{ name } :{ version } . { '--no-cache' if no_cache else '' } " ,
391- stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True
392- )
393- if repository is not None :
394- # Run docker tag
395- logging .debug (f'Tagging images with "latest" and "{ version } "' )
396- subprocess .run (
397- f"docker tag claimed-{ name } :{ version } { repository } /claimed-{ name } :{ version } " ,
398- stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
399- )
400- subprocess .run (
401- f"docker tag claimed-{ name } :{ version } { repository } /claimed-{ name } :latest" ,
402- stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
403- )
404- except Exception as err :
405- logging .error ('Docker build failed. Consider running C3 with `--log_level DEBUG` to see the docker build logs.' )
406- if not keep_generated_files :
407- remove_temporary_files (file_path , target_code )
408- raise err
409- logging .info (f'Successfully built image claimed-{ name } :{ version } ' )
410-
411- if local_mode :
412- logging .info (f'No repository provided, skip docker push.' )
413- else :
414- logging .info (f'Pushing images to registry { repository } ' )
379+ if not skip_docker_build :
380+ if subprocess .run ('docker buildx' , shell = True , stdout = subprocess .PIPE ).returncode == 0 :
381+ # Using docker buildx
382+ logging .debug ('Using docker buildx' )
383+ build_command = f'docker buildx build -f { dockerfile } '
384+ else :
385+ logging .debug ('Using docker build. Consider installing docker-buildx.' )
386+ build_command = f'docker build -f { dockerfile } '
387+
388+ logging .info (f'Building container image claimed-{ name } :{ version } ' )
415389 try :
416- # Run docker push
417- subprocess .run (
418- f"docker push { repository } /claimed-{ name } :latest" ,
419- stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
420- )
390+ # Run docker build
421391 subprocess .run (
422- f"docker push { repository } / claimed-{ name } :{ version } " ,
423- stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
392+ f"{ build_command } --platform { platform } -t claimed-{ name } :{ version } . { '--no-cache' if no_cache else '' } " ,
393+ stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True
424394 )
425- logging .info ('Successfully pushed image to registry' )
395+ if repository is not None :
396+ # Run docker tag
397+ logging .debug (f'Tagging images with "latest" and "{ version } "' )
398+ subprocess .run (
399+ f"docker tag claimed-{ name } :{ version } { repository } /claimed-{ name } :{ version } " ,
400+ stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
401+ )
402+ subprocess .run (
403+ f"docker tag claimed-{ name } :{ version } { repository } /claimed-{ name } :latest" ,
404+ stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
405+ )
426406 except Exception as err :
427- logging .error (f'Could not push images to namespace { repository } . '
428- f'Please check if docker is logged in or select a namespace with access.' )
407+ logging .error ('Docker build failed. Consider running C3 with `--log_level DEBUG` to see the docker build logs.' )
429408 if not keep_generated_files :
430409 remove_temporary_files (file_path , target_code )
431410 raise err
411+ logging .info (f'Successfully built image claimed-{ name } :{ version } ' )
412+
413+ if local_mode :
414+ logging .info (f'No repository provided, skip docker push.' )
415+ else :
416+ logging .info (f'Pushing images to registry { repository } ' )
417+ try :
418+ # Run docker push
419+ subprocess .run (
420+ f"docker push { repository } /claimed-{ name } :latest" ,
421+ stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
422+ )
423+ subprocess .run (
424+ f"docker push { repository } /claimed-{ name } :{ version } " ,
425+ stdout = None if log_level == 'DEBUG' else subprocess .PIPE , check = True , shell = True ,
426+ )
427+ logging .info ('Successfully pushed image to registry' )
428+ except Exception as err :
429+ logging .error (f'Could not push images to namespace { repository } . '
430+ f'Please check if docker is logged in or select a namespace with access.' )
431+ if not keep_generated_files :
432+ remove_temporary_files (file_path , target_code )
433+ raise err
432434
433435 # Check for existing files and optionally modify them before overwriting
434436 try :
@@ -482,6 +484,8 @@ def main():
482484 help = 'Select image platform, default is linux/amd64. Alternativly, select linux/arm64".' )
483485 parser .add_argument ('--image_version' , type = str , default = 'python3.12' ,
484486 help = 'Select python or R version (defaults to python3.12).' )
487+ parser .add_argument ('--skip-docker-build' , action = 'store_true' ,
488+ help = 'Enable skipping docker build (default: False).' )
485489
486490 args = parser .parse_args ()
487491
@@ -518,6 +522,7 @@ def main():
518522 platform = args .platform ,
519523 dockerfile = args .dockerfile ,
520524 image_version = args .image_version ,
525+ skip_docker_build = args .skip_docker_build ,
521526 )
522527
523528
0 commit comments