Skip to content

Commit 629405e

Browse files
authored
Switch docker base to node:10-alpine (#36)
1 parent 8d0a3b2 commit 629405e

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.circleci
2+
docker
3+
node_modules
4+
scripts
5+
Dockerfile
6+
Makefile
7+
plugin_start*

Dockerfile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
FROM node:10 AS base
1+
FROM node:10-alpine AS base
2+
3+
ENV CHROME_BIN="/usr/bin/chromium-browser"
4+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
25

36
WORKDIR /usr/src/app
47

5-
RUN apt-get update && \
6-
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
7-
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
8-
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
9-
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
10-
fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
11-
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
12-
wget https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64.deb && \
13-
dpkg -i dumb-init_*.deb && rm -f dumb-init_*.deb && \
14-
apt-get clean && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
8+
RUN \
9+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
10+
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
11+
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
12+
&& apk --no-cache update \
13+
&& apk --no-cache upgrade \
14+
&& apk add --no-cache --virtual .build-deps \
15+
udev ttf-opensans chromium \
16+
ca-certificates dumb-init \
17+
&& rm -rf /var/cache/apk/* /tmp/*
1518

1619
FROM base as build
1720

18-
RUN npm install -g typescript
19-
2021
COPY . ./
2122

22-
RUN yarn install --pure-lockfile && \
23-
yarn run build
23+
RUN yarn install --pure-lockfile
24+
RUN yarn run build
2425

2526
EXPOSE 8081
2627

src/browser.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { Logger } from './logger';
55
import uniqueFilename = require('unique-filename');
66

77
export class Browser {
8-
9-
constructor(private log: Logger) {
10-
}
8+
constructor(private log: Logger) {}
119

1210
validateOptions(options) {
1311
options.width = parseInt(options.width) || 1000;
@@ -36,7 +34,7 @@ export class Browser {
3634

3735
if ((process as any).pkg) {
3836
const parts = puppeteer.executablePath().split(path.sep);
39-
while(!parts[0].startsWith('chrome-')) {
37+
while (!parts[0].startsWith('chrome-')) {
4038
parts.shift();
4139
}
4240
const executablePath = [path.dirname(process.execPath), ...parts].join(path.sep);
@@ -47,10 +45,18 @@ export class Browser {
4745
args: ['--no-sandbox'],
4846
});
4947
} else {
50-
browser = await puppeteer.launch({
51-
env: env,
52-
args: ['--no-sandbox'],
53-
});
48+
if (env['CHROME_BIN']) {
49+
browser = await puppeteer.launch({
50+
executablePath: env['CHROME_BIN'],
51+
env: env,
52+
args: ['--no-sandbox'],
53+
});
54+
} else {
55+
browser = await puppeteer.launch({
56+
env: env,
57+
args: ['--no-sandbox'],
58+
});
59+
}
5460
}
5561
page = await browser.newPage();
5662

@@ -61,29 +67,32 @@ export class Browser {
6167
});
6268

6369
await page.setCookie({
64-
'name': 'renderKey',
65-
'value': options.renderKey,
66-
'domain': options.domain,
70+
name: 'renderKey',
71+
value: options.renderKey,
72+
domain: options.domain,
6773
});
6874

6975
await page.goto(options.url);
7076

7177
// wait for all panels to render
72-
await page.waitForFunction(() => {
73-
const panelCount = document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
74-
return (<any>window).panelsRendered >= panelCount;
75-
}, {
76-
timeout: options.timeout * 1000
77-
});
78+
await page.waitForFunction(
79+
() => {
80+
const panelCount =
81+
document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
82+
return (<any>window).panelsRendered >= panelCount;
83+
},
84+
{
85+
timeout: options.timeout * 1000,
86+
}
87+
);
7888

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

83-
await page.screenshot({path: options.filePath});
93+
await page.screenshot({ path: options.filePath });
8494

8595
return { filePath: options.filePath };
86-
8796
} finally {
8897
if (page) {
8998
await page.close();
@@ -94,4 +103,3 @@ export class Browser {
94103
}
95104
}
96105
}
97-

0 commit comments

Comments
 (0)