File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,14 @@ def _send_func(request_data):
22
22
pass # nosec
23
23
24
24
def is_docker ():
25
- from pathlib import Path
26
- cgroup = Path ('/proc/self/cgroup' )
27
- return Path ('/.dockerenv' ).is_file () or cgroup .is_file () and 'docker' in cgroup .read_text ()
25
+ def text_in_file (text , filename ):
26
+ try :
27
+ with open (filename , encoding = 'utf-8' ) as lines :
28
+ return any (text in line for line in lines )
29
+ except OSError :
30
+ return False
31
+ cgroup = '/proc/self/cgroup'
32
+ return os .path .exists ('/.dockerenv' ) or text_in_file ('docker' , cgroup )
28
33
29
34
class GA4Backend (TelemetryBackend ):
30
35
id = 'ga4'
Original file line number Diff line number Diff line change @@ -105,7 +105,5 @@ def test_new_cid_priority_over_old_file(self):
105
105
def test_is_docker (self ):
106
106
from .backend_ga4 import is_docker
107
107
run_from_docker = "DOCKER_RUN" in os .environ and os .environ ["DOCKER_RUN" ].lower () == "true"
108
- print ("os.environ {}" .format (os .environ ["DOCKER_RUN" ]))
109
- print ("is docker {}" .format (is_docker ()))
110
108
111
109
self .assertTrue (run_from_docker == is_docker ())
You can’t perform that action at this time.
0 commit comments