File tree 4 files changed +34
-11
lines changed
4 files changed +34
-11
lines changed Original file line number Diff line number Diff line change 26
26
with :
27
27
name : wheel
28
28
path : ${{ github.workspace }}/**/*.whl
29
+
30
+ Run_Docker_Tests :
31
+ runs-on : ubuntu-20.04
32
+ steps :
33
+ - uses : actions/checkout@v4
34
+
35
+ - name : git ls-tree
36
+ run : |
37
+ docker build --tag 'image_tests' .
Original file line number Diff line number Diff line change
1
+ FROM python:3.12
2
+ WORKDIR /usr/local/app
3
+ ENV CI=true
4
+ ENV DOCKER_RUN=true
5
+
6
+ RUN pip install pytest
7
+
8
+ COPY src ./src
9
+ EXPOSE 5000
10
+
11
+ RUN useradd app
12
+ USER app
13
+
14
+ RUN pytest -k test_is_docker ./
Original file line number Diff line number Diff line change @@ -21,18 +21,10 @@ def _send_func(request_data):
21
21
except Exception as err :
22
22
pass # nosec
23
23
24
-
25
24
def is_docker ():
26
- def text_in_file (text , filename ):
27
- try :
28
- with open (filename , encoding = 'utf-8' ) as lines :
29
- return any (text in line for line in lines )
30
- except OSError :
31
- return False
32
-
33
- cgroup = os .path .join ('proc' , 'self' , 'cgroup' )
34
- return os .path .exists (os .sep + '.dockerenv' ) or text_in_file ('docker' , cgroup )
35
-
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 ()
36
28
37
29
class GA4Backend (TelemetryBackend ):
38
30
id = 'ga4'
Original file line number Diff line number Diff line change @@ -101,3 +101,11 @@ def test_new_cid_priority_over_old_file(self):
101
101
self .backend .old_cid_filename )
102
102
103
103
self .assertTrue (cid_value == new_cid )
104
+
105
+ def test_is_docker (self ):
106
+ from .backend_ga4 import is_docker
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
+
111
+ self .assertTrue (run_from_docker == is_docker ())
You can’t perform that action at this time.
0 commit comments