Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ hello:
build: hello/
links:
- consul:consul
goodbye:
build: goodbye/
links:
- consul:consul
world:
build: world/
links:
Expand Down
25 changes: 25 additions & 0 deletions goodbye/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
15 changes: 15 additions & 0 deletions goodbye/containerpilot.json5
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
15 changes: 15 additions & 0 deletions goodbye/index.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
18 changes: 18 additions & 0 deletions goodbye/kube-deployment.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions goodbye/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions goodbye/test/index.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
2 changes: 1 addition & 1 deletion nginx/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2></h2>
};

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];
Expand Down
16 changes: 8 additions & 8 deletions nginx/nginx.conf.ctmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}}

Expand Down
Binary file added skywind_docker_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skywind_docker_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.