From 17e68080b799c70c9ad31846add78eaa744ca525 Mon Sep 17 00:00:00 2001 From: Daohan Chong Date: Sun, 6 Mar 2022 18:14:30 +0800 Subject: [PATCH] Fix docker deployment (#166) * Docker fix * Update docker build script --- Dockerfile | 44 +++++++++++++++---------- requirements.txt | 2 +- scylla/providers/proxy_list_provider.py | 14 +++++--- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index d7f5aa6..b79fcd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,44 @@ FROM node:lts-buster as node-build + WORKDIR /root + COPY package.json . RUN yarn install COPY . . RUN make assets-build +FROM ubuntu:focal as python-build -FROM python:3.9-slim as python-build -RUN apt-get update && apt-get install -y g++ gcc libxslt-dev make libcurl4-openssl-dev build-essential -RUN apt-get install -y libssl-dev -WORKDIR /root +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=America/Los_Angeles + +RUN apt-get update && \ + apt-get install -y python3 python3-distutils libpython3.8-dev curl g++ gcc libxslt-dev make libcurl4-openssl-dev build-essential libssl-dev && \ + update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \ + curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ + python get-pip.py && \ + rm get-pip.py && \ + # Feature-parity with node.js base images. + apt-get install -y --no-install-recommends git openssh-client && \ + # clean apt cache + rm -rf /var/lib/apt/lists/* && \ + # Create the pwuser + adduser pwuser + +WORKDIR /app COPY --from=node-build /root/scylla/assets ./scylla/assets COPY requirements.txt . -RUN pip install -r requirements.txt -RUN python -m playwright install chromium +RUN pip3 install -r requirements.txt COPY . . -RUN python setup.py install +RUN python3 setup.py install -FROM python:3.9-slim as prod - -LABEL maintainer="WildCat " - -RUN apt-get update && apt-get install -y libxslt-dev libssl-dev libcurl4-openssl-dev - -COPY --from=python-build /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/ -COPY --from=python-build /root/.cache/ms-playwright /root/.cache/ms-playwright - -WORKDIR /var/www/scylla +RUN mkdir -p /var/www/scylla VOLUME /var/www/scylla +RUN python3 -m playwright install chromium --with-deps + EXPOSE 8899 EXPOSE 8081 -CMD python -m scylla \ No newline at end of file +CMD python3 -m scylla --db-path /var/www/scylla/scylla.db diff --git a/requirements.txt b/requirements.txt index a68c576..4d91139 100755 --- a/requirements.txt +++ b/requirements.txt @@ -6,5 +6,5 @@ sanic==21.6.2 sanic-cors schedule==1.1.0 six==1.16.0 -playwright==1.13.1 +playwright==1.19.1 pyquery==1.4.3 diff --git a/scylla/providers/proxy_list_provider.py b/scylla/providers/proxy_list_provider.py index c3b70ba..0f245db 100644 --- a/scylla/providers/proxy_list_provider.py +++ b/scylla/providers/proxy_list_provider.py @@ -1,5 +1,6 @@ import base64 import re +from typing import List from pyquery import PyQuery @@ -14,14 +15,19 @@ def __init__(self): super().__init__() self.w = Worker() - def parse(self, document: PyQuery) -> [ProxyIP]: - ip_list: [ProxyIP] = [] + def parse(self, document: PyQuery) -> List[ProxyIP]: + ip_list: List[ProxyIP] = [] if document is None: return [] for ul in document.find('#proxy-table > div.table-wrap ul'): - js_code = ul.find('li.proxy script').text() + js_code_element = ul.find('li.proxy script') + + if not js_code_element: + return [] + + js_code = js_code_element.text() matched = re.findall(r"Proxy\('(.+)'\)", js_code) if matched and len(matched) > 0: encoded = matched[0] @@ -32,7 +38,7 @@ def parse(self, document: PyQuery) -> [ProxyIP]: return ip_list - def urls(self) -> [str]: + def urls(self) -> List[str]: ret = [] first_url = 'http://proxy-list.org/english/index.php?p=1' first_page = self.w.get_html(first_url, False)