From 02d2a9592f44b14fadc7d4ac18fe10fddb966871 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Mon, 6 Aug 2018 15:02:42 -0700 Subject: [PATCH] Docker puppeteer work around (revert this later) - Tracked at https://github.com/dawnlabs/carbon/issues/451 --- Dockerfile | 17 +++++++++++------ handlers/image.js | 2 +- package.json | 2 +- server.js | 3 ++- yarn.lock | 14 +++++--------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b9392a..ae21a8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,23 @@ FROM node:9-alpine -# Installs latest Chromium (63) package. +# Source https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md +# Installs latest Chromium (68) package. +ENV CHROME_BIN=/usr/bin/chromium-browser RUN apk update && apk upgrade && \ - echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \ - echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \ + echo @v3.8 http://nl.alpinelinux.org/alpine/v3.8/community >> /etc/apk/repositories && \ + echo @v3.8 http://nl.alpinelinux.org/alpine/v3.8/main >> /etc/apk/repositories && \ apk add --no-cache \ - chromium@edge \ - nss@edge + chromium@v3.8 \ + nss@v3.8 WORKDIR /app COPY package.json ./ COPY yarn.lock ./ +# Tell Puppeteer to skip installing Chrome. We'll be using the installed package. +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true + RUN yarn COPY . . @@ -30,4 +35,4 @@ USER pptruser ENV NODE_ENV production EXPOSE 3000 -CMD [ "yarn", "start" ] \ No newline at end of file +CMD [ "yarn", "start" ] diff --git a/handlers/image.js b/handlers/image.js index 8480d75..7bdeab0 100644 --- a/handlers/image.js +++ b/handlers/image.js @@ -17,7 +17,7 @@ module.exports = browser => async (req, res) => { const targetElement = await page.$('#export-container') - const dataUrl = await page.evaluate(target => { + const dataUrl = await page.evaluate((target = document) => { const config = { style: { transform: 'scale(2)', diff --git a/package.json b/package.json index c1509a2..1fcdfa0 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "ms": "^2.0.0", "next": "^6.0.3", "now-logs": "^0.0.7", - "puppeteer": "^1.0.0", + "puppeteer": "0.13.x", "react": "16.3.*", "react-click-outside": "^3.0.0", "react-codemirror2": "^5.0.0", diff --git a/server.js b/server.js index 809e932..ebb9d58 100644 --- a/server.js +++ b/server.js @@ -29,7 +29,8 @@ const puppeteerParams = dev ? {} : { executablePath: '/usr/bin/chromium-browser', - args: ['--no-sandbox', '--disable-setuid-sandbox'] + // TODO args: ['--no-sandbox', '--disable-setuid-sandbox'] + args: ['--no-sandbox', '--headless', '--disable-gpu'] } app diff --git a/yarn.lock b/yarn.lock index e0eab27..36cdb22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4514,10 +4514,6 @@ mime@^1.3.4: version "1.6.0" resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" -mime@^2.0.3: - version "2.3.1" - resolved "https://registry.yarnpkg.com/mime/-/mime-2.3.1.tgz#b1621c54d63b97c47d3cfe7f7215f7d64517c369" - mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" @@ -5683,14 +5679,14 @@ punycode@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" -puppeteer@^1.0.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.4.0.tgz#437f0f3450d76e437185c0bf06f446e80f184692" +puppeteer@0.13.x: + version "0.13.0" + resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-0.13.0.tgz#2e6956205f2c640964c2107f620ae1eef8bde8fd" dependencies: - debug "^3.1.0" + debug "^2.6.8" extract-zip "^1.6.5" https-proxy-agent "^2.1.0" - mime "^2.0.3" + mime "^1.3.4" progress "^2.0.0" proxy-from-env "^1.0.0" rimraf "^2.6.1"