Skip to content

Commit

Permalink
指定 redis 主机地址等配置
Browse files Browse the repository at this point in the history
  • Loading branch information
luolongfei committed Nov 22, 2021
1 parent 8ef021e commit f2511a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 6 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down Expand Up @@ -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}"; \
Expand All @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
5 changes: 4 additions & 1 deletion netflix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f2511a0

Please sign in to comment.