├── 1 ├── Makefile └── producer │ ├── .dockerignore │ ├── .gitignore │ ├── Dockerfile │ ├── Test.Dockerfile │ └── producer │ ├── index.js │ ├── package.json │ └── test │ └── index.js ├── 2 ├── Makefile ├── producer │ ├── .dockerignore │ ├── .gitignore │ ├── Dockerfile │ ├── Test.Dockerfile │ └── producer │ │ ├── index.js │ │ ├── package.json │ │ └── test │ │ └── index.js ├── run.yml ├── test.yml └── test │ ├── Dockerfile │ ├── index.js │ └── package.json ├── 3 ├── Makefile ├── nginx │ └── producer.conf ├── producer │ ├── .dockerignore │ ├── .gitignore │ ├── Dockerfile │ ├── Test.Dockerfile │ └── producer │ │ ├── index.js │ │ ├── package.json │ │ └── test │ │ └── index.js ├── run.yml ├── test.yml └── test │ ├── Dockerfile │ ├── index.js │ └── package.json ├── 4 ├── Makefile ├── consumer │ ├── Dockerfile │ └── consumer │ │ ├── consume.js │ │ ├── index.js │ │ └── package.json ├── nginx │ └── producer.conf ├── producer │ ├── Dockerfile │ └── producer │ │ ├── index.js │ │ ├── package.json │ │ └── produce.js ├── run.yml ├── test.yml └── test │ ├── Dockerfile │ ├── index.js │ └── package.json ├── 5 ├── Makefile ├── consumer │ ├── Dockerfile │ └── consumer │ │ ├── app.js │ │ ├── consume.js │ │ └── package.json ├── kube.yml ├── nginx │ ├── Dockerfile │ └── producer.conf ├── producer │ ├── Dockerfile │ └── producer │ │ ├── index.js │ │ ├── package.json │ │ └── produce.js ├── run.yml ├── test.yml └── test │ ├── Dockerfile │ ├── index.js │ └── package.json └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /1/Makefile: -------------------------------------------------------------------------------- 1 | .SILENT: 2 | help: 3 | echo 4 | echo "NodeSource Metrics Server Make commands" 5 | echo 6 | echo " Commands: " 7 | echo 8 | echo " help - show this message" 9 | echo " run - Start this service, and all of its deps, locally (docker)" 10 | echo " test-producer - Run the unit tests for producer" 11 | echo " deps - Check for all dependencies" 12 | 13 | build: 14 | docker build -t retrohacker/presentation:producer ./producer/ 15 | 16 | build-test: build 17 | docker build -t retrohacker/presentation:producer-test -f ./producer/Test.Dockerfile ./producer/ 18 | 19 | run: build 20 | docker run -it -p 3000:3000 retrohacker/presentation:producer 21 | 22 | test-producer: build-test 23 | docker run -it -p 3000:3000 retrohacker/presentation:producer-test 24 | 25 | deps: 26 | echo " Dependencies: " 27 | echo 28 | echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 29 | echo 30 | -------------------------------------------------------------------------------- /1/producer/.dockerignore: -------------------------------------------------------------------------------- 1 | ./producer/node_modules 2 | ./producer/coverage 3 | ./producer/.nyc_output 4 | -------------------------------------------------------------------------------- /1/producer/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | -------------------------------------------------------------------------------- /1/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ENV NODE_ENV production 6 | ADD producer/package.json package.json 7 | RUN npm install 8 | 9 | ADD producer/ . 10 | 11 | CMD ["node","index.js"] 12 | -------------------------------------------------------------------------------- /1/producer/Test.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM retrohacker/presentation:producer 2 | 3 | ENV NODE_ENV dev 4 | RUN npm install 5 | 6 | CMD ["npm", "test"] 7 | -------------------------------------------------------------------------------- /1/producer/producer/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var app = express() 3 | 4 | var response = 'Hello World!' 5 | 6 | app.get('/', function (req, res) { 7 | res.send(response) 8 | }) 9 | 10 | var server = null 11 | 12 | /* istanbul ignore next */ 13 | function onListen () { 14 | var host = server.address().address 15 | var port = server.address().port 16 | 17 | console.log('Example app listening at http://%s:%s', host, port) 18 | } 19 | 20 | /* istanbul ignore next */ 21 | if(module.parent) { 22 | module.exports = app 23 | } else { 24 | server = app.listen(3000, onListen) 25 | } 26 | -------------------------------------------------------------------------------- /1/producer/producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3" 6 | }, 7 | "devDependencies": { 8 | "nyc": "^9.0.1", 9 | "supertest": "^2.0.1", 10 | "tape": "^4.6.2" 11 | }, 12 | "scripts": { 13 | "test": "nyc tape ./test/*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /1/producer/producer/test/index.js: -------------------------------------------------------------------------------- 1 | var supertest = require('supertest') 2 | var app = require('../') 3 | var tape = require('tape') 4 | 5 | tape('Server returns hello world', function (t) { 6 | supertest(app) 7 | .get('/') 8 | .expect(200, 'Hello World!') 9 | .end(function (e) { 10 | t.error(e, 'Supertest checks pass') 11 | t.end() 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /2/Makefile: -------------------------------------------------------------------------------- 1 | .SILENT: 2 | help: 3 | echo 4 | echo "Nodevember Make commands" 5 | echo 6 | echo " Commands: " 7 | echo 8 | echo " help - show this message" 9 | echo " build - Build the Docker images that power local dev (docker)" 10 | echo " clean - Remove docker containers" 11 | echo " run - Start this service, and all of its deps, locally (docker)" 12 | echo " test-producer - Run unit tests for the producer microservice" 13 | echo " test-integration - Run integration tests for this project" 14 | echo " test-all - Run all tests for this project" 15 | echo " deps - Check for all dependencies" 16 | 17 | build: clean 18 | docker-compose -f ./run.yml build 19 | 20 | build-test: build 21 | docker build -t retrohacker/presentation:producer-test -f ./producer/Test.Dockerfile ./producer/ 22 | 23 | run: build 24 | docker-compose -f ./run.yml up 25 | 26 | test-producer: build-test 27 | docker run -it -p 3000:3000 retrohacker/presentation:producer-test 28 | 29 | build-test-integration: build 30 | docker-compose -f ./test.yml build 31 | 32 | test-integration: clean 33 | docker-compose -f ./test.yml up 34 | 35 | test-all: test-producer test-integration 36 | 37 | clean: 38 | docker-compose -f ./run.yml rm -f 39 | docker-compose -f ./test.yml rm -f 40 | 41 | deps: 42 | echo " Dependencies: " 43 | echo 44 | echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 45 | echo " * docker-compose $(shell which docker-compose > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 46 | echo 47 | 48 | .PHONY: build build-test run test-producer build-test-integration test-integration test-all clean deps 49 | -------------------------------------------------------------------------------- /2/producer/.dockerignore: -------------------------------------------------------------------------------- 1 | ./producer/node_modules 2 | ./producer/coverage 3 | ./producer/.nyc_output 4 | -------------------------------------------------------------------------------- /2/producer/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | -------------------------------------------------------------------------------- /2/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ENV NODE_ENV production 6 | ADD producer/package.json package.json 7 | RUN npm install 8 | 9 | ADD producer/ . 10 | 11 | CMD ["node","index.js"] 12 | -------------------------------------------------------------------------------- /2/producer/Test.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM retrohacker/presentation:producer 2 | 3 | ENV NODE_ENV dev 4 | RUN npm install 5 | 6 | CMD ["npm", "test"] 7 | -------------------------------------------------------------------------------- /2/producer/producer/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var app = express() 3 | 4 | var response = 'Hello World!' 5 | 6 | app.get('/', function (req, res) { 7 | res.send(response) 8 | }) 9 | 10 | var server = null 11 | 12 | /* istanbul ignore next */ 13 | function onListen () { 14 | var host = server.address().address 15 | var port = server.address().port 16 | 17 | console.log('Example app listening at http://%s:%s', host, port) 18 | } 19 | 20 | /* istanbul ignore next */ 21 | if(module.parent) { 22 | module.exports = app 23 | } else { 24 | server = app.listen(3000, onListen) 25 | } 26 | -------------------------------------------------------------------------------- /2/producer/producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3" 6 | }, 7 | "devDependencies": { 8 | "nyc": "^9.0.1", 9 | "supertest": "^2.0.1", 10 | "tape": "^4.6.2" 11 | }, 12 | "scripts": { 13 | "test": "nyc tape ./test/*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2/producer/producer/test/index.js: -------------------------------------------------------------------------------- 1 | var supertest = require('supertest') 2 | var app = require('../') 3 | var tape = require('tape') 4 | 5 | tape('Server returns hello world', function (t) { 6 | supertest(app) 7 | .get('/') 8 | .expect(200, 'Hello World!') 9 | .end(function (e) { 10 | t.error(e, 'Supertest checks pass') 11 | t.end() 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /2/run.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | ports: 7 | - 3000:3000 8 | -------------------------------------------------------------------------------- /2/test.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | extends: 5 | file: ./run.yml 6 | service: producer 7 | integration: 8 | image: retrohacker/presentation:integration-test 9 | build: ./test 10 | environment: 11 | - PRODUCER_HOST=producer 12 | - PRODUCER_PORT=3000 13 | links: 14 | - producer 15 | -------------------------------------------------------------------------------- /2/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | WORKDIR /usr/src/app 4 | 5 | ENV NODE_ENV dev 6 | 7 | ADD package.json ./ 8 | RUN npm install 9 | ADD * ./ 10 | 11 | CMD ["npm", "test"] 12 | -------------------------------------------------------------------------------- /2/test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var supertest = require('supertest') 3 | var async = require('async') 4 | var net = require('net') 5 | 6 | var server_host = process.env['PRODUCER_HOST'] 7 | var server_port = process.env['PRODUCER_PORT'] 8 | 9 | test('Waiting for service to become available', function (t) { 10 | var client 11 | async.retry(function (cb) { 12 | t.comment(`Attempting to connect to ${server_host}:${server_port}...`) 13 | client = net.connect(server_port, server_host, cb) 14 | }, function (e) { 15 | t.error(e, 'server is available') 16 | if(e) throw e 17 | client.unref() 18 | client.end() 19 | t.end() 20 | }) 21 | }) 22 | 23 | test('Should return hello world', function(t) { 24 | supertest(`http://${server_host}:${server_port}`) 25 | .get('/') 26 | .expect(200, 'Hello World!') 27 | .end(function(e) { 28 | t.error(e, 'supertest assertions pass') 29 | t.end() 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /2/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "async": "^2.1.2", 4 | "supertest": "^2.0.1", 5 | "tape": "^4.6.2" 6 | }, 7 | "scripts": { 8 | "test": "tape *.js" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /3/Makefile: -------------------------------------------------------------------------------- 1 | .SILENT: 2 | help: 3 | echo 4 | echo "Nodevember Make Commands" 5 | echo 6 | echo " Commands: " 7 | echo 8 | echo " help - show this message" 9 | echo " build - Build the Docker images that power local dev (docker)" 10 | echo " clean - Remove docker containers" 11 | echo " run - Start this service, and all of its deps, locally (docker)" 12 | echo " test-producer - Run unit tests for the producer microservice" 13 | echo " test-integration - Run integration tests for this project" 14 | echo " test-all - Run all tests for this project" 15 | echo " deps - Check for all dependencies" 16 | 17 | build: clean 18 | docker-compose -f ./run.yml build 19 | 20 | build-test: build 21 | docker build -t retrohacker/presentation:producer-test -f ./producer/Test.Dockerfile ./producer/ 22 | 23 | run: build 24 | docker-compose -f ./run.yml up 25 | 26 | test-producer: build-test 27 | docker run -it -p 3000:3000 retrohacker/presentation:producer-test 28 | 29 | build-test-integration: build 30 | docker-compose -f ./test.yml build 31 | 32 | test-integration: clean 33 | docker-compose -f ./test.yml up 34 | 35 | test-all: test-producer test-integration 36 | 37 | clean: 38 | docker-compose -f ./run.yml rm -f 39 | docker-compose -f ./test.yml rm -f 40 | 41 | deps: 42 | echo " Dependencies: " 43 | echo 44 | echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 45 | echo " * docker-compose $(shell which docker-compose > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 46 | echo 47 | 48 | .PHONY: build build-test run test-producer build-test-integration test-integration test-all clean deps 49 | -------------------------------------------------------------------------------- /3/nginx/producer.conf: -------------------------------------------------------------------------------- 1 | upstream producer { 2 | server producer:3000; 3 | } 4 | 5 | proxy_cache_path /tmp/producer keys_zone=producer:25m; 6 | 7 | 8 | server { 9 | listen 8080; 10 | 11 | gzip on; 12 | gzip_static on; 13 | gzip_disable "MSIE [1-6]\."; 14 | default_type text/html; 15 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; 16 | 17 | location / { 18 | proxy_cache producer; 19 | proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; 20 | proxy_cache_valid 1m; 21 | proxy_connect_timeout 10s; 22 | 23 | proxy_pass http://producer; 24 | proxy_read_timeout 90; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /3/producer/.dockerignore: -------------------------------------------------------------------------------- 1 | ./producer/node_modules 2 | ./producer/coverage 3 | ./producer/.nyc_output 4 | -------------------------------------------------------------------------------- /3/producer/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | -------------------------------------------------------------------------------- /3/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ENV NODE_ENV production 6 | ADD producer/package.json package.json 7 | RUN npm install 8 | 9 | ADD producer/ . 10 | 11 | CMD ["node","index.js"] 12 | -------------------------------------------------------------------------------- /3/producer/Test.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM retrohacker/presentation:producer 2 | 3 | ENV NODE_ENV dev 4 | RUN npm install 5 | 6 | CMD ["npm", "test"] 7 | -------------------------------------------------------------------------------- /3/producer/producer/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var app = express() 3 | 4 | var response = 'Hello World!' 5 | 6 | app.get('/', function (req, res) { 7 | console.log(response) 8 | res.send(response) 9 | }) 10 | 11 | var server = null 12 | 13 | /* istanbul ignore next */ 14 | function onListen () { 15 | var host = server.address().address 16 | var port = server.address().port 17 | 18 | console.log('Example app listening at http://%s:%s', host, port) 19 | } 20 | 21 | /* istanbul ignore next */ 22 | if(module.parent) { 23 | module.exports = app 24 | } else { 25 | server = app.listen(3000, onListen) 26 | } 27 | -------------------------------------------------------------------------------- /3/producer/producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "async": "^1.4.2", 4 | "express": "^4.13.3" 5 | }, 6 | "devDependencies": { 7 | "nyc": "^9.0.1", 8 | "supertest": "^2.0.1", 9 | "tape": "^4.6.2" 10 | }, 11 | "scripts": { 12 | "test": "nyc tape ./test/*" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /3/producer/producer/test/index.js: -------------------------------------------------------------------------------- 1 | var supertest = require('supertest') 2 | var app = require('../') 3 | var tape = require('tape') 4 | 5 | tape('Server returns hello world', function (t) { 6 | supertest(app) 7 | .get('/') 8 | .expect(200, 'Hello World!') 9 | .end(function (e) { 10 | t.error(e, 'Supertest checks pass') 11 | t.end() 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /3/run.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | ports: 7 | - 3000:3000 8 | nginx: 9 | image: nginx 10 | volumes: 11 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 12 | ports: 13 | - 8080:8080 14 | links: 15 | - producer 16 | -------------------------------------------------------------------------------- /3/test.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | extends: 5 | file: ./run.yml 6 | service: producer 7 | nginx: 8 | image: nginx 9 | volumes: 10 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 11 | ports: 12 | - 8080:8080 13 | links: 14 | - producer 15 | integration: 16 | image: retrohacker/presentation:integration-test 17 | build: ./test 18 | environment: 19 | - PRODUCER_HOST=nginx 20 | - PRODUCER_PORT=8080 21 | links: 22 | - nginx 23 | -------------------------------------------------------------------------------- /3/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | WORKDIR /usr/src/app 4 | 5 | ENV NODE_ENV dev 6 | 7 | ADD package.json ./ 8 | RUN npm install 9 | ADD * ./ 10 | 11 | CMD ["npm", "test"] 12 | -------------------------------------------------------------------------------- /3/test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var supertest = require('supertest') 3 | var async = require('async') 4 | var net = require('net') 5 | 6 | var server_host = process.env['PRODUCER_HOST'] 7 | var server_port = process.env['PRODUCER_PORT'] 8 | 9 | test('Waiting for service to become available', function (t) { 10 | var client 11 | async.retry(function (cb) { 12 | t.comment(`Attempting to connect to ${server_host}:${server_port}...`) 13 | client = net.connect(server_port, server_host, cb) 14 | }, function (e) { 15 | t.error(e, 'server is available') 16 | if(e) throw e 17 | client.unref() 18 | client.end() 19 | t.end() 20 | }) 21 | }) 22 | 23 | function helloWorldTest (t) { 24 | supertest(`http://${server_host}:${server_port}`) 25 | .get('/') 26 | .expect(200, 'Hello World!') 27 | .end(function(e) { 28 | t.error(e, 'supertest assertions pass') 29 | t.end() 30 | }) 31 | } 32 | 33 | test('Should return hello world', helloWorldTest) 34 | test('Test nginx cache', helloWorldTest) 35 | -------------------------------------------------------------------------------- /3/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "async": "^2.1.2", 4 | "supertest": "^2.0.1", 5 | "tape": "^4.6.2" 6 | }, 7 | "scripts": { 8 | "test": "tape *.js" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /4/Makefile: -------------------------------------------------------------------------------- 1 | .SILENT: 2 | help: 3 | echo 4 | echo "Nodevember Make Commands" 5 | echo 6 | echo " Commands: " 7 | echo 8 | echo " help - show this message" 9 | echo " build - Build the Docker images that power local dev (docker)" 10 | echo " clean - Remove docker containers" 11 | echo " run - Start this service, and all of its deps, locally (docker)" 12 | echo " test-integration - Run integration tests for this project" 13 | echo " test-all - Run all tests for this project" 14 | echo " deps - Check for all dependencies" 15 | 16 | build: clean 17 | docker-compose -f ./run.yml build 18 | 19 | run: build 20 | docker-compose -f ./run.yml up 21 | 22 | build-test-integration: build 23 | docker-compose -f ./test.yml build 24 | 25 | test-integration: clean 26 | docker-compose -f ./test.yml up 27 | 28 | test-all: test-integration 29 | 30 | clean: 31 | docker-compose -f ./run.yml rm -f 32 | docker-compose -f ./test.yml rm -f 33 | 34 | deps: 35 | echo " Dependencies: " 36 | echo 37 | echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 38 | echo " * docker-compose $(shell which docker-compose > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 39 | echo 40 | 41 | .PHONY: build build-test run build-test-integration test-integration test-all clean deps 42 | -------------------------------------------------------------------------------- /4/consumer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ADD consumer/package.json package.json 6 | RUN npm install 7 | 8 | ADD consumer/ . 9 | 10 | CMD ["node","index.js"] 11 | -------------------------------------------------------------------------------- /4/consumer/consumer/consume.js: -------------------------------------------------------------------------------- 1 | // Publisher 2 | var amqp = require('amqplib/callback_api') 3 | var async = require('async') 4 | var q = 'log' 5 | var conn 6 | var callback 7 | 8 | function connect () { 9 | async.during(singleConnect, waitingForConnection, function (e) { 10 | console.log('Connected to RabbitMQ!') 11 | conn.createChannel(function on_open (e, ch) { 12 | if (e != null) return console.error(e) 13 | ch.assertQueue(q) 14 | ch.consume(q, function (msg) { 15 | if (msg !== null) { 16 | callback(msg.content.toString()) 17 | ch.ack(msg) 18 | } 19 | }) 20 | }) 21 | }) 22 | } 23 | 24 | function singleConnect (cb) { 25 | console.log('Trying to connect to rabbitmq...') 26 | return amqp.connect('amqp://rabbitmq', function (e, c) { 27 | conn = c 28 | return cb(null, e) 29 | }) 30 | } 31 | 32 | function waitingForConnection (cb) { 33 | console.log('Connection to rabbitmq failed, retrying...') 34 | setTimeout(cb, 1000) 35 | } 36 | 37 | connect() 38 | 39 | module.exports = function on_log (cb) { 40 | callback = cb 41 | } 42 | -------------------------------------------------------------------------------- /4/consumer/consumer/index.js: -------------------------------------------------------------------------------- 1 | var on_log = require('./consume.js') 2 | 3 | on_log(function log (msg) { 4 | console.log(msg) 5 | }) 6 | -------------------------------------------------------------------------------- /4/consumer/consumer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3", 6 | "pg": "^6.1.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /4/nginx/producer.conf: -------------------------------------------------------------------------------- 1 | upstream producer { 2 | server producer:3000; 3 | } 4 | 5 | proxy_cache_path /tmp/producer keys_zone=producer:25m; 6 | 7 | 8 | server { 9 | listen 8080; 10 | 11 | gzip on; 12 | gzip_static on; 13 | gzip_disable "MSIE [1-6]\."; 14 | default_type text/html; 15 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; 16 | 17 | location / { 18 | proxy_cache producer; 19 | proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; 20 | proxy_cache_valid 1m; 21 | proxy_connect_timeout 10s; 22 | 23 | proxy_pass http://producer; 24 | proxy_read_timeout 90; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /4/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ENV NODE_ENV production 6 | ADD producer/package.json package.json 7 | RUN npm install 8 | 9 | ADD producer/ . 10 | 11 | CMD ["node","index.js"] 12 | -------------------------------------------------------------------------------- /4/producer/producer/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var app = express() 3 | var log = require('./produce.js') 4 | 5 | var response = 'Hello World!' 6 | 7 | app.get('/', function (req, res) { 8 | res.send(response) 9 | log(response) 10 | }) 11 | 12 | /* istanbul ignore next */ 13 | function onListen () { 14 | var host = server.address().address 15 | var port = server.address().port 16 | 17 | console.log('Example app listening at http://%s:%s', host, port) 18 | } 19 | 20 | /* istanbul ignore next */ 21 | if(module.parent) { 22 | module.exports = app 23 | } else { 24 | server = app.listen(3000, onListen) 25 | } 26 | -------------------------------------------------------------------------------- /4/producer/producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3" 6 | }, 7 | "devDependencies": { 8 | "nyc": "^9.0.1", 9 | "supertest": "^2.0.1", 10 | "tape": "^4.6.2" 11 | }, 12 | "scripts": { 13 | "test": "nyc tape ./test/*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /4/producer/producer/produce.js: -------------------------------------------------------------------------------- 1 | // Publisher 2 | var amqp = require('amqplib/callback_api') 3 | var async = require('async') 4 | var q = 'log' 5 | var conn 6 | 7 | function connect () { 8 | async.during(singleConnect, waitingForConnection, function (e) { 9 | console.log('Connected to RabbitMQ!') 10 | }) 11 | } 12 | 13 | function singleConnect (cb) { 14 | console.log('Trying to connect to rabbitmq...') 15 | return amqp.connect('amqp://rabbitmq', function (e, c) { 16 | conn = c 17 | return cb(null, e) 18 | }) 19 | } 20 | 21 | function waitingForConnection (cb) { 22 | console.log('Connection to rabbitmq failed, retrying...') 23 | setTimeout(cb, 1000) 24 | } 25 | 26 | connect() 27 | 28 | module.exports = function log (string) { 29 | conn.createChannel(function on_open (e, ch) { 30 | if (e != null) { 31 | return console.log(e) 32 | } 33 | ch.assertQueue(q) 34 | ch.sendToQueue(q, new Buffer(string)) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /4/run.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | links: 7 | - rabbitmq 8 | ports: 9 | - 3000:3000 10 | nginx: 11 | image: nginx 12 | volumes: 13 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 14 | ports: 15 | - 8080:8080 16 | links: 17 | - producer 18 | consumer: 19 | build: ./consumer 20 | image: retrohacker/presentation:consumer 21 | links: 22 | - rabbitmq 23 | rabbitmq: 24 | image: rabbitmq 25 | -------------------------------------------------------------------------------- /4/test.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | links: 7 | - rabbitmq 8 | ports: 9 | - 3000:3000 10 | nginx: 11 | image: nginx 12 | volumes: 13 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 14 | ports: 15 | - 8080:8080 16 | links: 17 | - producer 18 | consumer: 19 | build: ./consumer 20 | links: 21 | - rabbitmq 22 | rabbitmq: 23 | image: rabbitmq 24 | integration: 25 | image: retrohacker/presentation:integration-test 26 | build: ./test 27 | environment: 28 | - PRODUCER_HOST=nginx 29 | - PRODUCER_PORT=8080 30 | - NGINX_HOST=nginx 31 | - NGINX_PORT=8080 32 | links: 33 | - nginx 34 | - producer 35 | -------------------------------------------------------------------------------- /4/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | WORKDIR /usr/src/app 4 | 5 | ENV NODE_ENV dev 6 | 7 | ADD package.json ./ 8 | RUN npm install 9 | ADD * ./ 10 | 11 | CMD ["npm", "test"] 12 | -------------------------------------------------------------------------------- /4/test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var supertest = require('supertest') 3 | var async = require('async') 4 | var net = require('net') 5 | 6 | var producer_host = process.env['PRODUCER_HOST'] 7 | var producer_port = process.env['PRODUCER_PORT'] 8 | var producer = `http://${producer_host}:${producer_port}` 9 | 10 | var nginx_host = process.env['NGINX_HOST'] 11 | var nginx_port = process.env['NGINX_PORT'] 12 | var nginx = `http://${nginx_host}:${nginx_port}` 13 | 14 | var config = { 15 | user: process.env.PGUSER, 16 | database: process.env.PGDATABASE, 17 | password: process.env.PGPASSWORD, 18 | host: process.env.PGHOST, 19 | port: process.env.PGPORT, 20 | max: 10, 21 | idleTimeoutMillis: 30000, 22 | }; 23 | 24 | test('Waiting for producer to become available', function (t) { 25 | var client 26 | async.retry(function (cb) { 27 | t.comment(`Attempting to connect to ${producer_host}:${producer_port}...`) 28 | client = net.connect(producer_port, producer_host, cb) 29 | }, function (e) { 30 | t.error(e, 'producer is available') 31 | if(e) throw e 32 | client.unref() 33 | client.end() 34 | t.end() 35 | }) 36 | }) 37 | 38 | test('Waiting for nginx to become available', function (t) { 39 | var client 40 | async.retry(function (cb) { 41 | t.comment(`Attempting to connect to ${nginx_host}:${nginx_port}...`) 42 | client = net.connect(nginx_port, nginx_host, cb) 43 | }, function (e) { 44 | t.error(e, 'nginx is available') 45 | if(e) throw e 46 | client.unref() 47 | client.end() 48 | t.end() 49 | }) 50 | }) 51 | 52 | function helloWorldTestBuilder (url) { 53 | return function helloWorldTest (t) { 54 | supertest(url) 55 | .get('/') 56 | .expect(200, 'Hello World!') 57 | .end(function(e) { 58 | t.error(e, 'supertest assertions pass') 59 | t.end() 60 | }) 61 | } 62 | } 63 | 64 | test('Test producer', helloWorldTestBuilder(producer)) 65 | test('Test nginx fresh', helloWorldTestBuilder(nginx)) 66 | test('Test nginx cache', helloWorldTestBuilder(nginx)) 67 | -------------------------------------------------------------------------------- /4/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "async": "^2.1.2", 4 | "pg": "^6.1.0", 5 | "supertest": "^2.0.1", 6 | "tape": "^4.6.2" 7 | }, 8 | "scripts": { 9 | "test": "tape *.js" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /5/Makefile: -------------------------------------------------------------------------------- 1 | #.SILENT: 2 | help: 3 | echo 4 | echo "NodeSource Metrics Server Make commands" 5 | echo 6 | echo " Commands: " 7 | echo 8 | echo " help - show this message" 9 | echo " build - Build the Docker images that power local dev (docker)" 10 | echo " clean - Remove docker containers" 11 | echo " run - Start this service, and all of its deps, locally (docker)" 12 | echo " deploy - Deploy this app to Google Cloud (kubernetes)" 13 | echo " provision-cluster - Provision a remote kubernetes cluster" 14 | echo " delete-cluster - Remove a remote kubernetes cluster" 15 | echo " dashboard - Start the kubectl dashboard" 16 | echo " test-integration - Run integration tests for this project" 17 | echo " test-all - Run all tests for this project" 18 | echo " deps - Check for all dependencies" 19 | 20 | build: clean 21 | docker-compose -f ./run.yml build 22 | docker tag 5_consumer gcr.io/core-falcon-135017/consumer:latest 23 | docker tag 5_producer gcr.io/core-falcon-135017/producer:latest 24 | docker tag 5_nginx gcr.io/core-falcon-135017/nginx:latest 25 | 26 | run: build 27 | docker-compose -f ./run.yml up 28 | 29 | clean: 30 | docker-compose -f ./run.yml rm -f 31 | docker-compose -f ./test.yml rm -f 32 | 33 | clean-deploy: clean 34 | gcloud config set project core-falcon-135017 35 | gcloud container clusters get-credentials presentation 36 | kubectl delete -f kube.yml || true 37 | 38 | deploy: clean-deploy build 39 | gcloud config set project core-falcon-135017 40 | gcloud docker push gcr.io/core-falcon-135017/consumer:latest 41 | gcloud docker push gcr.io/core-falcon-135017/producer:latest 42 | gcloud docker push gcr.io/core-falcon-135017/nginx:latest 43 | gcloud container clusters get-credentials presentation 44 | kubectl create -f kube.yml 45 | kubectl get services 46 | echo "Run `kubectl get services` to fetch NGinx's ip address" 47 | 48 | provision-cluster: 49 | gcloud config set project core-falcon-135017 50 | gcloud container clusters create presentation 51 | 52 | delete-cluster: 53 | gcloud config set project core-falcon-135017 54 | gcloud container clusters delete presentation -q 55 | 56 | dashboard: 57 | gcloud config set project core-falcon-135017 58 | gcloud container clusters get-credentials presentation 59 | echo "Navigate to 127.0.0.1:8001/ui in your browser" 60 | kubectl proxy 61 | 62 | build-test-integration: build 63 | docker-compose -f ./test.yml build 64 | 65 | test-integration: clean 66 | docker-compose -f ./test.yml up 67 | 68 | test-all: test-integration 69 | 70 | deps: 71 | echo " Dependencies: " 72 | echo 73 | echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 74 | echo " * docker-compose $(shell which docker-compose > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 75 | echo " * gcloud $(shell which gcloud > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 76 | echo " * kubectl $(shell which kubectl > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')" 77 | echo 78 | -------------------------------------------------------------------------------- /5/consumer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | EXPOSE 3000 4 | 5 | ADD consumer/package.json package.json 6 | RUN npm install 7 | 8 | ADD consumer/ . 9 | 10 | CMD ["node","app.js"] 11 | -------------------------------------------------------------------------------- /5/consumer/consumer/app.js: -------------------------------------------------------------------------------- 1 | var on_log = require('./consume.js') 2 | 3 | on_log(function log (msg) { 4 | console.log(msg) 5 | }) 6 | -------------------------------------------------------------------------------- /5/consumer/consumer/consume.js: -------------------------------------------------------------------------------- 1 | // Publisher 2 | var amqp = require('amqplib/callback_api') 3 | var async = require('async') 4 | var q = 'log' 5 | var conn 6 | var callback 7 | 8 | function connect () { 9 | async.during(singleConnect, waitingForConnection, function (e) { 10 | console.log('Connected to RabbitMQ!') 11 | conn.createChannel(function on_open (e, ch) { 12 | if (e != null) return console.error(e) 13 | ch.assertQueue(q) 14 | ch.consume(q, function (msg) { 15 | if (msg !== null) { 16 | callback(msg.content.toString()) 17 | ch.ack(msg) 18 | } 19 | }) 20 | }) 21 | }) 22 | } 23 | 24 | function singleConnect (cb) { 25 | console.log('Trying to connect to rabbitmq...') 26 | return amqp.connect('amqp://rabbitmq', function (e, c) { 27 | conn = c 28 | return cb(null, e) 29 | }) 30 | } 31 | 32 | function waitingForConnection (cb) { 33 | console.log('Connection to rabbitmq failed, retrying...') 34 | setTimeout(cb, 1000) 35 | } 36 | 37 | connect() 38 | 39 | module.exports = function on_log (cb) { 40 | callback = cb 41 | } 42 | -------------------------------------------------------------------------------- /5/consumer/consumer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /5/kube.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceList 3 | items: 4 | - apiVersion: v1 5 | kind: Service 6 | metadata: 7 | name: producer 8 | spec: 9 | ports: 10 | - port: 3000 11 | targetPort: 3000 12 | selector: 13 | app: producer 14 | - apiVersion: v1 15 | kind: Service 16 | metadata: 17 | name: nginx 18 | spec: 19 | sessionAffinity: ClientIP 20 | type: LoadBalancer 21 | ports: 22 | - port: 80 23 | targetPort: 8080 24 | selector: 25 | app: nginx 26 | - apiVersion: v1 27 | kind: Service 28 | metadata: 29 | name: rabbitmq 30 | spec: 31 | ports: 32 | - port: 5672 33 | targetPort: 5672 34 | selector: 35 | app: rabbitmq 36 | --- 37 | apiVersion: extensions/v1beta1 38 | kind: DeploymentList 39 | items: 40 | - apiVersion: extensions/v1beta1 41 | kind: Deployment 42 | metadata: 43 | labels: 44 | app: producer 45 | name: producer 46 | spec: 47 | replicas: 1 48 | template: 49 | metadata: 50 | labels: 51 | app: producer 52 | spec: 53 | containers: 54 | - image: gcr.io/core-falcon-135017/producer:latest 55 | name: producer 56 | ports: 57 | - containerPort: 3000 58 | - apiVersion: extensions/v1beta1 59 | kind: Deployment 60 | metadata: 61 | name: consumer 62 | labels: 63 | app: consumer 64 | spec: 65 | replicas: 4 66 | template: 67 | metadata: 68 | labels: 69 | app: consumer 70 | spec: 71 | containers: 72 | - name: consumer 73 | image: gcr.io/core-falcon-135017/consumer:latest 74 | - apiVersion: extensions/v1beta1 75 | kind: Deployment 76 | metadata: 77 | name: nginx 78 | labels: 79 | app: nginx 80 | spec: 81 | replicas: 1 82 | template: 83 | metadata: 84 | labels: 85 | app: nginx 86 | spec: 87 | containers: 88 | - name: nginx 89 | image: gcr.io/core-falcon-135017/nginx:latest 90 | ports: 91 | - containerPort: 8080 92 | - apiVersion: extensions/v1beta1 93 | kind: Deployment 94 | metadata: 95 | name: rabbitmq 96 | labels: 97 | app: rabbitmq 98 | spec: 99 | replicas: 1 100 | template: 101 | metadata: 102 | labels: 103 | app: rabbitmq 104 | spec: 105 | containers: 106 | - name: rabbitmq 107 | image: "rabbitmq" 108 | -------------------------------------------------------------------------------- /5/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx 2 | ADD producer.conf /etc/nginx/conf.d/producer.conf 3 | -------------------------------------------------------------------------------- /5/nginx/producer.conf: -------------------------------------------------------------------------------- 1 | upstream producer { 2 | server producer:3000; 3 | } 4 | 5 | proxy_cache_path /tmp/producer keys_zone=producer:25m; 6 | 7 | 8 | server { 9 | listen 8080; 10 | 11 | gzip on; 12 | gzip_static on; 13 | gzip_disable "MSIE [1-6]\."; 14 | default_type text/html; 15 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; 16 | 17 | location / { 18 | proxy_cache producer; 19 | proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; 20 | proxy_cache_valid 1m; 21 | proxy_connect_timeout 10s; 22 | 23 | proxy_pass http://producer; 24 | proxy_read_timeout 90; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /5/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | ADD producer/package.json package.json 4 | RUN npm install 5 | 6 | ADD producer/ . 7 | 8 | CMD ["node","index.js"] 9 | -------------------------------------------------------------------------------- /5/producer/producer/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var app = express() 3 | var log = require('./produce.js') 4 | 5 | var response = 'Hello World!' 6 | 7 | app.get('/', function (req, res) { 8 | res.send(response) 9 | log(response) 10 | }) 11 | 12 | /* istanbul ignore next */ 13 | function onListen () { 14 | var host = server.address().address 15 | var port = server.address().port 16 | 17 | console.log('Example app listening at http://%s:%s', host, port) 18 | } 19 | 20 | /* istanbul ignore next */ 21 | if(module.parent) { 22 | module.exports = app 23 | } else { 24 | server = app.listen(3000, onListen) 25 | } 26 | -------------------------------------------------------------------------------- /5/producer/producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "amqplib": "^0.4.0", 4 | "async": "^1.4.2", 5 | "express": "^4.13.3" 6 | }, 7 | "devDependencies": { 8 | "nyc": "^9.0.1", 9 | "supertest": "^2.0.1", 10 | "tape": "^4.6.2" 11 | }, 12 | "scripts": { 13 | "test": "nyc tape ./test/*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /5/producer/producer/produce.js: -------------------------------------------------------------------------------- 1 | // Publisher 2 | var amqp = require('amqplib/callback_api') 3 | var async = require('async') 4 | var q = 'log' 5 | var conn 6 | 7 | function connect () { 8 | async.during(singleConnect, waitingForConnection, function (e) { 9 | console.log('Connected to RabbitMQ!') 10 | }) 11 | } 12 | 13 | function singleConnect (cb) { 14 | console.log('Trying to connect to rabbitmq...') 15 | return amqp.connect('amqp://rabbitmq', function (e, c) { 16 | conn = c 17 | return cb(null, e) 18 | }) 19 | } 20 | 21 | function waitingForConnection (cb) { 22 | console.log('Connection to rabbitmq failed, retrying...') 23 | setTimeout(cb, 1000) 24 | } 25 | 26 | connect() 27 | 28 | module.exports = function log (string) { 29 | conn.createChannel(function on_open (e, ch) { 30 | if (e != null) { 31 | return console.log(e) 32 | } 33 | ch.assertQueue(q) 34 | ch.sendToQueue(q, new Buffer(string)) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /5/run.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | links: 7 | - rabbitmq 8 | ports: 9 | - 3000:3000 10 | nginx: 11 | image: nginx 12 | volumes: 13 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 14 | ports: 15 | - 8080:8080 16 | links: 17 | - producer 18 | consumer: 19 | build: ./consumer 20 | image: retrohacker/presentation:consumer 21 | links: 22 | - rabbitmq 23 | rabbitmq: 24 | image: rabbitmq 25 | -------------------------------------------------------------------------------- /5/test.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | producer: 4 | build: ./producer 5 | image: retrohacker/presentation:producer 6 | links: 7 | - rabbitmq 8 | ports: 9 | - 3000:3000 10 | nginx: 11 | image: nginx 12 | volumes: 13 | - ./nginx/producer.conf:/etc/nginx/conf.d/producer.conf:ro 14 | ports: 15 | - 8080:8080 16 | links: 17 | - producer 18 | consumer: 19 | build: ./consumer 20 | links: 21 | - rabbitmq 22 | rabbitmq: 23 | image: rabbitmq 24 | integration: 25 | image: retrohacker/presentation:integration-test 26 | build: ./test 27 | environment: 28 | - PRODUCER_HOST=nginx 29 | - PRODUCER_PORT=8080 30 | - NGINX_HOST=nginx 31 | - NGINX_PORT=8080 32 | links: 33 | - nginx 34 | - producer 35 | -------------------------------------------------------------------------------- /5/test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | WORKDIR /usr/src/app 4 | 5 | ENV NODE_ENV dev 6 | 7 | ADD package.json ./ 8 | RUN npm install 9 | ADD * ./ 10 | 11 | CMD ["npm", "test"] 12 | -------------------------------------------------------------------------------- /5/test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var supertest = require('supertest') 3 | var async = require('async') 4 | var net = require('net') 5 | 6 | var producer_host = process.env['PRODUCER_HOST'] 7 | var producer_port = process.env['PRODUCER_PORT'] 8 | var producer = `http://${producer_host}:${producer_port}` 9 | 10 | var nginx_host = process.env['NGINX_HOST'] 11 | var nginx_port = process.env['NGINX_PORT'] 12 | var nginx = `http://${nginx_host}:${nginx_port}` 13 | 14 | var config = { 15 | user: process.env.PGUSER, 16 | database: process.env.PGDATABASE, 17 | password: process.env.PGPASSWORD, 18 | host: process.env.PGHOST, 19 | port: process.env.PGPORT, 20 | max: 10, 21 | idleTimeoutMillis: 30000, 22 | }; 23 | 24 | test('Waiting for producer to become available', function (t) { 25 | var client 26 | async.retry(function (cb) { 27 | t.comment(`Attempting to connect to ${producer_host}:${producer_port}...`) 28 | client = net.connect(producer_port, producer_host, cb) 29 | }, function (e) { 30 | t.error(e, 'producer is available') 31 | if(e) throw e 32 | client.unref() 33 | client.end() 34 | t.end() 35 | }) 36 | }) 37 | 38 | test('Waiting for nginx to become available', function (t) { 39 | var client 40 | async.retry(function (cb) { 41 | t.comment(`Attempting to connect to ${nginx_host}:${nginx_port}...`) 42 | client = net.connect(nginx_port, nginx_host, cb) 43 | }, function (e) { 44 | t.error(e, 'nginx is available') 45 | if(e) throw e 46 | client.unref() 47 | client.end() 48 | t.end() 49 | }) 50 | }) 51 | 52 | function helloWorldTestBuilder (url) { 53 | return function helloWorldTest (t) { 54 | supertest(url) 55 | .get('/') 56 | .expect(200, 'Hello World!') 57 | .end(function(e) { 58 | t.error(e, 'supertest assertions pass') 59 | t.end() 60 | }) 61 | } 62 | } 63 | 64 | test('Test producer', helloWorldTestBuilder(producer)) 65 | test('Test nginx fresh', helloWorldTestBuilder(nginx)) 66 | test('Test nginx cache', helloWorldTestBuilder(nginx)) 67 | -------------------------------------------------------------------------------- /5/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "async": "^2.1.2", 4 | "pg": "^6.1.0", 5 | "supertest": "^2.0.1", 6 | "tape": "^4.6.2" 7 | }, 8 | "scripts": { 9 | "test": "tape *.js" 10 | } 11 | } 12 | --------------------------------------------------------------------------------