Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch docker base to node:10-alpine #36

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.circleci
docker
node_modules
scripts
Dockerfile
Makefile
plugin_start*
31 changes: 16 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
FROM node:10 AS base
FROM node:10-alpine AS base

ENV CHROME_BIN="/usr/bin/chromium-browser"
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

WORKDIR /usr/src/app

RUN apt-get update && \
apt-get install -yq gconf-service libasound2 libatk1.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 \
fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
wget https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64.deb && \
dpkg -i dumb-init_*.deb && rm -f dumb-init_*.deb && \
apt-get clean && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
RUN \
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --no-cache --virtual .build-deps \
udev ttf-opensans chromium \
ca-certificates dumb-init \
&& rm -rf /var/cache/apk/* /tmp/*

FROM base as build

RUN npm install -g typescript

COPY . ./

RUN yarn install --pure-lockfile && \
yarn run build
RUN yarn install --pure-lockfile
RUN yarn run build

EXPOSE 8081

Expand Down
48 changes: 28 additions & 20 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Logger } from './logger';
import uniqueFilename = require('unique-filename');

export class Browser {

constructor(private log: Logger) {
}
constructor(private log: Logger) {}

validateOptions(options) {
options.width = parseInt(options.width) || 1000;
Expand Down Expand Up @@ -36,7 +34,7 @@ export class Browser {

if ((process as any).pkg) {
const parts = puppeteer.executablePath().split(path.sep);
while(!parts[0].startsWith('chrome-')) {
while (!parts[0].startsWith('chrome-')) {
parts.shift();
}
const executablePath = [path.dirname(process.execPath), ...parts].join(path.sep);
Expand All @@ -47,10 +45,18 @@ export class Browser {
args: ['--no-sandbox'],
});
} else {
browser = await puppeteer.launch({
env: env,
args: ['--no-sandbox'],
});
if (env['CHROME_BIN']) {
browser = await puppeteer.launch({
executablePath: env['CHROME_BIN'],
env: env,
args: ['--no-sandbox'],
});
} else {
browser = await puppeteer.launch({
env: env,
args: ['--no-sandbox'],
});
}
}
page = await browser.newPage();

Expand All @@ -61,29 +67,32 @@ export class Browser {
});

await page.setCookie({
'name': 'renderKey',
'value': options.renderKey,
'domain': options.domain,
name: 'renderKey',
value: options.renderKey,
domain: options.domain,
});

await page.goto(options.url);

// wait for all panels to render
await page.waitForFunction(() => {
const panelCount = document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
return (<any>window).panelsRendered >= panelCount;
}, {
timeout: options.timeout * 1000
});
await page.waitForFunction(
() => {
const panelCount =
document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
return (<any>window).panelsRendered >= panelCount;
},
{
timeout: options.timeout * 1000,
}
);

if (!options.filePath) {
options.filePath = uniqueFilename(os.tmpdir()) + '.png';
}

await page.screenshot({path: options.filePath});
await page.screenshot({ path: options.filePath });

return { filePath: options.filePath };

} finally {
if (page) {
await page.close();
Expand All @@ -94,4 +103,3 @@ export class Browser {
}
}
}