Skip to content

Commit 4d8208e

Browse files
authored
Add files via upload
0 parents  commit 4d8208e

File tree

6 files changed

+294
-0
lines changed

6 files changed

+294
-0
lines changed

Dockerfile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
FROM centos:7
2+
3+
MAINTAINER gergokee
4+
5+
LABEL Remarks="This is a dockerfile example for puppeteer on Centos 6"
6+
7+
#login as root to perform yum
8+
USER root
9+
RUN yum -y update && \
10+
11+
##We don't need apache:
12+
##yum -y install httpd && \
13+
14+
yum clean all
15+
16+
RUN yum -y install sudo
17+
RUN yum -y install wget
18+
RUN yum -y install gcc-c++ make
19+
RUN curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -
20+
RUN yum -y install -y nodejs
21+
RUN curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
22+
RUN yum -y install yarn
23+
24+
# Install puppeteer
25+
RUN npm i puppeteer
26+
27+
# If running Docker >= 1.13.0 use docker run's --init arg to reap zombie processes, otherwise
28+
# uncomment the following lines to have `dumb-init` as PID 1
29+
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
30+
RUN chmod +x /usr/local/bin/dumb-init
31+
32+
#Install missing Chromium dependencies:
33+
RUN yum -y install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc
34+
RUN npm -y install --save puppeteer
35+
36+
#chrome-sandbox hack:
37+
#RUN cd /node_modules/puppeteer/.local-chromium/linux-*/chrome-linux && mv chrome_sandbox chrome-sandbox && chown root chrome-sandbox && chmod 4755 chrome-sandbox
38+
39+
40+
ENV NODE_PATH="/usr/lib/node_modules:${NODE_PATH}"
41+
ENV PATH="/tools:${PATH}"
42+
43+
44+
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser
45+
46+
COPY ./tools /tools
47+
48+
# Set language to UTF8
49+
ENV LANG="C.UTF-8"
50+
51+
WORKDIR /app
52+
53+
# Add user so we don't need --no-sandbox.
54+
RUN mkdir /screenshots \
55+
&& mkdir -p /home/pptruser/Downloads \
56+
&& chown -R pptruser:pptruser /home/pptruser \
57+
&& chown -R pptruser:pptruser /usr/lib/node_modules \
58+
&& chown -R pptruser:pptruser /screenshots \
59+
&& chown -R pptruser:pptruser /app \
60+
&& chown -R pptruser:pptruser /tools
61+
62+
# Run everything after as non-privileged user, for security reasons !!!
63+
USER pptruser
64+
65+
# --cap-add=SYS_ADMIN
66+
# https://docs.docker.com/engine/reference/run/#additional-groups
67+
68+
ENTRYPOINT ["dumb-init", "--"]
69+
70+
71+
72+
CMD ["node", "index.js"]
73+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 alekzonder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Centos 6 puppeteer docker image
2+
3+
docker image with [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) installed for **Centos 6 only**
4+
5+
If you can, please use Centos 7 or higher but cause Centos 6 is EOL. Otherwise you can use this tool for Centos6.
6+
7+
Repo is based on [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) and [alekzonder/docker-puppeteer] (https://github.com/alekzonder/docker-puppeteer)
8+
9+
## install
10+
11+
```
12+
docker pull gergokee/centos6-puppeteer:latest
13+
14+
```
15+
16+
## before usage
17+
18+
19+
1. You should **not** pass `--no-sandbox, --disable-setuid-sandbox` args when launching it, only if there is no other way, when you need to run it as **root** (which is not recommended).
20+
21+
```js
22+
const puppeteer = require('puppeteer');
23+
24+
(async () => {
25+
26+
console.info("Starting browser");
27+
28+
let browser;
29+
30+
try {
31+
32+
browser = await puppeteer.launch({});
33+
34+
} catch (e) {
35+
36+
console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
37+
browser = await puppeteer.launch({args:[
38+
'--no-sandbox',
39+
'--disable-setuid-sandbox'
40+
]});
41+
42+
}
43+
44+
console.info("Browser successfully started");
45+
console.info("Closing browser");
46+
47+
await browser.close();
48+
49+
console.info("Done");
50+
51+
})();
52+
```
53+
54+
2. If you see errors like "ERR_NETWORK_CHANGED", write your script to check the output of it and make a loop till the output is not generating errors. Unfortunately the problem is that IPV6 needs to be turned off. And because latest docker for Centos 6 is docker v1.7, you are unable to pass the necessary flag: **--sysctl net.ipv6.conf.all.disable_ipv6=1**
55+
56+
57+
3. add `--enable-logging` for chrome debug logging http://www.chromium.org/for-testers/enable-logging
58+
59+
```js
60+
const puppeteer = require('puppeteer');
61+
62+
(async() => {
63+
64+
const browser = await puppeteer.launch({args: [
65+
'--no-sandbox',
66+
'--disable-setuid-sandbox',
67+
68+
// debug logging
69+
'--enable-logging', '--v=1'
70+
]});
71+
(async () => {
72+
73+
console.info("Starting browser");
74+
75+
let browser;
76+
77+
try {
78+
79+
browser = await puppeteer.launch({args: [
80+
'--enable-logging', '--v=1'
81+
]});
82+
83+
} catch (e) {
84+
85+
console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
86+
browser = await puppeteer.launch({args:[
87+
'--no-sandbox',
88+
'--disable-setuid-sandbox',
89+
'--enable-logging', '--v=1'
90+
]});
91+
92+
}
93+
94+
console.info("Browser successfully started");
95+
console.info("Closing browser");
96+
97+
await browser.close();
98+
99+
console.info("Done");
100+
101+
})();
102+
103+
104+
```
105+
106+
## usage
107+
108+
### mount your script to /app/index.js
109+
110+
```bash
111+
docker run --rm -v <path_to_script>:/app/index.js gergokee/centos6-puppeteer:latest
112+
```
113+
114+
### custom script from dir
115+
116+
```bash
117+
docker run --rm \
118+
-v <path_to_dir>:/app \
119+
gergokee/centos6-puppeteer:latest \
120+
node my_script.js
121+
```

examples/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
const puppeteer = require('puppeteer');
3+
const fs = require('fs');
4+
(async () => {
5+
console.info("Starting browser");
6+
let browser;
7+
try {
8+
browser = await puppeteer.launch({});
9+
} catch (e) {
10+
console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
11+
browser = await puppeteer.launch({args:['--no-sandbox','--disable-setuid-sandbox']});
12+
}
13+
console.info("Browser successfully started");
14+
console.info("Closing browser");
15+
await browser.close();
16+
console.info("Done");
17+
})();

gitignore

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+

sh/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker build -t gergokee/centos6-puppeteer:latest .

0 commit comments

Comments
 (0)