Skip to content

Commit

Permalink
puppeteer 启用远程浏览器进程, 修复 Dockerfile 和 docker-compose (DIYgod#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQW authored and DIYgod committed Oct 12, 2018
1 parent 1a64ac3 commit 88883f0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
49 changes: 32 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
FROM node:10.3.0-slim
MAINTAINER soulteary<[email protected]>
LABEL MAINTAINER https://github.com/DIYgod/RSSHub/

RUN apt-get update && apt-get install -yq libgconf-2-4 apt-transport-https

ENV NODE_ENV production

WORKDIR /usr/src/app
WORKDIR /app

COPY package.json /app

ARG USE_CHINA_NPM_REGISTRY=0;

COPY ./package.json .
RUN apt-get update && apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb
RUN if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
echo 'use npm mirror'; npm config set registry https://registry.npm.taobao.org; \
fi;

ARG PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1;

RUN if [ "$PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" = 0 ]; then \
apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb \
&& npm install --production; \
else \
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true && \
npm install --production; \
fi;

ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

ARG USE_CHINA_NPM_REGISTRY=0
RUN if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then echo 'use npm mirror'; npm install --production --vb --registry=https://registry.npm.taobao.org; else npm install --production; fi;

COPY . .
COPY . /app

CMD node index.js
EXPOSE 1200
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "run", "start"]
22 changes: 11 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
version: '2.1'
version: '3'

services:

rsshub:
service.rsshub:
build:
dockerfile: ./Dockerfile
context: .
args:
# 是否在构建过程中使用淘宝NPM源进行加速
USE_CHINA_NPM_REGISTRY: 0
# 是否在构建过程中跳过安装 Chromium, 参见 https://docs.rsshub.app/install/#docker-compose-deployment
# whether to skip puppeteer Chromium installation or not, refer to https://docs.rsshub.app/en/install/#docker-compose-deployment
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
restart: always
image: rsshub
ports:
- 1200:1200
environment:
NODE_ENV: production
CACHE_TYPE: redis
REDIS_URL: 'redis://redis:6379/'
command: node index.js
links:
- redis
REDIS_URL: 'redis://db.redis:6379/'
volumes:
- ./config/app.json:/usr/src/app/app.json
- ./config/config.js:/usr/src/app/config.json
- ./config/app.json:/app/app.json
- ./config/config.js:/app/config.js
depends_on:
- redis
- db.redis

redis:
image: redis:4.0.9-alpine
db.redis:
image: redis:4.0.11-alpine
volumes:
- redis-data:/data

Expand Down
3 changes: 3 additions & 0 deletions docs/en/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ $ docker volume create redis-data

2. Change `environment` section in [docker-compose.yml](https://github.com/DIYgod/RSSHub/blob/master/docker-compose.yml) to configure the corresponding option

- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1` skips puppeteer Chromium installation. Default to 1, requires `puppeteerWSEndpoint` in `config.js` to be set with a remote Chrome Websocket address, otherwise relevant routes will not work.
- `USE_CHINA_NPM_REGISTRY=1` avoids GFW npm registry interference in mainland China. Default to 0.

3. Deploy

```bash
Expand Down
3 changes: 3 additions & 0 deletions docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ $ docker volume create redis-data

2. 修改 [docker-compose.yml](https://github.com/DIYgod/RSSHub/blob/master/docker-compose.yml) 中的 `environment` 进行配置

- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1` 用以跳过 puppeteer Chromium 的安装. 默认为 1, 需要在 `config.js` 中的 `puppeteerWSEndpoint`中设置相应的远程 Chrome Websocket 地址, 以启用相应路由.
- `USE_CHINA_NPM_REGISTRY=1` 防止 npm 受到来自 GFW 的干扰. 默认为 0.

3. 部署

```bash
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"pidusage": "^2.0.17",
"plist": "^3.0.1",
"puppeteer": "^1.9.0",
"puppeteer-core": "^1.9.0",
"raven": "^2.6.4",
"readall": "1.1.0",
"redis": "2.8.0",
Expand Down
3 changes: 1 addition & 2 deletions utils/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const config = require('../config');
const puppeteer = require('puppeteer');

const options = {
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-infobars', '--window-position=0,0', '--ignore-certifcate-errors', '--ignore-certifcate-errors-spki-list', `--user-agent=${config.ua}`],
Expand All @@ -10,12 +11,10 @@ const options = {
module.exports = async () => {
let browser;
if (config.puppeteerWSEndpoint) {
const puppeteer = require('puppeteer-core');
browser = await puppeteer.connect({
browserWSEndpoint: config.puppeteerWSEndpoint,
});
} else {
const puppeteer = require('puppeteer');
browser = await puppeteer.launch(options);
}

Expand Down

0 comments on commit 88883f0

Please sign in to comment.