From 487cb1f6f0d9db965ee4c4643be4e8648b640f4b Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Tue, 26 Nov 2024 13:39:59 +0800 Subject: [PATCH] chore:docker --- .gitattributes | 1 + .github/workflows/main.yml | 8 ++++---- Dockerfile | 19 ++++++++++++------- Pipfile | 6 +++--- README.md | 2 +- README_en.md | 4 ++-- docs/tutorial.md | 2 +- docs/tutorial_en.md | 4 ++-- driver/setup.py | 8 +++++++- driver/utils.py | 9 +++++++-- entrypoint.sh | 17 +++++++++++++++++ updates/hotel/request.py | 8 ++++++-- updates/multicast/request.py | 8 ++++++-- updates/online_search/request.py | 8 ++++++-- utils/config.py | 4 +++- utils/retry.py | 9 ++++++--- 16 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 entrypoint.sh diff --git a/.gitattributes b/.gitattributes index 1a966c6..e89baee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +*.sh linguist-language=Python Dockerfile linguist-language=Python \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b590cd2..297b717 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,22 +50,22 @@ jobs: # open_ffmpeg = False # print(open_ffmpeg)')" >> $GITHUB_ENV - name: Set up Chrome - if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' + if: env.OPEN_DRIVER == 'True' uses: browser-actions/setup-chrome@latest with: chrome-version: stable - name: Download chrome driver - if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' + if: env.OPEN_DRIVER == 'True' uses: nanasess/setup-chromedriver@master # - name: Install FFmpeg - # if: env.OPEN_FFMPEG == 'True' || env.OPEN_FFMPEG == 'true' + # if: env.OPEN_FFMPEG == 'True' # run: sudo apt-get update && sudo apt-get install -y ffmpeg - name: Install pipenv run: pip3 install --user pipenv - name: Install dependecies run: pipenv --python 3.13 && pipenv install - name: Install selenium - if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' + if: env.OPEN_DRIVER == 'True' run: pipenv install selenium - name: Update run: pipenv run dev diff --git a/Dockerfile b/Dockerfile index e16c249..39cc522 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.13 AS builder -ARG LITE=false +ARG LITE=False WORKDIR /app @@ -9,16 +9,16 @@ COPY Pipfile* ./ RUN pip install -i https://mirrors.aliyun.com/pypi/simple pipenv RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy\ - && if [ "$LITE" = false ]; then pipenv install selenium; fi + && if [ "$LITE" = False ]; then pipenv install selenium; fi FROM python:3.13-slim ARG APP_WORKDIR=/iptv -ARG LITE=false +ARG LITE=False ENV APP_WORKDIR=$APP_WORKDIR -ENV PIPENV_VENV_IN_PROJECT=1 +ENV LITE=$LITE ENV PATH="/.venv/bin:$PATH" WORKDIR $APP_WORKDIR @@ -40,7 +40,7 @@ RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free RUN apt-get update && apt-get install -y --no-install-recommends cron -RUN if [ "$LITE" = false ]; then apt-get install -y --no-install-recommends chromium chromium-driver; fi \ +RUN if [ "$LITE" = False ]; then apt-get install -y --no-install-recommends chromium chromium-driver; fi \ && apt-get clean && rm -rf /var/lib/apt/lists/* RUN (crontab -l ; \ @@ -49,5 +49,10 @@ RUN (crontab -l ; \ EXPOSE 8000 -CMD . /.venv/bin/activate && service cron start && python $APP_WORKDIR/main.py \ - && gunicorn -w 4 -b 0.0.0.0:8000 main:app \ No newline at end of file +COPY entrypoint.sh /iptv_entrypoint.sh + +COPY config /iptv_config + +RUN chmod +x /iptv_entrypoint.sh + +ENTRYPOINT /iptv_entrypoint.sh \ No newline at end of file diff --git a/Pipfile b/Pipfile index 1b262ef..a078090 100644 --- a/Pipfile +++ b/Pipfile @@ -6,11 +6,11 @@ verify_ssl = true [scripts] dev = "python main.py" ui = "python tkinter_ui/tkinter_ui.py" -docker_run = "docker run -v config:/iptv/config -v output:/iptv/output -d -p 8000:8000 guovern/iptv" -docker_run_lite = "docker run -v config:/iptv-lite/config -v output:/iptv-lite/output -d -p 8000:8000 guovern/iptv:lite" +docker_run = "docker run -v ./config:/iptv/config -v ./output:/iptv/output -d -p 8000:8000 guovern/iptv" +docker_run_lite = "docker run -v ./config:/iptv_lite/config -v ./output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite" tkinter_build = "pyinstaller tkinter_ui/tkinter_ui.spec" docker_build = "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg APP_WORKDIR=/iptv -t guovern/iptv ." -docker_build_lite = "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg APP_WORKDIR=/iptv-lite --build-arg LITE=true -t guovern/iptv:lite ." +docker_build_lite = "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg APP_WORKDIR=/iptv_lite --build-arg LITE=True -t guovern/iptv:lite ." [dev-packages] requests = "*" diff --git a/README.md b/README.md index 6c5a7de..cbb9484 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output - iptv:lite: ```bash -docker run -v /etc/docker/config:/iptv-lite/config -v /etc/docker/output:/iptv-lite/output -d -p 8000:8000 guovern/iptv:lite +docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite ``` 3. 更新结果: diff --git a/README_en.md b/README_en.md index 5daa4eb..9f7a3e2 100644 --- a/README_en.md +++ b/README_en.md @@ -153,7 +153,7 @@ pipenv run ui ### Method 4: Docker -- iptv (Full version): Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the iptv-lite running mode (recommended for hotel sources, multicast sources, and online searches) +- iptv (Full version): Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the lite running mode (recommended for hotel sources, multicast sources, and online searches) - iptv:lite (Condensed version): Lightweight, low performance requirements, fast update speed, stability uncertain (recommend using this version for the subscription source) It's recommended to try each one and choose the version that suits you @@ -200,7 +200,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output - iptv:lite: ```bash -docker run -v /etc/docker/config:/iptv-lite/config -v /etc/docker/output:/iptv-lite/output -d -p 8000:8000 guovern/iptv:lite +docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite ``` 3. Update results: diff --git a/docs/tutorial.md b/docs/tutorial.md index b6940d7..87def7e 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -245,7 +245,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output - iptv:lite: ```bash -docker run -v /etc/docker/config:/iptv-lite/config -v /etc/docker/output:/iptv-lite/output -d -p 8000:8000 guovern/iptv:lite +docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite ``` 3. 更新结果: diff --git a/docs/tutorial_en.md b/docs/tutorial_en.md index 0ead44a..7fe20fa 100644 --- a/docs/tutorial_en.md +++ b/docs/tutorial_en.md @@ -197,7 +197,7 @@ pipenv run ui ### Method 4: Docker -- iptv (Full version): Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the iptv-lite running mode (recommended for hotel sources, multicast sources, and online searches) +- iptv (Full version): Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the lite running mode (recommended for hotel sources, multicast sources, and online searches) - iptv:lite (Condensed version): Lightweight, low performance requirements, fast update speed, stability uncertain (recommend using this version for the subscription source) It's recommended to try each one and choose the version that suits you @@ -244,7 +244,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output - iptv:lite: ```bash -docker run -v /etc/docker/config:/iptv-lite/config -v /etc/docker/output:/iptv-lite/output -d -p 8000:8000 guovern/iptv:lite +docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite ``` 3. Update results: diff --git a/driver/setup.py b/driver/setup.py index d1070d5..a80e95f 100644 --- a/driver/setup.py +++ b/driver/setup.py @@ -1,4 +1,10 @@ -from selenium import webdriver +from utils.config import config + +if config.open_driver: + try: + from selenium import webdriver + except: + pass def setup_driver(proxy=None): diff --git a/driver/utils.py b/driver/utils.py index 54a0570..bab9d61 100644 --- a/driver/utils.py +++ b/driver/utils.py @@ -6,6 +6,13 @@ from utils.retry import ( from time import sleep import re from bs4 import BeautifulSoup +from utils.config import config + +if config.open_driver: + try: + from selenium.webdriver.common.by import By + except: + pass def get_soup_driver(url): @@ -33,8 +40,6 @@ def search_submit(driver, name): """ Input key word and submit with driver """ - from selenium.webdriver.common.by import By - search_box = locate_element_with_retry(driver, (By.XPATH, '//input[@type="text"]')) if not search_box: return diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..d3c19f0 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +for file in /iptv_config/*; do + filename=$(basename "$file") + target_file="$APP_WORKDIR/config/$filename" + if [ ! -e "$target_file" ]; then + cp -r "$file" "$target_file" + fi +done + +. /.venv/bin/activate + +service cron start + +python $APP_WORKDIR/main.py + +gunicorn -w 4 -b 0.0.0.0:8000 main:app \ No newline at end of file diff --git a/updates/hotel/request.py b/updates/hotel/request.py index a2eb570..1f8e21a 100644 --- a/updates/hotel/request.py +++ b/updates/hotel/request.py @@ -22,6 +22,12 @@ from updates.subscribe import get_channels_by_subscribe_urls from collections import defaultdict import updates.fofa.fofa_map as fofa_map +if config.open_driver: + try: + from selenium.webdriver.common.by import By + except: + pass + async def get_channels_by_hotel(callback=None): """ @@ -32,8 +38,6 @@ async def get_channels_by_hotel(callback=None): proxy = None open_proxy = config.open_proxy open_driver = config.open_driver - if open_driver: - from selenium.webdriver.common.by import By page_num = config.hotel_page_num region_list = config.hotel_region_list if "all" in region_list or "ALL" in region_list or "全部" in region_list: diff --git a/updates/multicast/request.py b/updates/multicast/request.py index 769008d..1706e2d 100644 --- a/updates/multicast/request.py +++ b/updates/multicast/request.py @@ -26,6 +26,12 @@ from urllib.parse import parse_qs from collections import defaultdict from .update_tmp import get_multicast_region_result_by_rtp_txt +if config.open_driver: + try: + from selenium.webdriver.common.by import By + except: + pass + async def get_channels_by_multicast(names, callback=None): """ @@ -36,8 +42,6 @@ async def get_channels_by_multicast(names, callback=None): proxy = None open_proxy = config.open_proxy open_driver = config.open_driver - if open_driver: - from selenium.webdriver.common.by import By page_num = config.multicast_page_num if open_proxy: proxy = await get_proxy(pageUrl, best=True, with_test=True) diff --git a/updates/online_search/request.py b/updates/online_search/request.py index 27c9151..0992c9e 100644 --- a/updates/online_search/request.py +++ b/updates/online_search/request.py @@ -24,6 +24,12 @@ from tqdm.asyncio import tqdm_asyncio from concurrent.futures import ThreadPoolExecutor from requests_custom.utils import get_soup_requests, close_session +if config.open_driver: + try: + from selenium.webdriver.common.by import By + except: + pass + async def get_channels_by_online_search(names, callback=None): """ @@ -36,8 +42,6 @@ async def get_channels_by_online_search(names, callback=None): proxy = None open_proxy = config.open_proxy open_driver = config.open_driver - if open_driver: - from selenium.webdriver.common.by import By page_num = config.online_search_page_num if open_proxy: proxy = await get_proxy(pageUrl, best=True, with_test=True) diff --git a/utils/config.py b/utils/config.py index ea434b7..a4ccf78 100644 --- a/utils/config.py +++ b/utils/config.py @@ -270,7 +270,9 @@ class ConfigManager: @property def open_driver(self): - return self.config.getboolean("Settings", "open_driver", fallback=True) + return not os.environ.get("LITE") and self.config.getboolean( + "Settings", "open_driver", fallback=True + ) @property def hotel_page_num(self): diff --git a/utils/retry.py b/utils/retry.py index 39c0745..2702098 100644 --- a/utils/retry.py +++ b/utils/retry.py @@ -2,9 +2,12 @@ from time import sleep from utils.config import config if config.open_driver: - from selenium.webdriver.support.ui import WebDriverWait - from selenium.webdriver.support import expected_conditions as EC - from selenium.common.exceptions import TimeoutException + try: + from selenium.webdriver.support.ui import WebDriverWait + from selenium.webdriver.support import expected_conditions as EC + from selenium.common.exceptions import TimeoutException + except: + pass max_retries = 2