11import importlib
2- from typing import Any , Generator , Tuple
2+ import os
3+ from typing import Any , Generator , Set
34
45import click
56import docker
67import docker .api .build
78from docker .errors import BuildError
8- from tensorlake .functions_sdk .image import Image
9- from tensorlake .functions_sdk .workflow_module import (
10- WorkflowModuleInfo ,
11- load_workflow_module_info ,
9+ from docker .models .images import Image as DockerImage
10+ from tensorlake .applications import Image
11+ from tensorlake .applications .image import (
12+ ImageInformation ,
13+ dockerfile_content ,
14+ image_infos ,
1215)
16+ from tensorlake .applications .remote .application .ignored_code_paths import (
17+ ignored_code_paths ,
18+ )
19+ from tensorlake .applications .remote .application .loader import load_application
1320
1421
1522@click .command (
16- short_help = "Build images for graphs/workflows defined in the workflow file"
23+ short_help = "Builds images for application defined in <application-source-path> directory or file"
1724)
1825@click .argument (
19- "workflow-file-path" ,
20- type = click .Path (exists = True , file_okay = True , dir_okay = False ),
21- )
22- @click .option (
23- "-i" ,
24- "--image-names" ,
25- multiple = True ,
26- help = "Names of images to build. Can be specified multiple times. If not provided, all images will be built." ,
26+ "application-path" ,
27+ type = click .Path (exists = True , file_okay = True , dir_okay = True ),
2728)
28- def build_image (
29- workflow_file_path : str ,
30- image_names : tuple [str , ...] = None ,
31- ):
32- """
33- Build the images associated to an Indexify workflow
34-
35- A workflow is defined in a Python file, and the images are built using the local Docker daemon.
36- """
29+ def build_images (application_path : str ):
3730 try :
38- workflow_module_info : WorkflowModuleInfo = load_workflow_module_info (
39- workflow_file_path
31+ application_source_dir_or_file_path : str = os .path .abspath (application_path )
32+
33+ ignored_absolute_paths : Set [str ] = ignored_code_paths (
34+ os .path .dirname (application_source_dir_or_file_path )
4035 )
36+
37+ load_application (application_source_dir_or_file_path , ignored_absolute_paths )
4138 except Exception as e :
4239 click .secho (
43- f"Failed loading workflow file , please check the error message: { e } " ,
40+ f"Failed to load the application modules , please check the error message: { e } " ,
4441 fg = "red" ,
4542 )
4643 raise click .Abort
@@ -49,39 +46,28 @@ def build_image(
4946 docker_client .ping ()
5047
5148 indexify_version : str = importlib .metadata .version ("indexify" )
52- for image in workflow_module_info . images . keys ():
49+ for image , image_info in image_infos (). items ():
5350 image : Image
54- if len (image_names ) > 0 and image .image_name not in image_names :
55- click .echo (
56- f"Skipping image `{ image .image_name } ` as it is not in the provided image names."
57- )
58- continue
59-
60- click .echo (f"Building image `{ image .image_name } `" )
61-
51+ image_info : ImageInformation
52+ click .echo (f"Building image `{ image .name } :{ image .tag } `" )
6253 image .run (f"pip install 'indexify=={ indexify_version } '" )
63- built_image , logs_generator = _build ( image = image , docker_client = docker_client )
54+
6455 try :
6556 built_image , logs_generator = _build (
6657 image = image , docker_client = docker_client
6758 )
59+ built_image : DockerImage
6860 _print_build_log (logs_generator )
69- click .secho (f"built image: { built_image .tags [0 ]} " , fg = "green" )
61+ click .secho (f"Built image: { built_image .tags [0 ]} " , fg = "green" )
7062 except BuildError as e :
7163 raise click .Abort () from e
7264
73- click .secho (f"built image: { built_image .tags [0 ]} " , fg = "green" )
74-
7565
7666def _build (
7767 image : Image , docker_client : docker .DockerClient
78- ) -> Tuple [docker .models .images .Image , Generator [str , Any , None ]]:
79- docker_file = image .dockerfile ()
80- image_name = (
81- image .image_name
82- if ":" in image .image_name
83- else f"{ image .image_name } :{ image .image_tag } "
84- )
68+ ) -> tuple [DockerImage , Generator [str , Any , None ]]:
69+ docker_file_content : str = dockerfile_content (image )
70+ image_name = image .name if ":" in image .name else f"{ image .name } :{ image .tag } "
8571
8672 docker .api .build .process_dockerfile = lambda dockerfile , path : (
8773 "Dockerfile" ,
@@ -91,7 +77,7 @@ def _build(
9177 try :
9278 built_image , logs_generator = docker_client .images .build (
9379 path = "." ,
94- dockerfile = docker_file ,
80+ dockerfile = docker_file_content ,
9581 tag = image_name ,
9682 rm = True ,
9783 # pull=True, # optional: ensures fresh base images
0 commit comments