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

chore: bump node to 10 and puppeteer to 1.10 #34

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 17 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
FROM node:8-slim

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 yarn global add puppeteer@1.8.0 && yarn cache clean

ENV NODE_PATH="/usr/local/share/.config/yarn/global/node_modules:${NODE_PATH}"

ENV PATH="/tools:${PATH}"

RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser

COPY --chown=pptruser:pptruser ./tools /tools

# Set language to UTF8
ENV LANG="C.UTF-8"
FROM node:10-slim

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 git-core \
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/* \
&& yarn global add puppeteer@1.11.0 \
&& yarn cache clean

WORKDIR /app

# Add user so we don't need --no-sandbox.
RUN mkdir /screenshots \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /usr/local/share/.config/yarn/global/node_modules \
&& chown -R pptruser:pptruser /screenshots \
&& chown -R pptruser:pptruser /app \
&& chown -R pptruser:pptruser /tools

# Run everything after as non-privileged user.
USER pptruser

# --cap-add=SYS_ADMIN
# https://docs.docker.com/engine/reference/run/#additional-groups

ENTRYPOINT ["dumb-init", "--"]

# CMD ["/usr/local/share/.config/yarn/global/node_modules/puppeteer/.local-chromium/linux-526987/chrome-linux/chrome"]

CMD ["node", "index.js"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 alekzonder
Copyright (c) 2018 Daniel Iñigo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
178 changes: 2 additions & 176 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,179 +1,5 @@
# puppeteer docker image

docker image with [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) installed
Docker image with [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) installed.

and [screenshots scripts](#screenshots-tools)

[![nodesource/node](http://dockeri.co/image/alekzonder/puppeteer)](https://hub.docker.com/r/alekzonder/puppeteer/)

## docker tags

- `latest`
- `1`
- `1.1.1`
- `1.1.0`
- `1.0.0`
- `0`
- `0.13.0`
- `0.12.0`
- `0.11.0`
- `0.10.2`
- `0.10.1`
- `0.10.0`
- `0.9.0`

## install

```
docker pull alekzonder/puppeteer:latest
# OR
docker pull alekzonder/puppeteer:1.0.0
# OR
docker pull alekzonder/puppeteer:1

```

## before usage


1. you should pass `--no-sandbox, --disable-setuid-sandbox` args when launch browser

```js
const puppeteer = require('puppeteer');

(async() => {

const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
});

const page = await browser.newPage();

await page.goto('https://www.google.com/', {waitUntil: 'networkidle2'});

browser.close();

})();
```

2. if you got page crash with `BUS_ADRERR` ([chromium issue](https://bugs.chromium.org/p/chromium/issues/detail?id=571394)), increase shm-size on docker run with `--shm-size` argument

```bash
docker run --shm-size 1G --rm -v <path_to_script>:/app/index.js alekzonder/puppeteer:latest
```

3. If you're seeing random navigation errors (unreachable url) it's likely due to ipv6 being enabled in docker. Navigation errors are caused by ERR_NETWORK_CHANGED (-21) in chromium. Disable ipv6 in your container using `--sysctl net.ipv6.conf.all.disable_ipv6=1` to fix:
```bash
docker run --shm-size 1G --sysctl net.ipv6.conf.all.disable_ipv6=1 --rm -v <path_to_script>:/app/index.js alekzonder/puppeteer:latest
```

4. add `--enable-logging` for chrome debug logging http://www.chromium.org/for-testers/enable-logging

```js
const puppeteer = require('puppeteer');

(async() => {

const browser = await puppeteer.launch({args: [
'--no-sandbox',
'--disable-setuid-sandbox',

// debug logging
'--enable-logging', '--v=1'
]});


```


## usage

### mount your script to /app/index.js

```bash
docker run --shm-size 1G --rm -v <path_to_script>:/app/index.js alekzonder/puppeteer:latest
```

### custom script from dir

```bash
docker run --shm-size 1G --rm \
-v <path_to_dir>:/app \
alekzonder/puppeteer:latest \
node my_script.js
```

## screenshots tools

simple screenshot tools in image

```bash
docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
alekzonder/puppeteer:latest \
<screenshot,full_screenshot,screenshot_series,full_screenshot_series> 'https://www.google.com' 1366x768
```

### screenshot tools syntax

`<tool> <url> <width>x<height> [<delay_in_ms>]`

* `delay_in_ms`: is optional (defaults to `0`)
* Waits for `delay_in_ms` milliseconds before taking the screenshot

### `screenshot`

```bash
docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
alekzonder/puppeteer:latest \
screenshot 'https://www.google.com' 1366x768
```

output: one line json

```
{
"date":"2017-09-01T05:03:27.464Z",
"timestamp":1504242207,
"filename":"screenshot_1366_768.png",
"width":1366,
"height":768
}
```
got screenshot in /tmp/screenshots/screenshot_1366_768.png

### `full_screenshot`

save full screenshot of page

```bash
docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
alekzonder/puppeteer:latest \
full_screenshot 'https://www.google.com' 1366x768
```

### `screenshot_series`, `full_screenshot_series`

adds datetime in ISO format into filename

useful for cron screenshots

```bash
docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
alekzonder/puppeteer:latest \
screenshot_series 'https://www.google.com' 1366x768
```

```bash
docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
alekzonder/puppeteer:latest \
full_screenshot_series 'https://www.google.com' 1366x768
```

```
2017-09-01T05:08:55.027Z_screenshot_1366_768.png
# OR
2017-09-01T05:08:55.027Z_full_screenshot_1366_768.png
```
[![nodesource/node](http://dockeri.co/image/dinigo/puppeteer)](https://hub.docker.com/r/dinigo/puppeteer/)
20 changes: 0 additions & 20 deletions examples/google-screenshot.js

This file was deleted.

3 changes: 0 additions & 3 deletions sh/build.sh

This file was deleted.

89 changes: 0 additions & 89 deletions tools/fullScreenshot.js

This file was deleted.

Loading