diff options
author | Tim Lucas <t@toolmantim.com> | 2018-03-16 17:10:18 +1100 |
---|---|---|
committer | Tim Lucas <t@toolmantim.com> | 2018-03-16 17:10:18 +1100 |
commit | 98ecb0ea09c329f3c94ad072f8224fdd0d753bee (patch) | |
tree | 00b2b492b524c133f3fabce7f38c6076a4edb482 | |
parent | 6fc9024b9b39faf35b0dcbd38335c22ac78e55af (diff) | |
download | docker-puppeteer-98ecb0ea09c329f3c94ad072f8224fdd0d753bee.tar.gz docker-puppeteer-98ecb0ea09c329f3c94ad072f8224fdd0d753bee.tar.zst docker-puppeteer-98ecb0ea09c329f3c94ad072f8224fdd0d753bee.zip |
Remove the custom user and add example usage1.1.1
-rw-r--r-- | Dockerfile | 61 | ||||
-rw-r--r-- | README.md | 85 |
2 files changed, 94 insertions, 52 deletions
@@ -1,47 +1,20 @@ | |||
1 | # Copy and pasted from: | 1 | # A minimal Docker image with Node 8 and Puppeteer |
2 | # https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker | ||
3 | # | 2 | # |
4 | # The only change is locking it down to a specific version of Puppeteer in the | 3 | # Based upon: |
5 | # `npm install` line. | 4 | # https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker |
6 | 5 | ||
7 | FROM node:8-slim | 6 | FROM node:8-slim |
8 | 7 | ||
9 | # See https://crbug.com/795759 | 8 | RUN apt-get update \ |
10 | RUN apt-get update && apt-get install -yq libgconf-2-4 | 9 | # See https://crbug.com/795759 |
11 | 10 | && apt-get install -yq libgconf-2-4 \ | |
12 | # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others) | 11 | # Install latest chrome dev package, which installs the necessary libs to |
13 | # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer | 12 | # make the bundled version of Chromium that Puppeteer installs work. |
14 | # installs, work. | 13 | && apt-get install -y wget --no-install-recommends \ |
15 | RUN apt-get update && apt-get install -y wget --no-install-recommends \ | 14 | && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ |
16 | && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ | 15 | && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ |
17 | && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ | 16 | && apt-get update \ |
18 | && apt-get update \ | 17 | && apt-get install -y google-chrome-unstable --no-install-recommends \ |
19 | && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \ | 18 | && rm -rf /var/lib/apt/lists/* \ |
20 | --no-install-recommends \ | 19 | # Finally, install Puppeteer under /node_modules so it's available system-wide |
21 | && rm -rf /var/lib/apt/lists/* \ | 20 | && npm i puppeteer@1.1.1 \ No newline at end of file |
22 | && apt-get purge --auto-remove -y curl \ | ||
23 | && rm -rf /src/*.deb | ||
24 | |||
25 | # It's a good idea to use dumb-init to help prevent zombie chrome processes. | ||
26 | ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init | ||
27 | RUN chmod +x /usr/local/bin/dumb-init | ||
28 | |||
29 | # Uncomment to skip the chromium download when installing puppeteer. If you do, | ||
30 | # you'll need to launch puppeteer with: | ||
31 | # browser.launch({executablePath: 'google-chrome-unstable'}) | ||
32 | # ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true | ||
33 | |||
34 | # Install puppeteer so it's available in the container. | ||
35 | RUN npm i puppeteer@1.1.1 | ||
36 | |||
37 | # Add user so we don't need --no-sandbox. | ||
38 | RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \ | ||
39 | && mkdir -p /home/pptruser/Downloads \ | ||
40 | && chown -R pptruser:pptruser /home/pptruser \ | ||
41 | && chown -R pptruser:pptruser /node_modules | ||
42 | |||
43 | # Run everything after as non-privileged user. | ||
44 | USER pptruser | ||
45 | |||
46 | ENTRYPOINT ["dumb-init", "--"] | ||
47 | CMD ["google-chrome-unstable"] \ No newline at end of file | ||
@@ -1,17 +1,86 @@ | |||
1 | # Docker Puppeteer | 1 | # Docker Puppeteer |
2 | 2 | ||
3 | A Puppeteer Docker image based on [Puppeteer’s own recommendations](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker). | 3 | Node 8 + Puppeteer docker base image. Use it to add your own tools (such as a testing framework), configure any linked containers via your Docker Compose config, and run your Puppeteer scripts. |
4 | 4 | ||
5 | An example for how to use: | 5 | ## Usage example |
6 | |||
7 | Dockerfile.integration-tests: | ||
6 | 8 | ||
7 | ```Dockerfile | 9 | ```Dockerfile |
8 | FROM buildkite/puppeteer | 10 | FROM buildkite/puppeteer:1.1.1 |
11 | RUN npm i mocha@5 | ||
12 | ENV PATH="${PATH}:/node_modules/.bin" | ||
13 | ``` | ||
14 | |||
15 | docker-compose.integration-tests.yml: | ||
16 | |||
17 | ```yml | ||
18 | version: '3' | ||
19 | services: | ||
20 | tests: | ||
21 | build: | ||
22 | context: . | ||
23 | dockerfile: Dockerfile.integration-tests | ||
24 | volumes: | ||
25 | - "./integration-tests:/integration-tests" | ||
26 | - "/screenshots" | ||
27 | command: mocha --recursive /integration-tests | ||
28 | links: | ||
29 | - app | ||
30 | app: | ||
31 | image: tutum/hello-world | ||
32 | expose: | ||
33 | - "80" | ||
34 | ``` | ||
35 | |||
36 | integration-tests/index.test.js: | ||
37 | |||
38 | ```js | ||
39 | const assert = require('assert') | ||
40 | const puppeteer = require('puppeteer') | ||
9 | 41 | ||
10 | RUN npm install mocha | 42 | let browser |
11 | ENV PATH="${PATH}:/node_modules/.bin" | 43 | let page |
44 | |||
45 | before(async() => { | ||
46 | browser = await puppeteer.launch({ | ||
47 | args: [ | ||
48 | // Required for Docker version of Puppeteer | ||
49 | '--no-sandbox', | ||
50 | '--disable-setuid-sandbox', | ||
51 | // This will write shared memory files into /tmp instead of /dev/shm, | ||
52 | // because Docker’s default for /dev/shm is 64MB | ||
53 | '--disable-dev-shm-usage' | ||
54 | ] | ||
55 | }) | ||
56 | |||
57 | const browserVersion = await browser.version() | ||
58 | console.log(`Started ${browserVersion}`) | ||
59 | }) | ||
60 | |||
61 | beforeEach(async() => { | ||
62 | page = await browser.newPage() | ||
63 | }) | ||
64 | |||
65 | afterEach(async() => { | ||
66 | await page.close() | ||
67 | }) | ||
68 | |||
69 | after(async() => { | ||
70 | await browser.close() | ||
71 | }) | ||
72 | |||
73 | describe('App', () => { | ||
74 | it('renders', async() => { | ||
75 | const response = await page.goto('http://app/') | ||
76 | assert(response.ok()) | ||
77 | await page.screenshot({ path: `/screenshots/app.png` }) | ||
78 | }) | ||
79 | }) | ||
80 | ``` | ||
12 | 81 | ||
13 | # The `tests` dir is expected to be mounted into here | 82 | Running: |
14 | WORK_DIR /home/pptr | ||
15 | 83 | ||
16 | CMD ["mocha", "--recursive", "tests"] | ||
17 | ``` | 84 | ``` |
85 | docker-compose -f integration-tests run tests | ||
86 | ``` \ No newline at end of file | ||