用node:12 制作一个puppeteer的私有镜像

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

业务场景:通过node.js + puppeteer 框架进行无界面化浏览器截图

puppeteer 参考资料:https://github.com/puppeteer/puppeteer

参考资料: 

https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

https://github.com/puppeteer/puppeteer

https://medium.com/@christopher.talke/using-node-puppeteer-with-docker-without-wanting-to-smash-your-keyboard-ed78e9529a8b

# 用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"]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值