@@ -34,6 +34,9 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
3434 if num_jobs :
3535 command += f" --build-arg NUM_JOBS={ num_jobs } "
3636
37+ # Force the amd64 platform in case we're building on an arm-based one.
38+ command += " --platform linux/amd64"
39+
3740 # Note: "plain" output is more verbose, but it makes it easier to understand what went wrong
3841 # when a problem occurs.
3942 command += " --progress=plain"
@@ -43,31 +46,22 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
4346 # Run the command
4447 subprocess .check_call (command , shell = True )
4548 print (f"Built { image_name } successfully (the tags are: { full_tags } )." )
46- except Exception as error :
47- print (f"Error occurred : { error } " )
49+ except subprocess . CalledProcessError as error :
50+ print (f"Failed to build { image_name } : { error } " )
4851 exit (1 ) # stop the build
4952
5053
51- def push_docker_image (image_name , version , latest = False ):
52- # Docker tag command
53- full_image_name = f"{ image_name } :{ version } "
54- if latest :
55- latest_image_name = f"{ image_name } :latest"
56- tag_command = f"docker tag { full_image_name } { latest_image_name } "
57- subprocess .check_call (tag_command , shell = True )
58-
59- # Docker push command
60- push_command = f"docker push { full_image_name } "
61- subprocess .check_call (push_command , shell = True )
62-
63- # if latest flag is true, push the image with 'latest' tag
64- if latest :
65- push_command_latest = f"docker push { latest_image_name } "
66- subprocess .check_call (push_command_latest , 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 } "
6758
68- print (f"Pushed { full_image_name } successfully." )
69- if latest :
70- 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
7165
7266
7367def delete_docker_image (image_name , version ):
@@ -81,8 +75,9 @@ def delete_docker_image(image_name, version):
8175 try :
8276 subprocess .check_call (command , shell = True )
8377 print (f"Deleted { full_image_name } successfully." )
84- except subprocess .CalledProcessError :
85- 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
8681
8782
8883def build_instances (tags , docker_hub_user , num_jobs ):
@@ -106,35 +101,44 @@ def build_instances(tags, docker_hub_user, num_jobs):
106101# delete_docker_image("mintlayer-builder", "latest")
107102
108103
109- def push_instances (docker_hub_user , version , latest ):
110- push_docker_image (f"{ docker_hub_user } /node-daemon" , version , latest )
111- push_docker_image (f"{ docker_hub_user } /api-blockchain-scanner-daemon" , version , latest )
112- push_docker_image (f"{ docker_hub_user } /api-web-server" , version , latest )
113- push_docker_image (f"{ docker_hub_user } /wallet-cli" , version , latest )
114- push_docker_image (f"{ docker_hub_user } /wallet-rpc-daemon" , version , latest )
115- 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 )
116111
117112
118113def main ():
119114 parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
120115 parser .add_argument ('--push' , action = 'store_true' , help = 'Push the Docker image to Docker Hub' )
121116 parser .add_argument ('--docker-hub-user' , help = 'Docker Hub username' , default = 'mintlayer' )
122- 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' )
123118 parser .add_argument ('--build' , type = lambda x : (str (x ).lower () == 'true' ), default = True , help = "Set to false avoid the build" )
124119 parser .add_argument ('--version' , help = 'Override version number' , default = None )
125120 parser .add_argument ('--num_jobs' , help = 'Number of parallel jobs' , default = (os .cpu_count () or 1 ))
126121 parser .add_argument ('--local_tags' , nargs = '*' , help = 'Additional tags to apply (these won\' t be pushed)' , default = [])
127122 args = parser .parse_args ()
128123
129124 version = args .version if args .version else get_cargo_version ("Cargo.toml" )
130- tags = [version , * args .local_tags ]
125+ # Note: the CI currently takes the version from the release tag, so it always starts with "v",
126+ # but the version from Cargo.toml doesn't have this prefix.
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" )
133+
134+ all_tags = args .local_tags + tags_to_push
131135
132136 if args .build :
133- build_instances (tags , args .docker_hub_user , args .num_jobs )
137+ build_instances (all_tags , args .docker_hub_user , args .num_jobs )
134138
135139 # Only push the image if the --push flag is provided
136140 if args .push :
137- push_instances (args .docker_hub_user , version , args . latest )
141+ push_instances (args .docker_hub_user , tags_to_push )
138142
139143
140144if __name__ == "__main__" :
0 commit comments