业务场景:通过node.js + puppeteer 框架进行无界面化浏览器截图
puppeteer 参考资料:https://github.com/puppeteer/puppeteer
参考资料:
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
https://github.com/puppeteer/puppeteer
# 用node:12 制作一个puppeter的私有镜像
FROM node:12
RUN apt-get update && \
apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /home/puppeter/Downloads
综合使用方案
node.js egg.js puppeteer docker打包镜像Dokerfile 脚本
#方案1 待测试
FROM node:12-alpine
ENV NODE_ENV=production
ENV CHROME_BIN="/usr/bin/chromium-browser"\
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
RUN set -x \
&& apk update \
&& apk upgrade \
# replacing default repositories with edge ones
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
\
# Add the packages
&& apk add --no-cache dumb-init curl make gcc g++ python2 linux-headers binutils-gold gnupg libstdc++ nss chromium \
\
&& npm install puppeteer@0.13.0 \
\
# Do some cleanup
&& apk del --no-cache make gcc g++ python binutils-gold gnupg libstdc++ \
&& rm -rf /usr/include \
&& rm -rf /var/cache/apk/* /root/.node-gyp /usr/share/man /tmp/* \
&& echo
CMD /usr/bin/dumb-init
WORKDIR /app
COPY release.tgz /app/
RUN tar -xvf /app/release.tgz
RUN rm -r /app/release.tgz
RUN rm -r /app/node_modules
RUN npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
RUN npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
RUN npm install sharp
RUN npm i puppeteer -save
RUN npm install --production --loglevel verbose
EXPOSE 7001
ENTRYPOINT ["npm","run","start"]
## 方案2
## dome
## node.js + puppeteer 生成截图的 docker打包镜像脚本
# FROM node:12
# ENV NODE_ENV=production
# WORKDIR /app
# COPY [".npmrc", "package.json", "package-lock.json", "./"]
# 安装一些puppeteer基础依赖 ps:尽量采用外网访问走代理
# RUN apt-get update && \
# apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
# libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
# libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
# libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
# libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
# rm -rf /var/lib/apt/lists/*
# RUN mkdir -p /home/pptruser/Downloads
# 通过npm去安装依赖包 ps:之所以要在这里处理因为遇到了镜像缓慢问题
# RUN npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
# RUN npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
# RUN npm install sharp
# RUN npm install --production --loglevel verbose
# COPY ["config", "./config/"]
# COPY ["app", "./app/"]
# EXPOSE 7001
# ENTRYPOINT ["npm","run","start"]
# 方案3
FROM 9034xxxxx/node-puppeteer:latest
ENV NODE_ENV=production
WORKDIR /app
COPY release.tgz /app/
RUN tar -xvf /app/release.tgz
RUN rm -r /app/release.tgz
RUN rm -r /app/node_modules
RUN npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" \
&& npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" \
&& npm config set puppeteer_host "https://npm.taobao.org/mirrors"
RUN npm install sharp \
&& npm i puppeteer -save \
&& npm install --production --loglevel verbose
EXPOSE 7001
ENTRYPOINT ["npm","run","start"]

该博客介绍业务场景为利用 Node.js 和 Puppeteer 框架进行无界面化浏览器截图,还给出了 Puppeteer 的参考资料,包括其 GitHub 仓库及相关故障排除文档,还有在 Docker 中使用的文章,提供了综合使用方案。
411

被折叠的 条评论
为什么被折叠?



