diff options
-rw-r--r-- | Dockerfile | 6 | ||||
-rw-r--r-- | README.md | 86 | ||||
-rw-r--r-- | example/Dockerfile.integration-tests | 3 | ||||
-rw-r--r-- | example/README.md | 17 | ||||
-rw-r--r-- | example/docker-compose.integration-tests.yml | 16 | ||||
-rw-r--r-- | example/integration-tests/index.test.js | 41 |
6 files changed, 87 insertions, 82 deletions
@@ -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 |
21 | ADD package.json package-lock.json / | 23 | ADD package.json package-lock.json / |
22 | RUN npm install \ No newline at end of file | 24 | RUN npm install |
@@ -2,88 +2,14 @@ | |||
2 | 2 | ||
3 | A 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. | 3 | A 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 | ||
5 | See 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 | |||
9 | Dockerfile.integration-tests: | ||
10 | |||
11 | ```Dockerfile | ||
12 | FROM buildkite/puppeteer:latest | ||
13 | RUN npm i mocha | ||
14 | ENV PATH="${PATH}:/node_modules/.bin" | ||
15 | ``` | ||
16 | |||
17 | docker-compose.integration-tests.yml: | ||
18 | |||
19 | ```yml | ||
20 | version: '3' | ||
21 | services: | ||
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 | |||
38 | integration-tests/index.test.js: | ||
39 | 6 | ||
40 | ```js | 7 | See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. |
41 | const assert = require('assert') | ||
42 | const puppeteer = require('puppeteer') | ||
43 | |||
44 | let browser | ||
45 | let page | ||
46 | |||
47 | before(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 | |||
63 | beforeEach(async() => { | ||
64 | page = await browser.newPage() | ||
65 | }) | ||
66 | |||
67 | afterEach(async() => { | ||
68 | await page.close() | ||
69 | }) | ||
70 | 8 | ||
71 | after(async() => { | 9 | ## Example |
72 | await browser.close() | ||
73 | }) | ||
74 | 10 | ||
75 | describe('App', () => { | 11 | See 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 | ||
84 | Running: | 13 | ## Dependent Services |
85 | 14 | ||
86 | ```shell | 15 | This 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. |
87 | docker-compose -f docker-compose.integration-tests.yml run tests | ||
88 | ls 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 @@ | |||
1 | FROM buildkite/puppeteer:latest | ||
2 | RUN npm i mocha | ||
3 | ENV 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 | |||
3 | This 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 | ||
9 | git clone https://github.com/buildkite/docker-puppeteer.git | ||
10 | cd docker-puppeteer/example | ||
11 | |||
12 | # Build and run the example tests | ||
13 | docker-compose -f docker-compose.integration-tests.yml run tests | ||
14 | |||
15 | # See the screen that was generated | ||
16 | ls 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 @@ | |||
1 | version: '3' | ||
2 | services: | ||
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 @@ | |||
1 | const assert = require('assert') | ||
2 | const puppeteer = require('puppeteer') | ||
3 | |||
4 | let browser | ||
5 | let page | ||
6 | |||
7 | before(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 | |||
23 | beforeEach(async() => { | ||
24 | page = await browser.newPage() | ||
25 | }) | ||
26 | |||
27 | afterEach(async() => { | ||
28 | await page.close() | ||
29 | }) | ||
30 | |||
31 | after(async() => { | ||
32 | await browser.close() | ||
33 | }) | ||
34 | |||
35 | describe('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 | ||