@@ -83,7 +83,9 @@ def build_and_push_image(args, service_name, srcdir, dockerfile_path):
8383 if args .kind_cluster_name :
8484 load_kind_image (args .kind_cluster_name , service_name , srcdir )
8585
86-
86+ # This only builds and pushes images in directories with
87+ # 1) go.mod file
88+ # 2) images/*/Dockerfile
8789def push_image_for_go_mod (args , mod_dir ):
8890 """Builds and pushes docker images."""
8991 images_dir = os .path .join (mod_dir , "images" )
@@ -105,10 +107,37 @@ def push_image_for_go_mod(args, mod_dir):
105107 build_and_push_image (args , service_name , mod_dir , dockerfile_path )
106108
107109
110+ # This only builds and pushes images in examples/*/Dockerfile
111+ def push_images_for_examples (args ):
112+ """Builds and pushes docker images for examples."""
113+ repo_root = os .path .dirname (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
114+ examples_dir = os .path .join (repo_root , "examples" )
115+ if not os .path .isdir (examples_dir ):
116+ return
117+
118+ for example in os .listdir (examples_dir ):
119+ example_dir = os .path .join (examples_dir , example )
120+ if not os .path .isdir (example_dir ):
121+ continue
122+
123+ dockerfile_path = os .path .join (example_dir , "Dockerfile" )
124+ if not os .path .isfile (dockerfile_path ):
125+ continue
126+
127+ service_name = example .replace ("-" , "_" )
128+
129+ print (f"create Docker buildx builder for { service_name } " )
130+ create_buildx_builder_if_not_exists ()
131+ print (f"building image for { service_name } " )
132+ build_and_push_image (args , service_name , example_dir , "Dockerfile" )
133+
134+
108135def main (args ):
109136 """Builds and pushes docker images."""
110137 golang .for_each_module (lambda mod_dir : push_image_for_go_mod (args , mod_dir ))
111-
138+ push_images_for_examples (args )
139+ # TODO: Handle image building and pushing logic better
140+
112141
113142if __name__ == "__main__" :
114143 # parse arguments and call
0 commit comments