Skip to content

Commit 3a763b9

Browse files
authored
fix(DM01-5918): docker-compose containers before archive upload on timeout (#598)
* fix(DM01-5918): gracefully stop docker-compose containers before archive upload on timeout * increase the priority of the upload_archive() function * update upload archive func
1 parent f8fcb19 commit 3a763b9

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/job/job.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,12 @@ def upload_archive(self):
378378
testresult_exists = False
379379

380380
if os.path.exists(self.infrabox_archive_dir):
381-
files = self.get_files_in_dir(self.infrabox_archive_dir)
382-
383-
if files:
384-
c.collect("Uploading /infrabox/upload/archive", show=True)
381+
if self.get_files_in_dir(self.infrabox_archive_dir):
385382
archive_exists = True
386-
for f in files:
387-
c.collect("%s" % f, show=True)
388-
self.post_file_to_api_server("/archive", f, filename=f.replace(self.infrabox_upload_dir+'/', ''))
389383

390384
if os.path.exists(self.infrabox_testresult_dir):
391-
files = self.get_files_in_dir(self.infrabox_testresult_dir)
392-
393-
if files:
385+
if self.get_files_in_dir(self.infrabox_testresult_dir):
394386
testresult_exists = True
395-
for f in files:
396-
c.collect("%s" % f, show=True)
397387

398388
tar_file = os.path.join(self.infrabox_upload_dir, 'all_archives' + '.tar.gz')
399389
with tarfile.open(tar_file, mode='w:gz') as archive:
@@ -404,6 +394,12 @@ def upload_archive(self):
404394

405395
self.post_file_to_api_server("/archive", tar_file)
406396

397+
if archive_exists:
398+
c.collect("Uploading /infrabox/upload/archive", show=True)
399+
for f in self.get_files_in_dir(self.infrabox_archive_dir):
400+
c.collect("%s" % f, show=True)
401+
self.post_file_to_api_server("/archive", f, filename=f.replace(self.infrabox_upload_dir+'/', ''))
402+
407403

408404
def upload_coverage_results(self):
409405
if not os.path.exists(self.infrabox_coverage_dir):
@@ -501,16 +497,24 @@ def _get_size(self, start_path):
501497
return total_size
502498

503499
def finalize_upload(self):
500+
self.upload_archive()
504501
self.upload_coverage_results()
505502
self.upload_test_results()
506503
self.upload_markup_files()
507504
self.upload_badge_files()
508-
self.upload_archive()
509505

510506
def handle_abort(self, signum, sigframe):
511507
if not self.aborted:
512508
self.aborted = True
513509
self.console.collect("##Aborted", show=True)
510+
if hasattr(self, '_compose_file_new'):
511+
try:
512+
subprocess.call(
513+
['docker-compose', '-f', self._compose_file_new, 'stop', '--timeout', '30'],
514+
env=self.environment,
515+
timeout=35)
516+
except Exception:
517+
pass
514518
self.finalize_upload()
515519

516520
def main_run_job(self):
@@ -722,6 +726,8 @@ def run_job_docker_compose(self, c):
722726
with open(compose_file_new, "w+") as out:
723727
json.dump(compose_file_content, out)
724728

729+
self._compose_file_new = compose_file_new
730+
725731
collector = StatsCollector()
726732

727733
self._login_source_registries()

src/scheduler/kubernetes/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def _sync(self, fi):
481481
'automountServiceAccountToken': False,
482482
'containers': containers,
483483
'restartPolicy': 'Never',
484-
'terminationGracePeriodSeconds': 60,
484+
'terminationGracePeriodSeconds': 180,
485485
'volumes': f['spec']['volumes'],
486486
'imagePullSecrets': f['spec'].get('imagePullSecrets', None)
487487
},

0 commit comments

Comments
 (0)