@@ -46,31 +46,22 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
46
46
# Run the command
47
47
subprocess .check_call (command , shell = True )
48
48
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 } " )
51
51
exit (1 ) # stop the build
52
52
53
53
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 } "
65
58
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
74
65
75
66
76
67
def delete_docker_image (image_name , version ):
@@ -84,8 +75,9 @@ def delete_docker_image(image_name, version):
84
75
try :
85
76
subprocess .check_call (command , shell = True )
86
77
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
89
81
90
82
91
83
def build_instances (tags , docker_hub_user , num_jobs ):
@@ -109,20 +101,20 @@ def build_instances(tags, docker_hub_user, num_jobs):
109
101
# delete_docker_image("mintlayer-builder", "latest")
110
102
111
103
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 )
119
111
120
112
121
113
def main ():
122
114
parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
123
115
parser .add_argument ('--push' , action = 'store_true' , help = 'Push the Docker image to Docker Hub' )
124
116
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' )
126
118
parser .add_argument ('--build' , type = lambda x : (str (x ).lower () == 'true' ), default = True , help = "Set to false avoid the build" )
127
119
parser .add_argument ('--version' , help = 'Override version number' , default = None )
128
120
parser .add_argument ('--num_jobs' , help = 'Number of parallel jobs' , default = (os .cpu_count () or 1 ))
@@ -132,16 +124,21 @@ def main():
132
124
version = args .version if args .version else get_cargo_version ("Cargo.toml" )
133
125
# Note: the CI currently takes the version from the release tag, so it always starts with "v",
134
126
# 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" )
136
133
137
- tags = [ version , * args .local_tags ]
134
+ all_tags = args .local_tags + tags_to_push
138
135
139
136
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 )
141
138
142
139
# Only push the image if the --push flag is provided
143
140
if args .push :
144
- push_instances (args .docker_hub_user , version , args . latest )
141
+ push_instances (args .docker_hub_user , tags_to_push )
145
142
146
143
147
144
if __name__ == "__main__" :
0 commit comments