@@ -647,21 +647,45 @@ def tar_task_definition(self, name: str, contents: str) -> bytes:
647
647
648
648
return tarstream .getvalue ()
649
649
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
+
650
665
def start_container (self , image , container_name : str , repo_path : Path ):
651
666
""" Starts a container with the image and name ``container_name`` and copies the repository into the container.
652
667
653
668
:type image: docker.models.images.Image
654
669
:rtype: docker.models.container.Container
655
670
"""
656
671
command = "bash -i"
672
+ env = {}
673
+
657
674
if self .inherit_image :
658
675
command = "sh -i"
676
+ env = {"ENV" : "/root/.profile" }
659
677
660
678
container = self .client .containers .run (image , command = command , detach = True , tty = True , name = container_name ,
661
679
working_dir = str ((Path ("/srv/data" ) / self .cwd ).resolve ()),
662
- auto_remove = True )
680
+ auto_remove = True , environment = env )
663
681
664
682
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
+
665
689
container .put_archive ("/srv" , self .tar_files (repo_path ))
666
690
container .put_archive ("/srv/scripts" , self .tar_runner ())
667
691
@@ -751,7 +775,8 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
751
775
f"/srv/scripts/{ task_filename } " ],
752
776
tty = True )
753
777
754
- if res .exit_code == 124 :
778
+ # 124 is the standard, 143 on alpine
779
+ if res .exit_code in {124 , 143 }:
755
780
raise BuildTimeoutError (f"The task timeouted after { task .timeout } seconds." )
756
781
757
782
return Result (res .output )
0 commit comments