Skip to content
This repository was archived by the owner on Apr 27, 2021. It is now read-only.
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from nginx
add . /usr/share/nginx/html/
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions s/webrtc-from-chat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from node:boron
expose 6503
add package.json .
run npm install
add chatserver.js .
cmd ["node", "chatserver"]
32 changes: 8 additions & 24 deletions s/webrtc-from-chat/chatserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
});

Expand Down
6 changes: 6 additions & 0 deletions s/websocket-chat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from node:boron
expose 6502
add package.json .
run npm install
add chatserver.js .
cmd ["node", "chatserver"]