diff --git a/README.md b/README.md index 038d725..1ed520c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ The application is divided into 4 parts: ![application configuration diagram](application-diagram.jpg) +# Task results + +![web](skywind_docker_1.png) +![console](skywind_docker_2.png) + # Hello World running on Triton diff --git a/docker-compose.yml b/docker-compose.yml index 954fa82..a3c92d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,10 @@ hello: build: hello/ links: - consul:consul +goodbye: + build: goodbye/ + links: + - consul:consul world: build: world/ links: diff --git a/goodbye/Dockerfile b/goodbye/Dockerfile new file mode 100644 index 0000000..bb48ced --- /dev/null +++ b/goodbye/Dockerfile @@ -0,0 +1,25 @@ +FROM mhart/alpine-node:latest + +RUN apk update && \ + apk add curl + +# Install ContainerPilot +ENV CONTAINERPILOT_VER 3.0.0 +ENV CONTAINERPILOT /etc/containerpilot.json5 + +RUN export CONTAINERPILOT_CHECKSUM=6da4a4ab3dd92d8fd009cdb81a4d4002a90c8b7c \ + && curl -Lso /tmp/containerpilot.tar.gz \ + "https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \ + && echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \ + && tar zxf /tmp/containerpilot.tar.gz -C /bin \ + && rm /tmp/containerpilot.tar.gz + +# COPY ContainerPilot configuration +COPY containerpilot.json5 /etc/containerpilot.json5 +ENV CONTAINERPILOT=/etc/containerpilot.json5 + +# Install our application +COPY index.js /opt/hello/ + +EXPOSE 3003 +CMD ["/bin/containerpilot"] diff --git a/goodbye/containerpilot.json5 b/goodbye/containerpilot.json5 new file mode 100644 index 0000000..c2f0d87 --- /dev/null +++ b/goodbye/containerpilot.json5 @@ -0,0 +1,15 @@ +{ + consul: "consul:8500", + jobs: [ + { + name: "goodbye", + exec: "node /opt/hello/index.js", + port: 3003, + health: { + exec: "/usr/bin/curl -o /dev/null --fail -s http://localhost:3003/", + interval: 3, + ttl: 10 + } + } + ] +} diff --git a/goodbye/index.js b/goodbye/index.js new file mode 100644 index 0000000..890db41 --- /dev/null +++ b/goodbye/index.js @@ -0,0 +1,15 @@ +'use strict'; + +// Load modules + +const Http = require('http'); + + +const server = module.exports = Http.createServer((req, res) => { + res.writeHead(200); + res.end('Goodbye'); +}); + +server.listen(3003, () => { + console.log(`Goodbye server listening on port ${server.address().port}`); +}); diff --git a/goodbye/kube-deployment.yml b/goodbye/kube-deployment.yml new file mode 100644 index 0000000..b2e7dea --- /dev/null +++ b/goodbye/kube-deployment.yml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: hello + namespace: hello-world +spec: + replicas: 2 + template: + metadata: + labels: + app: hello + spec: + containers: + - image: gcr.io/jackzampolin-web/hello + imagePullPolicy: Always + name: hello + ports: + - containerPort: 3002 diff --git a/goodbye/package.json b/goodbye/package.json new file mode 100644 index 0000000..3029458 --- /dev/null +++ b/goodbye/package.json @@ -0,0 +1,17 @@ +{ + "name": "hello", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "lab -c" + }, + "keywords": [], + "author": "", + "license": "MPL-V2", + "devDependencies": { + "code": "3.x.x", + "lab": "11.x.x", + "wreck": "9.x.x" + } +} diff --git a/goodbye/test/index.js b/goodbye/test/index.js new file mode 100644 index 0000000..48f9126 --- /dev/null +++ b/goodbye/test/index.js @@ -0,0 +1,28 @@ +'use strict'; + +// Load modules + +const Code = require('code'); +const Lab = require('lab'); +const Wreck = require('wreck'); +const Hello = require('../'); + + +// Test shortcuts + +const lab = exports.lab = Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; + + +describe('Hello', () => { + it('responds with a 200 and the word "Hello"', (done) => { + Wreck.get(`http://localhost:${Hello.address().port}/`, (err, res, payload) => { + expect(err).to.not.exist(); + expect(res.statusCode).to.equal(200); + expect(payload.toString()).to.equal('Hello'); + done(); + }); + }); +}); diff --git a/nginx/index.html b/nginx/index.html index 69ea38f..ca548b3 100644 --- a/nginx/index.html +++ b/nginx/index.html @@ -18,7 +18,7 @@

}; function setHello () { - window.fetch('/hello').then(function (res) { + window.fetch('/goodbye').then(function (res) { return res.text(); }).then(function (val) { const h1 = document.getElementsByTagName('h1')[0]; diff --git a/nginx/nginx.conf.ctmpl b/nginx/nginx.conf.ctmpl index 8a8dade..4409549 100644 --- a/nginx/nginx.conf.ctmpl +++ b/nginx/nginx.conf.ctmpl @@ -24,10 +24,10 @@ http { keepalive_timeout 65; - {{ if service "hello" }} - upstream hello { + {{ if service "goodbye" }} + upstream goodbye { # write the address:port pairs for each healthy Hello node - {{range service "hello"}} + {{range service "goodbye"}} server {{.Address}}:{{.Port}}; {{end}} least_conn; @@ -55,12 +55,12 @@ http { deny all; } - {{ if service "hello" }} - location ^~ /hello { - # strip '/hello' from the request before passing + {{ if service "goodbye" }} + location ^~ /goodbye { + # strip '/goodbye' from the request before passing # it along to the Hello upstream - rewrite ^/hello(/.*)$ $1 break; - proxy_pass http://hello; + rewrite ^/goodbye(/.*)$ $1 break; + proxy_pass http://goodbye; proxy_redirect off; }{{end}} diff --git a/skywind_docker_1.png b/skywind_docker_1.png new file mode 100644 index 0000000..be3f1e5 Binary files /dev/null and b/skywind_docker_1.png differ diff --git a/skywind_docker_2.png b/skywind_docker_2.png new file mode 100644 index 0000000..adb25e0 Binary files /dev/null and b/skywind_docker_2.png differ