Skip to content

Commit 591a207

Browse files
committed
Timeout on Alpine
1 parent 1a0cb4a commit 591a207

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

arca/backend/docker.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,21 +647,45 @@ def tar_task_definition(self, name: str, contents: str) -> bytes:
647647

648648
return tarstream.getvalue()
649649

650+
def tar_alpine_alias(self):
651+
""" Returns a tar with a file with an alias definition thats needed for Alpine.
652+
"""
653+
tarstream = BytesIO()
654+
tar = tarfile.TarFile(fileobj=tarstream, mode='w')
655+
tarinfo = tarfile.TarInfo(name=".profile")
656+
657+
script_bytes = "if grep -q Alpine /etc/issue; then alias timeout=\"timeout -t\"; fi".encode("utf-8")
658+
tarinfo.size = len(script_bytes)
659+
tarinfo.mtime = int(time.time())
660+
tar.addfile(tarinfo, BytesIO(script_bytes))
661+
tar.close()
662+
663+
return tarstream.getvalue()
664+
650665
def start_container(self, image, container_name: str, repo_path: Path):
651666
""" Starts a container with the image and name ``container_name`` and copies the repository into the container.
652667
653668
:type image: docker.models.images.Image
654669
:rtype: docker.models.container.Container
655670
"""
656671
command = "bash -i"
672+
env = {}
673+
657674
if self.inherit_image:
658675
command = "sh -i"
676+
env = {"ENV": "/root/.profile"}
659677

660678
container = self.client.containers.run(image, command=command, detach=True, tty=True, name=container_name,
661679
working_dir=str((Path("/srv/data") / self.cwd).resolve()),
662-
auto_remove=True)
680+
auto_remove=True, environment=env)
663681

664682
container.exec_run(["mkdir", "-p", "/srv/scripts"])
683+
684+
# alpine uses a different timeout, an alias is needed
685+
if self.inherit_image:
686+
container.put_archive("/root", self.tar_alpine_alias())
687+
container.exec_run(["chmod", "+x", "/root/.profile"])
688+
665689
container.put_archive("/srv", self.tar_files(repo_path))
666690
container.put_archive("/srv/scripts", self.tar_runner())
667691

@@ -751,7 +775,8 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
751775
f"/srv/scripts/{task_filename}"],
752776
tty=True)
753777

754-
if res.exit_code == 124:
778+
# 124 is the standard, 143 on alpine
779+
if res.exit_code in {124, 143}:
755780
raise BuildTimeoutError(f"The task timeouted after {task.timeout} seconds.")
756781

757782
return Result(res.output)

0 commit comments

Comments
 (0)