From f2511a0068d20d03db7d7dc4c4e9556dfe10ea65 Mon Sep 17 00:00:00 2001 From: luolongfei Date: Mon, 22 Nov 2021 15:02:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E5=AE=9A=20redis=20=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=AD=89=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 6 ++++++ Dockerfile | 27 ++++++--------------------- docker-entrypoint.sh | 2 +- netflix.py | 5 ++++- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 8081899..9f59c78 100644 --- a/.env.example +++ b/.env.example @@ -11,3 +11,9 @@ BOT_MAIL_PASSWORD='' # 用于接收通知的邮箱 INBOX='' + +# Redis 地址(本地可设为 127.0.0.1,以 docker-compose 形式运行请设为 redis_for_netflix) +REDIS_HOST='redis_for_netflix' + +# Redis 端口 +REDIS_PORT=6379 diff --git a/Dockerfile b/Dockerfile index a93aa90..54c019c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,11 @@ ARG DEBIAN_FRONTEND=noninteractive ARG CHROME_VERSION=96.0.4664.45-1 ARG CHROME_DRIVER_VERSION=96.0.4664.45 -ARG CHROME_DOWNLOAD_URL=https://github.feifei.cf/https://github.com/feilongluo/data/releases/download/v0.1/google-chrome-stable_${CHROME_VERSION}_amd64.deb -ARG CHROME_DRIVER_DOWNLOAD_URL=https://npm.taobao.org/mirrors/chromedriver/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip +ARG CHROME_DOWNLOAD_URL=http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb +ARG CHROME_DRIVER_DOWNLOAD_URL=https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip -# Debian 设置国内源 -RUN sed -i 's/deb.debian.org/ftp.cn.debian.org/g' /etc/apt/sources.list +# Debian 设置国内源(暂时不必) +# RUN sed -i 's/deb.debian.org/ftp.cn.debian.org/g' /etc/apt/sources.list # set -eux e: 脚本只要发生错误,就终止执行 u: 遇到不存在的变量就会报错,并停止执行 x: 在运行结果之前,先输出执行的那一行命令 RUN set -eux; \ @@ -56,20 +56,6 @@ RUN set -eux; \ apt-get clean; \ # 删除包信息缓存 rm -rf /var/lib/apt/lists/* - -# 确定 Chrome 以及 ChromeDriver 的下载地址 -RUN if [ $(curl -ks cip.cc | awk -F ':' '/地址/ {print $2}' | awk -F ' ' '{if ($1 == "中国") print 1; else print 0}') -eq 1 ]; \ - then \ - echo '检测到当前系统在中国境内,将从淘宝镜像下载 chromedriver,并从 github.feifei.cf 下载 chrome'; \ - CHROME_DOWNLOAD_URL=https://github.feifei.cf/https://github.com/feilongluo/data/releases/download/v0.1/google-chrome-stable_${CHROME_VERSION}_amd64.deb; \ - CHROME_DRIVER_DOWNLOAD_URL=https://npm.taobao.org/mirrors/chromedriver/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip; \ - else \ - echo '检测到当前系统在国外,将直接从谷歌官网下载 chrome 以及 chromedriver'; \ - CHROME_DOWNLOAD_URL=http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb; \ - CHROME_DRIVER_DOWNLOAD_URL=https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip; \ - fi - -WORKDIR /tmp # 下载并安装 Chrome RUN wget --no-verbose -O /tmp/chrome.deb "${CHROME_DOWNLOAD_URL}"; \ @@ -87,13 +73,12 @@ RUN wget --no-verbose -O chromedriver.zip "${CHROME_DRIVER_DOWNLOAD_URL}"; \ WORKDIR /app -COPY requirements.txt ./ +COPY . ./ + RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt VOLUME ["/conf", "/app/logs"] -COPY . ./ - COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b5d0f83..4454fce 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -18,6 +18,6 @@ if [ ! -f /app/.env ]; then ln -s /conf/.env /app/.env fi -python netflix.py -hl +python netflix.py -hl -f exec "$@" \ No newline at end of file diff --git a/netflix.py b/netflix.py index 8324dbe..86d8bc4 100644 --- a/netflix.py +++ b/netflix.py @@ -198,6 +198,9 @@ def __init__(self): # 线程池 self.max_workers = self.args.max_workers + # Redis 配置 + self.REDIS_HOST = os.getenv('REDIS_HOST', '127.0.0.1') + self.REDIS_PORT = os.getenv('REDIS_PORT', 6379) self.redis = None @staticmethod @@ -1094,7 +1097,7 @@ def run(self): self.today = real_today self.__logger_setting() - self.redis = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True) + self.redis = redis.Redis(host=self.REDIS_HOST, port=self.REDIS_PORT, db=0, decode_responses=True) self.redis.set_response_callback('GET', int) with ThreadPoolExecutor(max_workers=self.max_workers) as executor: