Skip to content

Commit

Permalink
Dockerfile: install mitmproxy into a special pythonpath; Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoye committed Sep 15, 2022
1 parent 7ac6542 commit 40a9a65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN if [[ -n "$USE_MIRROR" ]] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.us
&& apk update \
&& apk add --no-cache build-base jpeg-dev zlib-dev libffi-dev openssl-dev \
&& if [[ -n "$USE_MIRROR" ]] ; then pip install --no-cache-dir . facebook-wda==0.8.1 jsonschema -i https://pypi.douban.com/simple ; else pip install --no-cache-dir . facebook-wda==0.8.1 jsonschema ; fi \
&& pip install mitmproxy -t /usr/local/mitmenv \
&& rm -rf /usr/src \
&& apk del --purge build-base jpeg-dev zlib-dev libffi-dev openssl-dev

Expand All @@ -23,9 +24,12 @@ ARG USE_MIRROR
ENV PYTHONUNBUFFERED 1
RUN if [[ -n "$USE_MIRROR" ]] ; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; fi \
&& apk update \
&& apk add --no-cache jpeg zlib libffi openssl curl libstdc++ tzdata
&& apk add --no-cache jpeg zlib libffi openssl curl libstdc++ tzdata \
&& echo -e "#!/bin/sh\nexport PYTHONPATH=/usr/local/mitmenv\npython -c 'from mitmproxy.tools.main import mitmdump;mitmdump()' \$@" > /usr/local/bin/mitmdump \
&& chmod a+x /usr/local/bin/mitmdump
COPY --from=pybuilder /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
COPY --from=pybuilder /usr/local/bin /usr/local/bin
COPY --from=pybuilder /usr/local/mitmenv /usr/local/mitmenv

EXPOSE 9090 4272
CMD [ "lyrebird" ]
1 change: 1 addition & 0 deletions e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _find_free_port(self):
return s.getsockname()[1]

def start(self, checker_path=None):

cmdline = f'python -m lyrebird -b -v --no-mitm --mock {self.port} --extra-mock {self.extra_mock_port}'
if checker_path:
cmdline = cmdline + f' --script {checker_path}'
Expand Down
9 changes: 7 additions & 2 deletions lyrebird/mock/mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lyrebird.base_server import ThreadServer
from lyrebird import application
from lyrebird import log
import sys
import traceback

"""
Expand Down Expand Up @@ -89,8 +90,12 @@ def on_app_error(error):
def run(self):
server_ip = application.config.get('ip')
_logger.log(60, f'Core start on http://{server_ip}:{self.port}')
self.socket_io.run(self.app, host='0.0.0.0', port=self.port, debug=self.debug,
use_reloader=False, allow_unsafe_werkzeug=True)
if not sys.stdin or not sys.stdin.isatty():
# For e2e testing start lyrebird in subprocess
self.socket_io.run(self.app, host='0.0.0.0', port=self.port, debug=self.debug,
use_reloader=False, allow_unsafe_werkzeug=True)
else:
self.socket_io.run(self.app, host='0.0.0.0', port=self.port, debug=self.debug, use_reloader=False)

def stop(self):
"""
Expand Down

0 comments on commit 40a9a65

Please sign in to comment.