From 7d0a41ca854f0a2d909e2cf7e79aee9f8b9d5774 Mon Sep 17 00:00:00 2001 From: Josh Mize Date: Mon, 6 Nov 2017 17:26:54 -0600 Subject: [PATCH 1/3] Add Dockerfiles and Makefile --- Dockerfile | 2 ++ Makefile | 20 ++++++++++++++++++++ s/webrtc-from-chat/Dockerfile | 6 ++++++ s/webrtc-from-chat/chatserver.js | 32 ++++++++------------------------ s/websocket-chat/Dockerfile | 6 ++++++ 5 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 s/webrtc-from-chat/Dockerfile create mode 100644 s/websocket-chat/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4870b0f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +from nginx +add . /usr/share/nginx/html/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..70facce --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +GIT_COMMIT ?= HEAD +VERSION ?= $(shell git rev-parse --short ${GIT_COMMIT}) +REGISTRY ?= quay.io/ +IMAGE_PREFIX ?= mozmar +NGINX_IMAGE_NAME ?= mdn-samples-nginx +NGINX_IMAGE ?= ${REGISTRY}${IMAGE_PREFIX}/${NGINX_IMAGE_NAME}\:${VERSION} +WEBRTC_IMAGE_NAME ?= mdn-samples-webrtc +WEBRTC_IMAGE ?= ${REGISTRY}${IMAGE_PREFIX}/${WEBRTC_IMAGE_NAME}\:${VERSION} +WEBSOCKET_IMAGE_NAME ?= mdn-samples-websocket +WEBSOCKET_IMAGE ?= ${REGISTRY}${IMAGE_PREFIX}/${WEBSOCKET_IMAGE_NAME}\:${VERSION} + +build: + docker build -t ${NGINX_IMAGE} . + cd s/webrtc-from-chat && docker build -t ${WEBRTC_IMAGE} . + cd s/websocket-chat && docker build -t ${WEBSOCKET_IMAGE} . + +push: + docker push ${NGINX_IMAGE} + docker push ${WEBRTC_IMAGE} + docker push ${WEBSOCKET_IMAGE} diff --git a/s/webrtc-from-chat/Dockerfile b/s/webrtc-from-chat/Dockerfile new file mode 100644 index 0000000..c9196da --- /dev/null +++ b/s/webrtc-from-chat/Dockerfile @@ -0,0 +1,6 @@ +from node:boron +expose 6503 +add package.json . +run npm install +add chatserver.js . +cmd ["node", "chatserver"] diff --git a/s/webrtc-from-chat/chatserver.js b/s/webrtc-from-chat/chatserver.js index bc6bd21..32c15be 100644 --- a/s/webrtc-from-chat/chatserver.js +++ b/s/webrtc-from-chat/chatserver.js @@ -26,8 +26,7 @@ "use strict"; -//var http = require('http'); -var https = require('https'); +var http = require('http'); var url = require('url'); var fs = require('fs'); var WebSocketServer = require('websocket').server; @@ -134,36 +133,21 @@ function sendUserListToAll() { } } -// Load the key and certificate data to be used for our HTTPS/WSS -// server. +// Our HTTP server does nothing but service WebSocket +// connections. Real Web requests are handled elsewhere. +var httpServer = http.createServer(function(request, response) {}); -var httpsOptions = { - key: fs.readFileSync("/etc/pki/tls/private/mdn.key"), - cert: fs.readFileSync("/etc/pki/tls/certs/mdn.crt") -}; - -// Our HTTPS server does nothing but service WebSocket -// connections, so every request just returns 404. Real Web -// requests are handled by the main server on the box. If you -// want to, you can return real HTML here and serve Web content. - -var httpsServer = https.createServer(httpsOptions, function(request, response) { - log("Received secure request for " + request.url); - response.writeHead(404); - response.end(); -}); - -// Spin up the HTTPS server on the port assigned to this sample. +// Spin up the HTTP server on the port assigned to this sample. // This will be turned into a WebSocket port very shortly. -httpsServer.listen(6503, function() { +httpServer.listen(6503, function() { log("Server is listening on port 6503"); }); -// Create the WebSocket server by converting the HTTPS server into one. +// Create the WebSocket server by converting the HTTP server into one. var wsServer = new WebSocketServer({ - httpServer: httpsServer, + httpServer: httpServer, autoAcceptConnections: false }); diff --git a/s/websocket-chat/Dockerfile b/s/websocket-chat/Dockerfile new file mode 100644 index 0000000..a3827dd --- /dev/null +++ b/s/websocket-chat/Dockerfile @@ -0,0 +1,6 @@ +from node:boron +expose 6502 +add package.json . +run npm install +add chatserver.js . +cmd ["node", "chatserver"] From 01a59f85535ce10f78ccc5fe6bac646e12a5cb16 Mon Sep 17 00:00:00 2001 From: Josh Mize Date: Mon, 6 Nov 2017 21:57:05 -0600 Subject: [PATCH 2/3] add initial k8s deployment & service --- Makefile | 4 ++++ k8s/deployment.yaml | 27 +++++++++++++++++++++++++++ k8s/service.yaml | 23 +++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 k8s/deployment.yaml create mode 100644 k8s/service.yaml diff --git a/Makefile b/Makefile index 70facce..dd68d89 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ WEBRTC_IMAGE_NAME ?= mdn-samples-webrtc WEBRTC_IMAGE ?= ${REGISTRY}${IMAGE_PREFIX}/${WEBRTC_IMAGE_NAME}\:${VERSION} WEBSOCKET_IMAGE_NAME ?= mdn-samples-websocket WEBSOCKET_IMAGE ?= ${REGISTRY}${IMAGE_PREFIX}/${WEBSOCKET_IMAGE_NAME}\:${VERSION} +NAMESPACE ?= mdn-samples build: docker build -t ${NGINX_IMAGE} . @@ -18,3 +19,6 @@ push: docker push ${NGINX_IMAGE} docker push ${WEBRTC_IMAGE} docker push ${WEBSOCKET_IMAGE} + +deploy: + kubectl -n ${NAMESPACE} apply -f k8s diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..6695256 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,27 @@ +kind: Deployment +apiVersion: extensions/v1beta1 +metadata: + name: mdn-samples +spec: + replicas: 1 + template: + metadata: + labels: + app: mdn-samples + spec: + containers: + - name: mdn-samples-nginx + image: "quay.io/mozmar/mdn-samples-nginx:7d0a41c" + imagePullPolicy: Always + ports: + - containerPort: 80 + - name: mdn-samples-webrtc + image: "quay.io/mozmar/mdn-samples-webrtc:7d0a41c" + imagePullPolicy: Always + ports: + - containerPort: 6503 + - name: mdn-samples-websocket + image: "quay.io/mozmar/mdn-samples-websocket:7d0a41c" + imagePullPolicy: Always + ports: + - containerPort: 6502 diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..1412785 --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,23 @@ +kind: Service +apiVersion: v1 +metadata: + name: mdn-samples-service + annotations: + service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:us-west-2:236517346949:certificate/921dce45-4537-4c2c-b4e4-0cc475e592ed +spec: + type: LoadBalancer + selector: + app: mdn-samples + ports: + - name: https + port: 443 + targetPort: 80 + protocol: TCP + - name: websocket + port: 6502 + targetPort: 6502 + protocol: TCP + - name: webrtc + port: 6503 + targetPort: 6503 + protocol: TCP From 4cfde5ad3158b139e7b004be6970435b04d445e8 Mon Sep 17 00:00:00 2001 From: Josh Mize Date: Mon, 6 Nov 2017 23:22:36 -0600 Subject: [PATCH 3/3] Add insecure ports --- k8s/service.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/k8s/service.yaml b/k8s/service.yaml index 1412785..728e979 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -4,11 +4,16 @@ metadata: name: mdn-samples-service annotations: service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:us-west-2:236517346949:certificate/921dce45-4537-4c2c-b4e4-0cc475e592ed + service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443,6503" spec: type: LoadBalancer selector: app: mdn-samples ports: + - name: http + port: 80 + targetPort: 80 + protocol: TCP - name: https port: 443 targetPort: 80