diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..80557db --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +# Client +.DS_STORE +node_modules +dist +coverage/ +.nyc_output/ +*.log +.env +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3f9e7fe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# build +FROM node:6-alpine AS build + +WORKDIR /app +COPY . . + +ARG CONTROLLER_SERVICE=http://lw-controller:8080 +ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" + +RUN cd /app \ + && apk add --no-cache --virtual .build-deps alpine-sdk python \ + && npm install \ + && npm run deploy:prod \ + && apk del .build-deps + +# run +FROM nginx:stable + +COPY --from=build /app/dist/ /var/www/ +COPY --from=build /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf diff --git a/onestep.Dockerfile b/onestep.Dockerfile new file mode 100644 index 0000000..d6c6051 --- /dev/null +++ b/onestep.Dockerfile @@ -0,0 +1,24 @@ +# similar to Dockerfile, but uses Apache HTTPd and does not use multi-stage build +FROM httpd:2.4 + +ARG CONTROLLER_SERVICE=http://lw-controller:8080 +ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" +RUN echo "Using ${CONTROLLER_SERVICE}" + +WORKDIR /app +COPY . . + +RUN apt-get update \ + && apt-get install -y curl gnupg \ + && (curl -sL https://deb.nodesource.com/setup_8.x | bash -) \ + && apt-get update \ + && apt-get install -y python build-essential nodejs \ + && npm install \ + && npm run deploy:prod \ + && rm -rf node_modules \ + && mv -f /app/dist/* /usr/local/apache2/htdocs/ \ + && apt-get remove -y python build-essential nodejs curl + +# Listen on 8080 +RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf +EXPOSE 8080 diff --git a/package.json b/package.json index 5613491..8c0c4c8 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,7 @@ "koa-static": "3.0.0", "material-ui": "0.16.7", "moment": "2.20.1", - "node-sass": "3.13.1", + "node-sass": "4.9.3", "nodemon": "1.14.9", "normalize.css": "4.2.0", "postcss-loader": "0.9.1", diff --git a/src/static/.htaccess b/src/static/.htaccess new file mode 100644 index 0000000..3fa8a40 --- /dev/null +++ b/src/static/.htaccess @@ -0,0 +1,11 @@ + + + RewriteEngine On + RewriteBase / + RewriteRule ^index\.html$ - [L] + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-l + RewriteRule . /index.html [L] + + diff --git a/src/static/docker-nginx.conf b/src/static/docker-nginx.conf new file mode 100644 index 0000000..ca0b7aa --- /dev/null +++ b/src/static/docker-nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80 default_server; + server_name localhost; + + root /var/www; + index index.html index.htm; + + location ~* \.(?:manifest|appcache|html?|xml|json)$ { + expires -1; + # access_log logs/static.log; # I don't usually include a static log + } + + location ~* \.(?:css|js)$ { + try_files $uri =404; + expires 1y; + add_header Cache-Control "public"; + access_log off; + } + + # Any route containing a file extension (e.g. /devicesfile.js) + location ~ ^.+\..+$ { + try_files $uri =404; + } + + # Any route that doesn't have a file extension (e.g. /devices) + location / { + try_files $uri $uri/ /index.html; + } +}