Tries to replace google-chrome headless with puppeteer

parent 59ed780b
Pipeline #21898 passed with stages
in 9 minutes and 50 seconds
...@@ -63,11 +63,6 @@ generate_assets: ...@@ -63,11 +63,6 @@ generate_assets:
dependencies: dependencies:
- build - build
script: script:
- curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
- apt-get -y update
- apt-get -y install --allow-unauthenticated google-chrome-stable imagemagick libpng-dev zlib1g-dev clang
- export CHROME_BIN=`whereis google-chrome | cut -d " " -f 2`
- npm install - npm install
- cd dist - cd dist
- node server & - node server &
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"prod-test:SSR": "npm run build:SSR && npm run job && npm run start:SSR", "prod-test:SSR": "npm run build:SSR && npm run job && npm run start:SSR",
"job": "npm run job:images; npm run job:link; npm run job:manifest", "job": "npm run job:images; npm run job:link; npm run job:manifest",
"job:images:logo": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=generateLogoImages", "job:images:logo": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=generateLogoImages",
"job:images:frontend": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=generateFrontendPreview --host=http://localhost:4000", "job:images:frontend": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=generateFrontendPreview --host=http://localhost:4210",
"job:images": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=all --host=http://localhost:4000", "job:images": "cd dist/browser/assets/jobs/; node --experimental-modules GenerateImages.mjs --command=all --host=http://localhost:4000",
"job:link": "cd dist/browser/assets/jobs/; node GenerateMetaNodes.js --command=generateLinkImages --baseUrl=http://localhost:4000", "job:link": "cd dist/browser/assets/jobs/; node GenerateMetaNodes.js --command=generateLinkImages --baseUrl=http://localhost:4000",
"job:manifest": "cd dist/browser/assets/jobs/; node GenerateMetaNodes.js --command=generateManifest --baseUrl=http://localhost:4000" "job:manifest": "cd dist/browser/assets/jobs/; node GenerateMetaNodes.js --command=generateManifest --baseUrl=http://localhost:4000"
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
"minimist": "^1.2.0", "minimist": "^1.2.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"protractor": "^5.4.1", "protractor": "^5.4.1",
"puppeteer": "^1.11.0",
"purify-css": "~1.2.5", "purify-css": "~1.2.5",
"sharp": "^0.21.0", "sharp": "^0.21.0",
"ts-node": "~7.0.1", "ts-node": "~7.0.1",
......
...@@ -7,7 +7,6 @@ import themeData from '../themeData'; ...@@ -7,7 +7,6 @@ import themeData from '../themeData';
import process from 'process'; import process from 'process';
import child_process from 'child_process'; import child_process from 'child_process';
import minimist from 'minimist'; import minimist from 'minimist';
import {default as chromeLauncher} from 'chrome-launcher';
import {default as imagemin} from 'imagemin'; import {default as imagemin} from 'imagemin';
import {default as imageminPngquant} from 'imagemin-pngquant'; import {default as imageminPngquant} from 'imagemin-pngquant';
...@@ -71,8 +70,6 @@ class GenerateImages { ...@@ -71,8 +70,6 @@ class GenerateImages {
} }
async generateFrontendPreview(host) { async generateFrontendPreview(host) {
const CHROME_BIN = process.env.CHROME_BIN;
const flags = ['--headless', '--hide-scrollbars', '--no-sandbox', '--remote-debugging-port=9222', '--disable-gpu', '--user-data-dir=remote-profile'];
const params = []; const params = [];
const themePreviewEndpoint = `${host}/preview`; const themePreviewEndpoint = `${host}/preview`;
themes.forEach((theme) => { themes.forEach((theme) => {
...@@ -81,22 +78,8 @@ class GenerateImages { ...@@ -81,22 +78,8 @@ class GenerateImages {
}); });
}); });
if (await this.isRunning(CHROME_BIN, CHROME_BIN, CHROME_BIN)) {
throw new Error('Chrome instance already running');
}
const chromeInstance = await chromeLauncher.launch({
startingUrl: 'https://google.com',
chromeFlags: flags,
chromePath: CHROME_BIN,
port: 9222
});
console.log(`Chrome debugging port running on ${chromeInstance.port}`);
console.log('chrome stuff', CHROME_BIN, themePreviewEndpoint, params);
// const chromeInstance = child_process.spawnSync(CHROME_BIN, flags);
const chromeDriver = child_process.spawn(`node`, [ const chromeDriver = child_process.spawn(`node`, [
path.join('ChromeDriver.js'), `--urls=${JSON.stringify(params)} --full --delay=100` path.join('puppeteer.js'), `--urls=${JSON.stringify(params)}`
]); ]);
chromeDriver.stdout.on('data', (data) => { chromeDriver.stdout.on('data', (data) => {
...@@ -107,7 +90,6 @@ class GenerateImages { ...@@ -107,7 +90,6 @@ class GenerateImages {
}); });
chromeDriver.on('exit', (code, signal) => { chromeDriver.on('exit', (code, signal) => {
console.log(`ChromeDriver: Done. Exit ${!!code ? 'code' : 'signal'} was: ${!!code ? code : signal}`); console.log(`ChromeDriver: Done. Exit ${!!code ? 'code' : 'signal'} was: ${!!code ? code : signal}`);
chromeInstance.kill();
}); });
} }
......
const puppeteer = require('puppeteer');
const path = require('path');
const file = require('fs');
const argv = require('minimist')(process.argv.slice(2));
const urls = argv.urls ? JSON.parse(argv.urls) : [argv.url || 'https://www.google.com'];
const format = argv.format === 'png' ? 'png' : 'jpeg';
const viewportWidth = argv.viewportWidth || 1024;
const viewportHeight = argv.viewportHeight || 768;
const delay = argv.delay || 0;
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const host = /localhost/.test(urls[0]) ?
'localhost' : /staging.arsnova.click/.test(urls[0]) ?
'staging.arsnova.click' : /beta.arsnova.click/.test(urls[0]) ?
'beta.arsnova.click' : /arsnova.click/.test(urls[0]) ?
'arsnova.click' : '';
await page.setCookie({
'name': 'cookieconsent_status',
'value': 'dismiss',
'domain': host,
'path': '/',
'expires': (new Date()).getTime() + (1000 * 60 * 60)
});
for (let i = 0; i < urls.length; i++) {
const url = urls[i];
await page.goto(url, {waitUntil: 'networkidle0'});
console.log('navigated to ', url);
const urlSeparated = url.split('/');
const themeImage = path.join(urlSeparated[urlSeparated.length - 2], 'preview_' + urlSeparated[urlSeparated.length - 1] + '.' + format);
const imgPath = path.join(__dirname, '..', 'images', 'theme', themeImage);
await page.screenshot({path: imgPath});
}
await browser.close();
})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment