@@ -34,6 +34,9 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
34
34
if num_jobs :
35
35
command += f" --build-arg NUM_JOBS={ num_jobs } "
36
36
37
+ # Force the amd64 platform in case we're building on an arm-based one.
38
+ command += " --platform linux/amd64"
39
+
37
40
# Note: "plain" output is more verbose, but it makes it easier to understand what went wrong
38
41
# when a problem occurs.
39
42
command += " --progress=plain"
@@ -43,31 +46,22 @@ def build_docker_image(dockerfile_path, image_name, tags, num_jobs=None):
43
46
# Run the command
44
47
subprocess .check_call (command , shell = True )
45
48
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 } " )
48
51
exit (1 ) # stop the build
49
52
50
53
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 } "
67
58
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
71
65
72
66
73
67
def delete_docker_image (image_name , version ):
@@ -81,8 +75,9 @@ def delete_docker_image(image_name, version):
81
75
try :
82
76
subprocess .check_call (command , shell = True )
83
77
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
86
81
87
82
88
83
def build_instances (tags , docker_hub_user , num_jobs ):
@@ -106,35 +101,44 @@ def build_instances(tags, docker_hub_user, num_jobs):
106
101
# delete_docker_image("mintlayer-builder", "latest")
107
102
108
103
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 )
116
111
117
112
118
113
def main ():
119
114
parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
120
115
parser .add_argument ('--push' , action = 'store_true' , help = 'Push the Docker image to Docker Hub' )
121
116
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' )
123
118
parser .add_argument ('--build' , type = lambda x : (str (x ).lower () == 'true' ), default = True , help = "Set to false avoid the build" )
124
119
parser .add_argument ('--version' , help = 'Override version number' , default = None )
125
120
parser .add_argument ('--num_jobs' , help = 'Number of parallel jobs' , default = (os .cpu_count () or 1 ))
126
121
parser .add_argument ('--local_tags' , nargs = '*' , help = 'Additional tags to apply (these won\' t be pushed)' , default = [])
127
122
args = parser .parse_args ()
128
123
129
124
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
131
135
132
136
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 )
134
138
135
139
# Only push the image if the --push flag is provided
136
140
if args .push :
137
- push_instances (args .docker_hub_user , version , args . latest )
141
+ push_instances (args .docker_hub_user , tags_to_push )
138
142
139
143
140
144
if __name__ == "__main__" :
0 commit comments