aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Dockerfile6
-rw-r--r--README.md86
-rw-r--r--example/Dockerfile.integration-tests3
-rw-r--r--example/README.md17
-rw-r--r--example/docker-compose.integration-tests.yml16
-rw-r--r--example/integration-tests/index.test.js41
6 files changed, 87 insertions, 82 deletions
diff --git a/Dockerfile b/Dockerfile
index 0d53911..2e1d916 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -15,8 +15,10 @@ RUN apt-get update \
15 && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ 15 && 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 \ 16 && apt-get update \
17 && apt-get install -y google-chrome-unstable --no-install-recommends \ 17 && apt-get install -y google-chrome-unstable --no-install-recommends \
18 && rm -rf /var/lib/apt/lists/* 18 && rm -rf /var/lib/apt/lists/* \
19 && wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
20 && chmod +x /usr/sbin/wait-for-it.sh
19 21
20# Install Puppeteer under /node_modules so it's available system-wide 22# Install Puppeteer under /node_modules so it's available system-wide
21ADD package.json package-lock.json / 23ADD package.json package-lock.json /
22RUN npm install \ No newline at end of file 24RUN npm install
diff --git a/README.md b/README.md
index 20c2fd6..8322299 100644
--- a/README.md
+++ b/README.md
@@ -2,88 +2,14 @@
2 2
3A Node + Puppeteer base image for running Puppeteer scripts. Add your own tools (such as Jest, Mocha, etc), link services you want to test via Docker Compose, and run your Puppeteer scripts with a headless Chromium. 3A Node + Puppeteer base image for running Puppeteer scripts. Add your own tools (such as Jest, Mocha, etc), link services you want to test via Docker Compose, and run your Puppeteer scripts with a headless Chromium.
4 4
5See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. 5## Versions
6
7## Usage example
8
9Dockerfile.integration-tests:
10
11```Dockerfile
12FROM buildkite/puppeteer:latest
13RUN npm i mocha
14ENV PATH="${PATH}:/node_modules/.bin"
15```
16
17docker-compose.integration-tests.yml:
18
19```yml
20version: '3'
21services:
22 tests:
23 build:
24 context: .
25 dockerfile: Dockerfile.integration-tests
26 volumes:
27 - "./integration-tests:/integration-tests"
28 - "/screenshots"
29 command: mocha --recursive /integration-tests
30 links:
31 - app
32 app:
33 image: tutum/hello-world
34 expose:
35 - "80"
36```
37
38integration-tests/index.test.js:
39 6
40```js 7See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available.
41const assert = require('assert')
42const puppeteer = require('puppeteer')
43
44let browser
45let page
46
47before(async() => {
48 browser = await puppeteer.launch({
49 args: [
50 // Required for Docker version of Puppeteer
51 '--no-sandbox',
52 '--disable-setuid-sandbox',
53 // This will write shared memory files into /tmp instead of /dev/shm,
54 // because Docker’s default for /dev/shm is 64MB
55 '--disable-dev-shm-usage'
56 ]
57 })
58
59 const browserVersion = await browser.version()
60 console.log(`Started ${browserVersion}`)
61})
62
63beforeEach(async() => {
64 page = await browser.newPage()
65})
66
67afterEach(async() => {
68 await page.close()
69})
70 8
71after(async() => { 9## Example
72 await browser.close()
73})
74 10
75describe('App', () => { 11See the [example directory](example) for a complete Docker Compose example, showing how to run Puppeteer against a linked Docker Compose web service.
76 it('renders', async() => {
77 const response = await page.goto('http://app/')
78 assert(response.ok())
79 await page.screenshot({ path: `/screenshots/app.png` })
80 })
81})
82```
83 12
84Running: 13## Dependent Services
85 14
86```shell 15This image includes [wait-for-it.sh](https://github.com/vishnubob/wait-for-it) which can be useful if you need to wait for a dependent web service to start accepting requests before your Puppeteer container attempts connecting to it. See [the example](example) for usage.
87docker-compose -f docker-compose.integration-tests.yml run tests
88ls screenshots/
89```
diff --git a/example/Dockerfile.integration-tests b/example/Dockerfile.integration-tests
new file mode 100644
index 0000000..41de685
--- /dev/null
+++ b/example/Dockerfile.integration-tests
@@ -0,0 +1,3 @@
1FROM buildkite/puppeteer:latest
2RUN npm i mocha
3ENV PATH="${PATH}:/node_modules/.bin" \ No newline at end of file
diff --git a/example/README.md b/example/README.md
new file mode 100644
index 0000000..3f1c735
--- /dev/null
+++ b/example/README.md
@@ -0,0 +1,17 @@
1# Docker Puppeteer Example
2
3This as an example of using the Docker Puppeteer docker image to run Mocha tests against a linked Docker Compose web service, and capturing a screenshot into a local `./screenshots` directory.
4
5## Running
6
7```shell
8# Clone this example
9git clone https://github.com/buildkite/docker-puppeteer.git
10cd docker-puppeteer/example
11
12# Build and run the example tests
13docker-compose -f docker-compose.integration-tests.yml run tests
14
15# See the screen that was generated
16ls screenshots/
17```
diff --git a/example/docker-compose.integration-tests.yml b/example/docker-compose.integration-tests.yml
new file mode 100644
index 0000000..074f4d1
--- /dev/null
+++ b/example/docker-compose.integration-tests.yml
@@ -0,0 +1,16 @@
1version: '3'
2services:
3 tests:
4 build:
5 context: .
6 dockerfile: Dockerfile.integration-tests
7 volumes:
8 - "./integration-tests:/integration-tests"
9 - "./screenshots:/screenshots"
10 command: "wait-for-it.sh app:80 -- mocha --recursive /integration-tests"
11 links:
12 - app
13 app:
14 image: tutum/hello-world
15 expose:
16 - "80"
diff --git a/example/integration-tests/index.test.js b/example/integration-tests/index.test.js
new file mode 100644
index 0000000..dd39d8a
--- /dev/null
+++ b/example/integration-tests/index.test.js
@@ -0,0 +1,41 @@
1const assert = require('assert')
2const puppeteer = require('puppeteer')
3
4let browser
5let page
6
7before(async() => {
8 browser = await puppeteer.launch({
9 args: [
10 // Required for Docker version of Puppeteer
11 '--no-sandbox',
12 '--disable-setuid-sandbox',
13 // This will write shared memory files into /tmp instead of /dev/shm,
14 // because Docker’s default for /dev/shm is 64MB
15 '--disable-dev-shm-usage'
16 ]
17 })
18
19 const browserVersion = await browser.version()
20 console.log(`Started ${browserVersion}`)
21})
22
23beforeEach(async() => {
24 page = await browser.newPage()
25})
26
27afterEach(async() => {
28 await page.close()
29})
30
31after(async() => {
32 await browser.close()
33})
34
35describe('App', () => {
36 it('renders', async() => {
37 const response = await page.goto('http://app/')
38 assert(response.ok())
39 await page.screenshot({ path: `/screenshots/app.png` })
40 })
41}) \ No newline at end of file