@@ -46,31 +46,22 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
4646 # Run the command
4747 subprocess .check_call (command , shell = True )
4848 print (f"Built { image_name } successfully (the tags are: { full_tags } )." )
49- except Exception as error :
50- print (f"Error occurred : { error } " )
49+ except subprocess . CalledProcessError as error :
50+ print (f"Failed to build { image_name } : { error } " )
5151 exit (1 ) # stop the build
5252
5353
54- def push_docker_image (image_name , version , latest = False ):
55- # Docker tag command
56- full_image_name = f"{ image_name } :{ version } "
57- if latest :
58- latest_image_name = f"{ image_name } :latest"
59- tag_command = f"docker tag { full_image_name } { latest_image_name } "
60- subprocess .check_call (tag_command , shell = True )
61-
62- # Docker push command
63- push_command = f"docker push { full_image_name } "
64- subprocess .check_call (push_command , shell = True )
54+ def push_docker_image (image_name , tags ):
55+ for tag in tags :
56+ full_image_name = f"{ image_name } :{ tag } "
57+ push_command = f"docker push { full_image_name } "
6558
66- # if latest flag is true, push the image with 'latest' tag
67- if latest :
68- push_command_latest = f"docker push { latest_image_name } "
69- subprocess .check_call (push_command_latest , shell = True )
70-
71- print (f"Pushed { full_image_name } successfully." )
72- if latest :
73- print (f"Pushed { latest_image_name } successfully." )
59+ try :
60+ subprocess .check_call (push_command , shell = True )
61+ print (f"Pushed { full_image_name } successfully." )
62+ except subprocess .CalledProcessError as error :
63+ print (f"Failed to push { full_image_name } : { error } " )
64+ exit (1 ) # stop the build
7465
7566
7667def delete_docker_image (image_name , version ):
@@ -84,8 +75,9 @@ def delete_docker_image(image_name, version):
8475 try :
8576 subprocess .check_call (command , shell = True )
8677 print (f"Deleted { full_image_name } successfully." )
87- except subprocess .CalledProcessError :
88- print (f"Failed to delete { full_image_name } ." )
78+ except subprocess .CalledProcessError as error :
79+ print (f"Failed to delete { full_image_name } : { error } " )
80+ # No need to fail the build here
8981
9082
9183def build_instances (tags , docker_hub_user , num_jobs ):
@@ -109,20 +101,20 @@ def build_instances(tags, docker_hub_user, num_jobs):
109101# delete_docker_image("mintlayer-builder", "latest")
110102
111103
112- def push_instances (docker_hub_user , version , latest ):
113- push_docker_image (f"{ docker_hub_user } /node-daemon" , version , latest )
114- push_docker_image (f"{ docker_hub_user } /api-blockchain-scanner-daemon" , version , latest )
115- push_docker_image (f"{ docker_hub_user } /api-web-server" , version , latest )
116- push_docker_image (f"{ docker_hub_user } /wallet-cli" , version , latest )
117- push_docker_image (f"{ docker_hub_user } /wallet-rpc-daemon" , version , latest )
118- push_docker_image (f"{ docker_hub_user } /dns-server" , version , latest )
104+ def push_instances (docker_hub_user , tags ):
105+ push_docker_image (f"{ docker_hub_user } /node-daemon" , tags )
106+ push_docker_image (f"{ docker_hub_user } /api-blockchain-scanner-daemon" , tags )
107+ push_docker_image (f"{ docker_hub_user } /api-web-server" , tags )
108+ push_docker_image (f"{ docker_hub_user } /wallet-cli" , tags )
109+ push_docker_image (f"{ docker_hub_user } /wallet-rpc-daemon" , tags )
110+ push_docker_image (f"{ docker_hub_user } /dns-server" , tags )
119111
120112
121113def main ():
122114 parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
123115 parser .add_argument ('--push' , action = 'store_true' , help = 'Push the Docker image to Docker Hub' )
124116 parser .add_argument ('--docker-hub-user' , help = 'Docker Hub username' , default = 'mintlayer' )
125- parser .add_argument ('--latest' , action = 'store_true' , help = 'Tag the Docker image as latest while pushing ' )
117+ parser .add_argument ('--latest' , action = 'store_true' , help = 'Tag the Docker image as latest' )
126118 parser .add_argument ('--build' , type = lambda x : (str (x ).lower () == 'true' ), default = True , help = "Set to false avoid the build" )
127119 parser .add_argument ('--version' , help = 'Override version number' , default = None )
128120 parser .add_argument ('--num_jobs' , help = 'Number of parallel jobs' , default = (os .cpu_count () or 1 ))
@@ -132,16 +124,21 @@ def main():
132124 version = args .version if args .version else get_cargo_version ("Cargo.toml" )
133125 # Note: the CI currently takes the version from the release tag, so it always starts with "v",
134126 # but the version from Cargo.toml doesn't have this prefix.
135- version = version if version .startswith ('v' ) else f"v{ version } "
127+ version = version .removeprefix ("v" )
128+
129+ # We want to push both "X.Y.Z" and "vX.Y.Z".
130+ tags_to_push = [version , f"v{ version } " ]
131+ if args .latest :
132+ tags_to_push .append ("latest" )
136133
137- tags = [ version , * args .local_tags ]
134+ all_tags = args .local_tags + tags_to_push
138135
139136 if args .build :
140- build_instances (tags , args .docker_hub_user , args .num_jobs )
137+ build_instances (all_tags , args .docker_hub_user , args .num_jobs )
141138
142139 # Only push the image if the --push flag is provided
143140 if args .push :
144- push_instances (args .docker_hub_user , version , args . latest )
141+ push_instances (args .docker_hub_user , tags_to_push )
145142
146143
147144if __name__ == "__main__" :
0 commit comments