@@ -39,7 +39,7 @@ def create_buildx_builder_if_not_exists():
3939 subprocess .run (["docker" , "buildx" , "use" , builder_name ], check = True )
4040
4141
42- def build_and_push_image_with_docker_buildx (args , image_name , srcdir , dockerfile_path ):
42+ def build_and_push_image_with_docker_buildx (args , service_name , srcdir , dockerfile_path ):
4343 platforms = "linux/amd64,linux/arm64"
4444 build_cmd = [
4545 "docker" ,
@@ -50,9 +50,12 @@ def build_and_push_image_with_docker_buildx(args, image_name, srcdir, dockerfile
5050 ]
5151 if args .docker_build_output_type == "registry" :
5252 build_cmd .append ("--platform=" + platforms )
53+ image_name = utils .get_full_image_name (args , service_name )
54+ build_cmd .extend (["-t" , image_name ])
55+ for tag in args .extra_image_tags : # additional image tags
56+ extra_tag = utils .get_full_image_name (args , service_name , tag = tag )
57+ build_cmd .extend (["-t" , extra_tag ])
5358 build_cmd .extend ([
54- "-t" ,
55- image_name ,
5659 "-f" ,
5760 dockerfile_path ,
5861 "." ,
@@ -61,7 +64,8 @@ def build_and_push_image_with_docker_buildx(args, image_name, srcdir, dockerfile
6164 print (f"pushed image { image_name } " )
6265
6366
64- def load_kind_image (cluster_name , image_name , srcdir ):
67+ def load_kind_image (cluster_name , service_name , srcdir ):
68+ image_name = utils .get_full_image_name (args , service_name )
6569 build_cmd = [
6670 "kind" ,
6771 "load" ,
@@ -74,10 +78,10 @@ def load_kind_image(cluster_name, image_name, srcdir):
7478 print (f"loaded image { image_name } into kind cluster { args .kind_cluster_name } " )
7579
7680
77- def build_and_push_image (args , image_name , srcdir , dockerfile_path ):
78- build_and_push_image_with_docker_buildx (args , image_name , srcdir , dockerfile_path )
81+ def build_and_push_image (args , service_name , srcdir , dockerfile_path ):
82+ build_and_push_image_with_docker_buildx (args , service_name , srcdir , dockerfile_path )
7983 if args .kind_cluster_name :
80- load_kind_image (args .kind_cluster_name , image_name , srcdir )
84+ load_kind_image (args .kind_cluster_name , service_name , srcdir )
8185
8286
8387def push_image_for_go_mod (args , mod_dir ):
@@ -95,18 +99,17 @@ def push_image_for_go_mod(args, mod_dir):
9599 dockerfile_path = os .path .join (root , filename )
96100 service_name = os .path .basename (root )
97101
98- image_name = utils .get_full_image_name (args , service_name )
99-
100102 print (f"create Docker buildx builder for { service_name } " )
101103 create_buildx_builder_if_not_exists ()
102- print (f"building image for { service_name } with tag { image_name } " )
103- build_and_push_image (args , image_name , mod_dir , dockerfile_path )
104+ print (f"building image for { service_name } " )
105+ build_and_push_image (args , service_name , mod_dir , dockerfile_path )
104106
105107
106108def main (args ):
107109 """Builds and pushes docker images."""
108110 golang .for_each_module (lambda mod_dir : push_image_for_go_mod (args , mod_dir ))
109111
112+
110113if __name__ == "__main__" :
111114 # parse arguments and call
112115 parser = argparse .ArgumentParser (description = "Build and push Docker images" )
@@ -115,6 +118,12 @@ if __name__ == "__main__":
115118 help = "Prefix for the image name. requires slash at the end if a path" ,
116119 type = str ,
117120 default = os .getenv ("IMAGE_PREFIX" ))
121+ parser .add_argument ("--extra-image-tag" ,
122+ dest = "extra_image_tags" ,
123+ help = "Additional tags to use when publishing images." ,
124+ type = str ,
125+ action = "append" ,
126+ default = [])
118127 parser .add_argument ("--kind-cluster-name" ,
119128 dest = "kind_cluster_name" ,
120129 help = "Name of the kind cluster. If set, images will be loaded into the cluster" ,
0 commit comments