chore:docker

This commit is contained in:
guorong.zheng 2024-11-26 13:39:59 +08:00
parent bfc78e2622
commit 487cb1f6f0
16 changed files with 84 additions and 33 deletions

1
.gitattributes vendored
View file

@ -1 +1,2 @@
*.sh linguist-language=Python
Dockerfile linguist-language=Python Dockerfile linguist-language=Python

View file

@ -50,22 +50,22 @@ jobs:
# open_ffmpeg = False # open_ffmpeg = False
# print(open_ffmpeg)')" >> $GITHUB_ENV # print(open_ffmpeg)')" >> $GITHUB_ENV
- name: Set up Chrome - name: Set up Chrome
if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' if: env.OPEN_DRIVER == 'True'
uses: browser-actions/setup-chrome@latest uses: browser-actions/setup-chrome@latest
with: with:
chrome-version: stable chrome-version: stable
- name: Download chrome driver - name: Download chrome driver
if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' if: env.OPEN_DRIVER == 'True'
uses: nanasess/setup-chromedriver@master uses: nanasess/setup-chromedriver@master
# - name: Install FFmpeg # - 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 # run: sudo apt-get update && sudo apt-get install -y ffmpeg
- name: Install pipenv - name: Install pipenv
run: pip3 install --user pipenv run: pip3 install --user pipenv
- name: Install dependecies - name: Install dependecies
run: pipenv --python 3.13 && pipenv install run: pipenv --python 3.13 && pipenv install
- name: Install selenium - name: Install selenium
if: env.OPEN_DRIVER == 'True' || env.OPEN_DRIVER == 'true' if: env.OPEN_DRIVER == 'True'
run: pipenv install selenium run: pipenv install selenium
- name: Update - name: Update
run: pipenv run dev run: pipenv run dev

View file

@ -1,6 +1,6 @@
FROM python:3.13 AS builder FROM python:3.13 AS builder
ARG LITE=false ARG LITE=False
WORKDIR /app WORKDIR /app
@ -9,16 +9,16 @@ COPY Pipfile* ./
RUN pip install -i https://mirrors.aliyun.com/pypi/simple pipenv RUN pip install -i https://mirrors.aliyun.com/pypi/simple pipenv
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy\ 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 FROM python:3.13-slim
ARG APP_WORKDIR=/iptv ARG APP_WORKDIR=/iptv
ARG LITE=false ARG LITE=False
ENV APP_WORKDIR=$APP_WORKDIR ENV APP_WORKDIR=$APP_WORKDIR
ENV PIPENV_VENV_IN_PROJECT=1 ENV LITE=$LITE
ENV PATH="/.venv/bin:$PATH" ENV PATH="/.venv/bin:$PATH"
WORKDIR $APP_WORKDIR 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 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/* && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN (crontab -l ; \ RUN (crontab -l ; \
@ -49,5 +49,10 @@ RUN (crontab -l ; \
EXPOSE 8000 EXPOSE 8000
CMD . /.venv/bin/activate && service cron start && python $APP_WORKDIR/main.py \ COPY entrypoint.sh /iptv_entrypoint.sh
&& gunicorn -w 4 -b 0.0.0.0:8000 main:app
COPY config /iptv_config
RUN chmod +x /iptv_entrypoint.sh
ENTRYPOINT /iptv_entrypoint.sh

View file

@ -6,11 +6,11 @@ verify_ssl = true
[scripts] [scripts]
dev = "python main.py" dev = "python main.py"
ui = "python tkinter_ui/tkinter_ui.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 = "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_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" 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 = "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] [dev-packages]
requests = "*" requests = "*"

View file

@ -198,7 +198,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output
- iptv:lite - iptv:lite
```bash ```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. 更新结果: 3. 更新结果:

View file

@ -153,7 +153,7 @@ pipenv run ui
### Method 4: Docker ### 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) - 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 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 - iptv:lite
```bash ```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: 3. Update results:

View file

@ -245,7 +245,7 @@ docker run -v /etc/docker/config:/iptv/config -v /etc/docker/output:/iptv/output
- iptv:lite - iptv:lite
```bash ```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. 更新结果: 3. 更新结果:

View file

@ -197,7 +197,7 @@ pipenv run ui
### Method 4: Docker ### 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) - 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 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 - iptv:lite
```bash ```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: 3. Update results:

View file

@ -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): def setup_driver(proxy=None):

View file

@ -6,6 +6,13 @@ from utils.retry import (
from time import sleep from time import sleep
import re import re
from bs4 import BeautifulSoup 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): def get_soup_driver(url):
@ -33,8 +40,6 @@ def search_submit(driver, name):
""" """
Input key word and submit with driver 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"]')) search_box = locate_element_with_retry(driver, (By.XPATH, '//input[@type="text"]'))
if not search_box: if not search_box:
return return

17
entrypoint.sh Normal file
View file

@ -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

View file

@ -22,6 +22,12 @@ from updates.subscribe import get_channels_by_subscribe_urls
from collections import defaultdict from collections import defaultdict
import updates.fofa.fofa_map as fofa_map 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): async def get_channels_by_hotel(callback=None):
""" """
@ -32,8 +38,6 @@ async def get_channels_by_hotel(callback=None):
proxy = None proxy = None
open_proxy = config.open_proxy open_proxy = config.open_proxy
open_driver = config.open_driver open_driver = config.open_driver
if open_driver:
from selenium.webdriver.common.by import By
page_num = config.hotel_page_num page_num = config.hotel_page_num
region_list = config.hotel_region_list region_list = config.hotel_region_list
if "all" in region_list or "ALL" in region_list or "全部" in region_list: if "all" in region_list or "ALL" in region_list or "全部" in region_list:

View file

@ -26,6 +26,12 @@ from urllib.parse import parse_qs
from collections import defaultdict from collections import defaultdict
from .update_tmp import get_multicast_region_result_by_rtp_txt 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): async def get_channels_by_multicast(names, callback=None):
""" """
@ -36,8 +42,6 @@ async def get_channels_by_multicast(names, callback=None):
proxy = None proxy = None
open_proxy = config.open_proxy open_proxy = config.open_proxy
open_driver = config.open_driver open_driver = config.open_driver
if open_driver:
from selenium.webdriver.common.by import By
page_num = config.multicast_page_num page_num = config.multicast_page_num
if open_proxy: if open_proxy:
proxy = await get_proxy(pageUrl, best=True, with_test=True) proxy = await get_proxy(pageUrl, best=True, with_test=True)

View file

@ -24,6 +24,12 @@ from tqdm.asyncio import tqdm_asyncio
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from requests_custom.utils import get_soup_requests, close_session 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): 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 proxy = None
open_proxy = config.open_proxy open_proxy = config.open_proxy
open_driver = config.open_driver open_driver = config.open_driver
if open_driver:
from selenium.webdriver.common.by import By
page_num = config.online_search_page_num page_num = config.online_search_page_num
if open_proxy: if open_proxy:
proxy = await get_proxy(pageUrl, best=True, with_test=True) proxy = await get_proxy(pageUrl, best=True, with_test=True)

View file

@ -270,7 +270,9 @@ class ConfigManager:
@property @property
def open_driver(self): 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 @property
def hotel_page_num(self): def hotel_page_num(self):

View file

@ -2,9 +2,12 @@ from time import sleep
from utils.config import config from utils.config import config
if config.open_driver: if config.open_driver:
from selenium.webdriver.support.ui import WebDriverWait try:
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
except:
pass
max_retries = 2 max_retries = 2