From d2cb41206e4ec5f27d860aa84607336f36b2258c Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Fri, 27 Mar 2020 19:37:27 +0100 Subject: [PATCH 1/4] Use docker image suited for puppeteer --- .teamcity/settings.kts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.teamcity/settings.kts b/.teamcity/settings.kts index 606cfab6fcef..2826c1006979 100644 --- a/.teamcity/settings.kts +++ b/.teamcity/settings.kts @@ -178,20 +178,13 @@ object ExamplesTemplate : Template({ #!/bin/bash set -e -x - sudo apt-get install -yq \ - gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ - libexpat1 libfontconfig1 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 - yarn install rm -rf built-storybooks mkdir -p built-storybooks yarn build-storybooks """.trimIndent() - dockerImage = "node:10" + dockerImage = "buildkite/puppeteer" dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux } } From d6e1cd1732957dd5ebe6e8cb62530b1714c7c4f3 Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Fri, 27 Mar 2020 20:02:27 +0100 Subject: [PATCH 2/4] Fix browser availablility check --- lib/cli/src/extract.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/cli/src/extract.js b/lib/cli/src/extract.js index 247c9705de32..20ee5e97e445 100644 --- a/lib/cli/src/extract.js +++ b/lib/cli/src/extract.js @@ -6,8 +6,7 @@ import getPort from 'get-port'; import { logger } from '@storybook/node-logger'; const read = async url => { - const puppeteer = await usePuppeteer(); - const browser = await puppeteer.launch(); + const browser = await usePuppeteerBrowser(); const page = await browser.newPage(); await page.goto(url); @@ -75,12 +74,9 @@ const useLocation = async input => { }); }; -const usePuppeteer = async () => { +const usePuppeteerBrowser = () => { try { - // eslint-disable-next-line import/no-extraneous-dependencies, global-require - require('puppeteer'); - - return puppeteerCore; + return puppeteerCore.launch(); } catch (e) { // it's not installed logger.info('installing puppeteer...'); @@ -88,7 +84,7 @@ const usePuppeteer = async () => { // eslint-disable-next-line global-require require('child_process').exec( `node ${require.resolve(path.join('puppeteer-core', 'install.js'))}`, - error => (error ? reject(error) : resolve(puppeteerCore)) + error => (error ? reject(error) : resolve(puppeteerCore.launch())) ); }); } From dc19dfab80fb6d7997cc2b0e3cfa9b30b4ad398b Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Fri, 27 Mar 2020 20:17:49 +0100 Subject: [PATCH 3/4] Catch the error properly --- lib/cli/src/extract.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/extract.js b/lib/cli/src/extract.js index 20ee5e97e445..514c379364db 100644 --- a/lib/cli/src/extract.js +++ b/lib/cli/src/extract.js @@ -74,9 +74,9 @@ const useLocation = async input => { }); }; -const usePuppeteerBrowser = () => { +const usePuppeteerBrowser = async () => { try { - return puppeteerCore.launch(); + return await puppeteerCore.launch(); } catch (e) { // it's not installed logger.info('installing puppeteer...'); From 06f0114d7a16b03bc2109977fe7f0e5ef74c80f3 Mon Sep 17 00:00:00 2001 From: Filipp Riabchun Date: Fri, 27 Mar 2020 20:35:35 +0100 Subject: [PATCH 4/4] Pass args to puppeteer.launch --- lib/cli/src/extract.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/extract.js b/lib/cli/src/extract.js index 514c379364db..40a312b9e474 100644 --- a/lib/cli/src/extract.js +++ b/lib/cli/src/extract.js @@ -75,8 +75,9 @@ const useLocation = async input => { }; const usePuppeteerBrowser = async () => { + const args = ['--no-sandbox ', '--disable-setuid-sandbox']; try { - return await puppeteerCore.launch(); + return await puppeteerCore.launch({ args }); } catch (e) { // it's not installed logger.info('installing puppeteer...'); @@ -84,7 +85,7 @@ const usePuppeteerBrowser = async () => { // eslint-disable-next-line global-require require('child_process').exec( `node ${require.resolve(path.join('puppeteer-core', 'install.js'))}`, - error => (error ? reject(error) : resolve(puppeteerCore.launch())) + error => (error ? reject(error) : resolve(puppeteerCore.launch({ args }))) ); }); }