@@ -78,6 +78,7 @@ def __init__(self, **kwargs):
78
78
79
79
self ._containers = set ()
80
80
self .client = None
81
+ self .alpine_inherited = None
81
82
82
83
def validate_configuration (self ):
83
84
"""
@@ -647,45 +648,22 @@ def tar_task_definition(self, name: str, contents: str) -> bytes:
647
648
648
649
return tarstream .getvalue ()
649
650
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
-
665
651
def start_container (self , image , container_name : str , repo_path : Path ):
666
652
""" Starts a container with the image and name ``container_name`` and copies the repository into the container.
667
653
668
654
:type image: docker.models.images.Image
669
655
:rtype: docker.models.container.Container
670
656
"""
671
657
command = "bash -i"
672
- env = {}
673
658
674
659
if self .inherit_image :
675
660
command = "sh -i"
676
- env = {"ENV" : "/root/.profile" }
677
661
678
662
container = self .client .containers .run (image , command = command , detach = True , tty = True , name = container_name ,
679
663
working_dir = str ((Path ("/srv/data" ) / self .cwd ).resolve ()),
680
- auto_remove = True , environment = env )
664
+ auto_remove = True )
681
665
682
666
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
-
689
667
container .put_archive ("/srv" , self .tar_files (repo_path ))
690
668
container .put_archive ("/srv/scripts" , self .tar_runner ())
691
669
@@ -768,12 +746,21 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
768
746
res = None
769
747
770
748
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 )
777
764
778
765
# 124 is the standard, 143 on alpine
779
766
if res .exit_code in {124 , 143 }:
0 commit comments