Skip to content

Commit c6a5cc9

Browse files
authored
Merge pull request dockersamples#20 from bfirsh/add-ci-test-for-docker-cloud
Docker Cloud stack file and CI tests
2 parents 34acff5 + 2d3fe7d commit c6a5cc9

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

dockercloud.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
db:
2+
image: 'postgres:9.4'
3+
restart: always
4+
redis:
5+
image: 'redis:latest'
6+
restart: always
7+
result-app:
8+
autoredeploy: true
9+
image: 'instavote/result-app:latest'
10+
ports:
11+
- '80:80'
12+
restart: always
13+
lb:
14+
autoredeploy: true
15+
image: 'dockercloud/haproxy:latest'
16+
links:
17+
- voting-app
18+
ports:
19+
- "80:80"
20+
roles:
21+
- global
22+
restart: always
23+
voting-app:
24+
autoredeploy: true
25+
image: 'instavote/voting-app:latest'
26+
restart: always
27+
target_num_containers: 5
28+
29+
worker:
30+
autoredeploy: true
31+
image: 'instavote/worker:latest'
32+
restart: always
33+
target_num_containers: 3

result-app/docker-compose.test.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
version: '2'
2+
3+
services:
4+
5+
sut:
6+
build: ./tests/
7+
depends_on:
8+
- voting-app
9+
- result-app
10+
- worker
11+
networks:
12+
- front-tier
13+
14+
voting-app:
15+
build: ../voting-app/
16+
ports: ["80"]
17+
depends_on:
18+
- redis
19+
- db
20+
networks:
21+
- front-tier
22+
- back-tier
23+
24+
result-app:
25+
build: .
26+
ports: ["80"]
27+
depends_on:
28+
- redis
29+
- db
30+
networks:
31+
- front-tier
32+
- back-tier
33+
34+
worker:
35+
build: ../worker/
36+
depends_on:
37+
- redis
38+
- db
39+
networks:
40+
- back-tier
41+
42+
redis:
43+
image: redis:alpine
44+
ports: ["6379"]
45+
networks:
46+
- back-tier
47+
48+
db:
49+
image: postgres:9.4
50+
volumes:
51+
- "db-data:/var/lib/postgresql/data"
52+
networks:
53+
- back-tier
54+
55+
volumes:
56+
db-data:
57+
58+
networks:
59+
front-tier:
60+
back-tier:

result-app/tests/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM node
2+
RUN npm install -g phantomjs
3+
ADD . /app
4+
WORKDIR /app
5+
CMD ["/app/tests.sh"]

result-app/tests/render.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var system = require('system');
2+
var page = require('webpage').create();
3+
var url = system.args[1];
4+
5+
page.onLoadFinished = function() {
6+
setTimeout(function(){
7+
console.log(page.content);
8+
phantom.exit();
9+
}, 1000);
10+
};
11+
12+
page.open(url, function() {
13+
page.evaluate(function() {
14+
});
15+
});

result-app/tests/tests.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
while ! timeout 1 bash -c "echo > /dev/tcp/voting-app/80"; do sleep 1; done
3+
curl -sS -X POST --data "vote=a" http://voting-app > /dev/null
4+
curl -sS -X POST --data "vote=b" http://voting-app > /dev/null
5+
sleep 10
6+
if phantomjs render.js http://result-app | grep -q '2 votes'; then
7+
echo -e "\e[42m------------"
8+
echo -e "\e[92mTests passed"
9+
echo -e "\e[42m------------"
10+
exit 0
11+
fi
12+
echo -e "\e[41m------------"
13+
echo -e "\e[91mTests failed"
14+
echo -e "\e[41m------------"
15+
exit 1

0 commit comments

Comments
 (0)