Runs container, and returns True if the container had a successful exit value. This blocks while the container is running. The container output is run through annotate.py to add timestamps and saved into the container's log file.
(self, container)
| 580 | return ctr |
| 581 | |
| 582 | def _run_container(self, container): |
| 583 | """Runs container, and returns True if the container had a successful exit value. |
| 584 | |
| 585 | This blocks while the container is running. The container output is |
| 586 | run through annotate.py to add timestamps and saved into the container's log file. |
| 587 | """ |
| 588 | container.running = True |
| 589 | tailer = None |
| 590 | |
| 591 | with open(container.logfile, "aw") as log_output: |
| 592 | if self.tail: |
| 593 | tailer = subprocess.Popen( |
| 594 | ["tail", "-f", "--pid", str(os.getpid()), "-v", container.logfile]) |
| 595 | |
| 596 | container.start = time.time() |
| 597 | # Sets up a "docker start ... | annotate.py > logfile" pipeline using |
| 598 | # subprocess. |
| 599 | annotate = subprocess.Popen( |
| 600 | [os.path.join(self.git_root, "docker", "annotate.py")], |
| 601 | stdin=subprocess.PIPE, |
| 602 | stdout=log_output, |
| 603 | stderr=log_output) |
| 604 | |
| 605 | logging.info("Starting container %s; logging to %s", container.name, |
| 606 | container.logfile) |
| 607 | docker = subprocess.Popen(["docker", "start", "--attach", container.id], |
| 608 | stdin=None, stdout=annotate.stdin, stderr=annotate.stdin) |
| 609 | |
| 610 | ret = docker.wait() |
| 611 | annotate.stdin.close() |
| 612 | annotate.wait() |
| 613 | |
| 614 | logging.info("Container %s returned %s", container, ret) |
| 615 | container.exitcode = ret |
| 616 | container.running = False |
| 617 | container.end = time.time() |
| 618 | if tailer: |
| 619 | tailer.kill() |
| 620 | return ret == 0 |
| 621 | |
| 622 | @staticmethod |
| 623 | def _stop_container(container): |