8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Puppeteer実行環境をAppEngineからCloudRunに移したときのメモ

Posted at

 FlightBooksというサービスを個人で開発していまして、先日ghostscriptの情報を教えてもらいました。現状PDFの生成部分はGoogle AppEngineのStandard Node環境でPuppeteerが動作していて、この部分をCloudRunに移植しつつ、gsコマンドと両方入ってる環境を作ろうと思いました。この辺毎回ググることになりそうなのでメモとして残そうと思います。

Chromeはaptでインストールする

今回ベースイメージは、node:12-slimを選択してみました。そのためOSイメージはdebian stretchになります。当初npmでPuppeteerをインストールしていたのですが、依存ライブラリの解決が面倒だったので、aptでインストールすることにしました。Chromeにはいくつかバージョンがありますが、こちらのRepoをみて本家のStable版をインストールすることにしました。

RUN  apt-get update \
     && apt-get install -y wget gnupg ca-certificates \
     && 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 \

Puppeteerをpuppeteer-coreにする

Chromeは既にインストール済みのため、バイナリイメージを含まないnpmモジュールをインストールします。

$ npm remove puppeteer
$ npm install --save puppeteer-core

必要なフォントとfontconfigを入れる

日本語対応したいので、noto fontを全面的に活用することにします。明朝体もインストールするためextraもstretch-backportsを利用していれます。英字は逆に最低限のみで、MS系互換フォントの fonts-liberation を利用します。

&& echo 'deb http://deb.debian.org/debian stretch-backports main' >> /etc/apt/sources.list \
    && apt update \
    && apt install -y fonts-noto-cjk-extra -t stretch-backports \
    && apt install -y google-chrome-stable fontconfig fonts-liberation fonts-noto-cjk \

Puppeteer.launchでパスを指定

puppeteer-coreにしたので、Chromeの実行パスを指定する必要があります。

# which google-chrome-stable
/usr/bin/google-chrome-stable

const browser = await puppeteer.launch({
  executablePath: '/usr/bin/google-chrome-stable'
});

以上で、無事CloudRun移植に必要なDockerfileのベースが出来上がりました。これをもとに追加の設定を入れ込んでみたいと思います。

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?