From 874a4bc79aeef71f67aa0e1c644fcb427f518948 Mon Sep 17 00:00:00 2001 From: Borja Burgos Date: Wed, 15 Jun 2016 19:14:55 -0700 Subject: [PATCH 1/3] adding CI test for Docker Cloud --- result-app/docker-compose.test.yml | 60 ++++++++++++++++++++++++++++++ result-app/tests/Dockerfile | 5 +++ result-app/tests/render.js | 15 ++++++++ result-app/tests/tests.sh | 15 ++++++++ 4 files changed, 95 insertions(+) create mode 100644 result-app/docker-compose.test.yml create mode 100644 result-app/tests/Dockerfile create mode 100644 result-app/tests/render.js create mode 100755 result-app/tests/tests.sh diff --git a/result-app/docker-compose.test.yml b/result-app/docker-compose.test.yml new file mode 100644 index 0000000..e2d9547 --- /dev/null +++ b/result-app/docker-compose.test.yml @@ -0,0 +1,60 @@ +version: '2' + +services: + + sut: + build: ./tests/ + depends_on: + - voting-app + - result-app + - worker + networks: + - front-tier + + voting-app: + build: ../voting-app/ + ports: ["80"] + depends_on: + - redis + - db + networks: + - front-tier + - back-tier + + result-app: + build: . + ports: ["80"] + depends_on: + - redis + - db + networks: + - front-tier + - back-tier + + worker: + build: ../worker/ + depends_on: + - redis + - db + networks: + - back-tier + + redis: + image: redis:alpine + ports: ["6379"] + networks: + - back-tier + + db: + image: postgres:9.4 + volumes: + - "db-data:/var/lib/postgresql/data" + networks: + - back-tier + +volumes: + db-data: + +networks: + front-tier: + back-tier: diff --git a/result-app/tests/Dockerfile b/result-app/tests/Dockerfile new file mode 100644 index 0000000..bca8c51 --- /dev/null +++ b/result-app/tests/Dockerfile @@ -0,0 +1,5 @@ +FROM node +RUN npm install -g phantomjs +ADD . /app +WORKDIR /app +CMD ["/app/tests.sh"] diff --git a/result-app/tests/render.js b/result-app/tests/render.js new file mode 100644 index 0000000..975137b --- /dev/null +++ b/result-app/tests/render.js @@ -0,0 +1,15 @@ +var system = require('system'); +var page = require('webpage').create(); +var url = system.args[1]; + +page.onLoadFinished = function() { + setTimeout(function(){ + console.log(page.content); + phantom.exit(); + }, 1000); +}; + +page.open(url, function() { + page.evaluate(function() { + }); +}); diff --git a/result-app/tests/tests.sh b/result-app/tests/tests.sh new file mode 100755 index 0000000..a3c8408 --- /dev/null +++ b/result-app/tests/tests.sh @@ -0,0 +1,15 @@ +#!/bin/sh +while ! timeout 1 bash -c "echo > /dev/tcp/voting-app/80"; do sleep 1; done +curl -sS -X POST --data "vote=a" http://voting-app > /dev/null +curl -sS -X POST --data "vote=b" http://voting-app > /dev/null +sleep 10 +if phantomjs render.js http://result-app | grep -q '2 votes'; then + echo -e "\e[42m------------" + echo -e "\e[92mTests passed" + echo -e "\e[42m------------" + exit 0 +fi + echo -e "\e[41m------------" + echo -e "\e[91mTests failed" + echo -e "\e[41m------------" + exit 1 From 9eccee1ac294ddaf9df172ed7fee5fd5c976d824 Mon Sep 17 00:00:00 2001 From: Borja Burgos Date: Wed, 15 Jun 2016 19:15:15 -0700 Subject: [PATCH 2/3] adding dockercloud.yml --- dockercloud.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 dockercloud.yml diff --git a/dockercloud.yml b/dockercloud.yml new file mode 100644 index 0000000..56a7e56 --- /dev/null +++ b/dockercloud.yml @@ -0,0 +1,33 @@ +db: + image: 'postgres:9.4' + restart: always +redis: + image: 'redis:latest' + restart: always +result-app: + autoredeploy: true + image: 'instavote/result-app:latest' + ports: + - '80:80' + restart: always +lb: + autoredeploy: true + image: 'dockercloud/haproxy:latest' + links: + - web + ports: + - "80:80" + roles: + - global + restart: always +voting-app: + autoredeploy: true + image: 'instavote/voting-app:latest' + restart: always + target_num_containers: 5 + +worker: + autoredeploy: true + image: 'instavote/worker:latest' + restart: always + target_num_containers: 3 From 2d3fe7d2999a246dcb4d0d0455ecc472f3c0be82 Mon Sep 17 00:00:00 2001 From: Borja Burgos Date: Thu, 16 Jun 2016 11:18:13 -0700 Subject: [PATCH 3/3] fixing bug in dockercloud.yml lb was linking to the wrong service (web instead of voting-app) --- dockercloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockercloud.yml b/dockercloud.yml index 56a7e56..b3d63d4 100644 --- a/dockercloud.yml +++ b/dockercloud.yml @@ -14,7 +14,7 @@ lb: autoredeploy: true image: 'dockercloud/haproxy:latest' links: - - web + - voting-app ports: - "80:80" roles: