Skip to content

Commit 94d18ed

Browse files
committed
Changed Alpine detection to something that actually works
1 parent 9067bb3 commit 94d18ed

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

arca/backend/docker.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __init__(self, **kwargs):
7878

7979
self._containers = set()
8080
self.client = None
81+
self.alpine_inherited = None
8182

8283
def validate_configuration(self):
8384
"""
@@ -647,45 +648,22 @@ def tar_task_definition(self, name: str, contents: str) -> bytes:
647648

648649
return tarstream.getvalue()
649650

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-
665651
def start_container(self, image, container_name: str, repo_path: Path):
666652
""" Starts a container with the image and name ``container_name`` and copies the repository into the container.
667653
668654
:type image: docker.models.images.Image
669655
:rtype: docker.models.container.Container
670656
"""
671657
command = "bash -i"
672-
env = {}
673658

674659
if self.inherit_image:
675660
command = "sh -i"
676-
env = {"ENV": "/root/.profile"}
677661

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

682666
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-
689667
container.put_archive("/srv", self.tar_files(repo_path))
690668
container.put_archive("/srv/scripts", self.tar_runner())
691669

@@ -768,12 +746,21 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
768746
res = None
769747

770748
try:
771-
res = container.exec_run(["timeout",
772-
str(task.timeout),
773-
"python",
774-
"/srv/scripts/runner.py",
775-
f"/srv/scripts/{task_filename}"],
776-
tty=True)
749+
command = ["timeout"]
750+
751+
if self.inherit_image:
752+
if self.alpine_inherited or b"Alpine" in container.exec_run(["cat", "/etc/issue"], tty=True).output:
753+
self.alpine_inherited = True
754+
command = ["timeout", "-t"]
755+
756+
command += [str(task.timeout),
757+
"python",
758+
"/srv/scripts/runner.py",
759+
f"/srv/scripts/{task_filename}"]
760+
761+
logger.debug("Running command %s", " ".join(command))
762+
763+
res = container.exec_run(command, tty=True)
777764

778765
# 124 is the standard, 143 on alpine
779766
if res.exit_code in {124, 143}:

arca/result.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ class Result:
1010

1111
def __init__(self, result: Union[str, Dict[str, Any]]) -> None:
1212
if isinstance(result, (str, bytes, bytearray)):
13+
output = result
1314
try:
1415
result = json.loads(result)
1516
except ValueError:
1617
raise BuildError("The build failed (the output was corrupted, "
17-
"possibly by the callable printing something)")
18+
"possibly by the callable printing something)",
19+
extra_info={
20+
"output": output
21+
})
1822

1923
if not isinstance(result, dict):
2024
raise BuildError("The build failed (the value returned from the runner was not valid)")

0 commit comments

Comments
 (0)