From 484420bbd98907ab1383f33aa66f3ff4de5485f6 Mon Sep 17 00:00:00 2001
From: Cole Christie <colec.mobile@gmail.com>
Date: Thu, 20 Sep 2018 16:02:51 -0700
Subject: [PATCH] Address issues with building the container on Linux vs Mac,
 reduce image size

---
 Dockerfile | 32 +++++++++++++++++---------------
 README.md  |  4 ++--
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 9f10bcd80..513c56e3e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,15 +3,18 @@
 # Source material: https://derickbailey.com/2017/05/31/how-a-650mb-node-js-image-for-docker-uses-less-space-than-a-50mb-image/
 # Source material: https://hub.docker.com/_/node/
 
+
+### Builder Stage (Multi-Stage Docker Build)
 # Use the slimed NodeJS source, yielding a space savings of 600MB (~66% of total)
-FROM node:alpine
+FROM node:alpine as builder
+ENV NODEROOT /usr/src/app/
 
 # Create app directory
-WORKDIR /usr/src/app
+WORKDIR $NODEROOT
 
 # Install app dependencies
-# A wildcard is used to ensure both package.json AND package-lock.json AND tslint.json AND tsconfig.json are copied
-# where available (npm@5+)
+# A wildcard is used to ensure the following are copied
+# package.json AND package-lock.json AND tslint.json AND tsconfig.json are copied where available (npm@5+)
 COPY *.json ./
 
 # Install all dependencies and copy results
@@ -21,17 +24,16 @@ COPY . .
 # Build library and canvas application then copy results
 RUN npm run build
 RUN npm run build-canvas
-COPY build/canvas/ build/canvas/
-
-# Open ports for HTTP
-EXPOSE 8080/tcp
+COPY . .
 
-# Setup standalone simple webserver to run the demo
-RUN npm install http-server -g
+### Runtime Stage (Multi-Stage Docker Build)
+FROM httpd:2.4 as runtime
+ENV NODEROOT /usr/src/app
+ENV HTTPDROOT /usr/local/apache2/htdocs/
 
-# Start NodeJS at container stand up
-CMD [ "http-server", "build/canvas/", "-p", "8080" ]
+## Code must be placed into /usr/local/apache2/htdocs/
+WORKDIR $HTTPDROOT
+COPY --from=builder $NODEROOT/build/canvas/ .
 
-# Developer helpers (what is inside this container?)
-RUN node -v
-RUN ls -alh
+# Open ports for HTTP
+EXPOSE 80
diff --git a/README.md b/README.md
index dde6fcb35..6544cb77d 100644
--- a/README.md
+++ b/README.md
@@ -83,11 +83,11 @@ and navigate to `build/viewer`
 
 Build the docker image
 
-    docker build -t molstar-proto .
+    docker build -t molstar/proto:httpd .
 
 Run the image
 
-    docker run -p 8080:8080 molstar-proto
+    docker run -d -p 80:80 molstar/proto:httpd
 
 
 
-- 
GitLab