Commit bc09017b authored by Adrian DC's avatar Adrian DC
Browse files

fix: resolve #13: fix rare container wait random failures

parent dcdb6c93
Loading
Loading
Loading
Loading
Loading
+12 −7
Changes for gitlabci_local/runner.py: 12 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -142,9 +142,9 @@ def runner(options, job_data, last_result):

            # Launch container
            container = client.containers.run(
                job_data['image'], auto_remove=True, command=script.name, detach=True,
                job_data['image'], command=script.name, detach=True,
                entrypoint=entrypoint, environment=variables, network_mode='bridge',
                stdout=True, stderr=True, stream=True, volumes=volumes,
                remove=True, stdout=True, stderr=True, stream=True, volumes=volumes,
                working_dir=pathWorkDir)

            # Create interruption handler
@@ -163,25 +163,30 @@ def runner(options, job_data, last_result):

            # Execution wrapper
            success = False
            try:

            # Show container logs
            try:
                for line in container.logs(stream=True):
                    print(line.decode('utf-8'), end='', flush=True)
            except:
                pass

            # Check container status
            try:
                wait = container.wait()
                success = (wait['StatusCode'] == 0)
            except:
                pass

            # Stop container
            try:
                container.stop(timeout=0)

            # Intercept execution failures
            except:
                pass

                # Stop container
            # Remove container
            try:
                    container.stop(timeout=0)
                container.remove(force=True)
            except:
                pass