@@ -138,26 +138,29 @@ def repo(self) -> Optional[str]:
138
138
return repo
139
139
140
140
def _run_command (self , cmd ):
141
+ on_travis = "TRAVIS_BRANCH" in os .environ
142
+ if on_travis :
143
+ self ._run_command_on_travis (cmd )
144
+ return
145
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
146
+ exit_code = os .system (cmd )
147
+ if exit_code != 0 :
148
+ raise RuntimeError ("Failed to build (exit_code=%s)" % exit_code )
149
+
150
+ def _run_command_on_travis (self , cmd ):
141
151
self ._logger .info (cmd )
142
152
143
153
stop = threading .Event ()
144
154
145
155
def f ():
146
156
nonlocal stop
147
157
counter = 0
148
- on_travis = "TRAVIS_BRANCH" in os . environ
158
+
149
159
while not stop .is_set ():
150
160
counter = counter + 1
161
+ print ("Still building... ({})" .format (counter ), flush = True )
162
+ stop .wait (10 )
151
163
152
- if on_travis :
153
- print ("Still building... ({})" .format (counter ), flush = True )
154
- stop .wait (10 )
155
- continue
156
-
157
- print ("." , end = "" , flush = True )
158
- stop .wait (1 )
159
- if not on_travis :
160
- print ()
161
164
threading .Thread (target = f ).start ()
162
165
try :
163
166
output = execute (cmd )
@@ -183,8 +186,14 @@ def _buildx_build(self, args: List[str], build_dir: str, build_tag: str, platfor
183
186
self ._run_command (cmd )
184
187
185
188
def build (self , platform : Platform , no_cache : bool ) -> None :
186
- self ._logger .info ("Build %s:%s (%s)" , self .name , self .tag , platform .tag_suffix )
187
- print ("Build %s:%s (%s)" % (self .name , self .tag , platform .tag_suffix ))
189
+ self ._logger .info ("Building %s:%s (%s)" , self .name , self .tag , platform .tag_suffix )
190
+
191
+ print ()
192
+ print ("=" * 80 )
193
+ print ("Building %s:%s (%s)" % (self .name , self .tag , platform .tag_suffix ))
194
+ print ("=" * 80 )
195
+
196
+ sys .stdout .flush ()
188
197
189
198
source_manager = self .prepare ()
190
199
@@ -257,18 +266,25 @@ def push(self, platform: Platform, no_cache: bool = False, dirty_push: bool = Fa
257
266
258
267
tag = self .get_build_tag (self .branch , platform )
259
268
260
- print ("Push {}" .format (tag ))
269
+ print ()
270
+ print ("=" * 80 )
271
+ print ("Pushing {}" .format (tag ))
272
+ print ("=" * 80 )
273
+
274
+ sys .stdout .flush ()
261
275
262
276
cmd = "docker push {}" .format (tag )
277
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
263
278
output = execute (cmd )
264
- self . _logger . debug ( "$ %s \n %s" , cmd , output )
279
+ print ( "%s" % output . rstrip (), flush = True )
265
280
last_line = output .splitlines ()[- 1 ]
266
281
p = re .compile (r"^(.*): digest: (.*) size: (\d+)$" )
267
282
m = p .match (last_line )
268
283
assert m
269
284
assert m .group (1 ) in tag
270
285
271
286
new_manifest = "{}/{}@{}" .format (self .group , self .name , m .group (2 ))
287
+ print ("New manifest: %s" % new_manifest , flush = True )
272
288
273
289
# append to manifest list
274
290
os .environ ["DOCKER_CLI_EXPERIMENTAL" ] = "enabled"
@@ -284,22 +300,28 @@ def push(self, platform: Platform, no_cache: bool = False, dirty_push: bool = Fa
284
300
tags .append ("{}@{}" .format (repo , m .digest ))
285
301
tags = " " .join (tags )
286
302
cmd = f"docker manifest create { t0 } { new_manifest } "
303
+
287
304
if len (tags ) > 0 :
288
305
cmd += " " + tags
289
- output = execute (cmd )
290
- self ._logger .debug ("$ %s\n %s" , cmd , output )
306
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
307
+ if os .system (cmd ) != 0 :
308
+ raise Exception ("Failed to create manifest" )
291
309
292
310
cmd = f"docker manifest push -p { t0 } "
293
- output = execute (cmd )
294
- self ._logger .debug ("$ %s\n %s" , cmd , output )
311
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
312
+ if os .system (cmd ) != 0 :
313
+ raise Exception ("Failed to push manifest" )
314
+
295
315
else :
296
316
cmd = f"docker manifest create { t0 } { new_manifest } "
297
- output = execute (cmd )
298
- self ._logger .debug ("$ %s\n %s" , cmd , output )
317
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
318
+ if os .system (cmd ) != 0 :
319
+ raise Exception ("Failed to create manifest" )
299
320
300
321
cmd = f"docker manifest push -p { t0 } "
301
- output = execute (cmd )
302
- self ._logger .debug ("$ %s\n %s" , cmd , output )
322
+ print ("\033 [34m$ %s\033 [0m" % cmd , flush = True )
323
+ if os .system (cmd ) != 0 :
324
+ raise Exception ("Failed to push manifest" )
303
325
304
326
def __repr__ (self ):
305
327
return "<Image name=%r tag=%r branch=%r>" % (self .name , self .tag , self .branch )
0 commit comments