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..dd68d89 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +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} +NAMESPACE ?= mdn-samples + +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} + +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..728e979 --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,28 @@ +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 + 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 + protocol: TCP + - name: websocket + port: 6502 + targetPort: 6502 + protocol: TCP + - name: webrtc + port: 6503 + targetPort: 6503 + protocol: TCP 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"]