From 068b1a2c0ed79e49324e75a9e635d03471fe241d Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Tue, 2 Oct 2018 15:24:34 +0200 Subject: [PATCH 01/11] docker image for webui --- .dockerignore | 8 ++++++++ Dockerfile | 19 +++++++++++++++++++ src/static/docker-nginx.conf | 29 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 src/static/docker-nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9a5e993 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Client +.DS_STORE +node_modules +dist +coverage/ +.nyc_output/ +*.log +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..352a671 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# 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 \ + && 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/src/static/docker-nginx.conf b/src/static/docker-nginx.conf new file mode 100644 index 0000000..d82c341 --- /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; + access_log off; + add_header Cache-Control "public"; + } + + # 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; + } +} From c480036701aee0513f0c7cb3cd36e073209b3ee7 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Tue, 2 Oct 2018 15:35:14 +0200 Subject: [PATCH 02/11] missing app build step --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 352a671..3f9e7fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ 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 fd088935edc1cfaa61679f1f95959ddf254354ca Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Tue, 2 Oct 2018 16:52:44 +0200 Subject: [PATCH 03/11] a dockerfile without stages --- .dockerignore | 1 + onestep.Dockerfile | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 onestep.Dockerfile diff --git a/.dockerignore b/.dockerignore index 9a5e993..80557db 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,3 +6,4 @@ coverage/ .nyc_output/ *.log .env +.git diff --git a/onestep.Dockerfile b/onestep.Dockerfile new file mode 100644 index 0000000..681fc12 --- /dev/null +++ b/onestep.Dockerfile @@ -0,0 +1,16 @@ +# build +FROM nginx:stable-alpine + +ARG CONTROLLER_SERVICE=http://lw-controller:8080 +ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" + +WORKDIR /app +COPY . . + +RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ + && npm install \ + && npm run deploy:prod \ + && apk del .build-deps + +RUN cp /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf +RUN mv /app/dist/ /var/www/ From 4dd2f9282414f8ebaee88e5313b23356e8d461b6 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Tue, 2 Oct 2018 17:26:45 +0200 Subject: [PATCH 04/11] add cmd --- onestep.Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 681fc12..7a34e69 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -14,3 +14,5 @@ RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ RUN cp /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf RUN mv /app/dist/ /var/www/ + +CMD ["nginx", "-g", "daemon off;"] From 58e97f8c64718ed83afe99edfc695220e976caa4 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Tue, 2 Oct 2018 17:38:51 +0200 Subject: [PATCH 05/11] remove logs --- onestep.Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 7a34e69..4720ae5 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -15,4 +15,6 @@ RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ RUN cp /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf RUN mv /app/dist/ /var/www/ +RUN rm /var/log/nginx/access.log /var/log/nginx/error.log + CMD ["nginx", "-g", "daemon off;"] From 58bdbe728e057cacf2df232fbb2adaf98f638346 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Wed, 3 Oct 2018 08:57:08 +0200 Subject: [PATCH 06/11] redirect logs --- src/static/docker-nginx.conf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/static/docker-nginx.conf b/src/static/docker-nginx.conf index d82c341..51b6bd3 100644 --- a/src/static/docker-nginx.conf +++ b/src/static/docker-nginx.conf @@ -2,6 +2,9 @@ server { listen 80 default_server; server_name localhost; + error_log /dev/stderr; + access_log /dev/stdout; + root /var/www; index index.html index.htm; @@ -13,7 +16,6 @@ server { location ~* \.(?:css|js)$ { try_files $uri =404; expires 1y; - access_log off; add_header Cache-Control "public"; } From 4cdc2182ef653fcf3f26397a6c88623dedabb166 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Wed, 3 Oct 2018 09:20:44 +0200 Subject: [PATCH 07/11] use base image --- onestep.Dockerfile | 18 +++++++++++++----- src/static/docker-nginx.conf | 4 +--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 4720ae5..896bba6 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -1,5 +1,5 @@ # build -FROM nginx:stable-alpine +FROM nginx:stable ARG CONTROLLER_SERVICE=http://lw-controller:8080 ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" @@ -7,14 +7,22 @@ ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" WORKDIR /app COPY . . -RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ +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 \ - && apk del .build-deps + && rm -rf node_modules \ + && apt-get remove -y python build-essential nodejs curl gnupg + +# RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ +# && npm install \ +# && npm run deploy:prod \ +# && apk del .build-deps RUN cp /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf RUN mv /app/dist/ /var/www/ -RUN rm /var/log/nginx/access.log /var/log/nginx/error.log - CMD ["nginx", "-g", "daemon off;"] diff --git a/src/static/docker-nginx.conf b/src/static/docker-nginx.conf index 51b6bd3..ca0b7aa 100644 --- a/src/static/docker-nginx.conf +++ b/src/static/docker-nginx.conf @@ -2,9 +2,6 @@ server { listen 80 default_server; server_name localhost; - error_log /dev/stderr; - access_log /dev/stdout; - root /var/www; index index.html index.htm; @@ -17,6 +14,7 @@ server { try_files $uri =404; expires 1y; add_header Cache-Control "public"; + access_log off; } # Any route containing a file extension (e.g. /devicesfile.js) From b6a61348c4af1850cd5cc534c9ca9b5c2df5654b Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Wed, 3 Oct 2018 09:38:30 +0200 Subject: [PATCH 08/11] using apache --- onestep.Dockerfile | 13 +++---------- src/static/.htaccess | 11 +++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/static/.htaccess diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 896bba6..103ac22 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -1,8 +1,9 @@ # build -FROM nginx:stable +FROM httpd:2.4 ARG CONTROLLER_SERVICE=http://lw-controller:8080 ENV CONTROLLER_SERVICE="${CONTROLLER_SERVICE}" +RUN echo "Using ${CONTROLLER_SERVICE}" WORKDIR /app COPY . . @@ -17,12 +18,4 @@ RUN apt-get update \ && rm -rf node_modules \ && apt-get remove -y python build-essential nodejs curl gnupg -# RUN apk add --no-cache --virtual .build-deps nodejs alpine-sdk python \ -# && npm install \ -# && npm run deploy:prod \ -# && apk del .build-deps - -RUN cp /app/dist/docker-nginx.conf /etc/nginx/conf.d/default.conf -RUN mv /app/dist/ /var/www/ - -CMD ["nginx", "-g", "daemon off;"] +RUN mv /app/dist/ /usr/local/apache2/htdocs/ 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] + + From 55ebb35c442d0a4f8028d01644260d2fd78dc621 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Wed, 3 Oct 2018 09:49:52 +0200 Subject: [PATCH 09/11] keep gnupg --- onestep.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 103ac22..719f8e9 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -16,6 +16,6 @@ RUN apt-get update \ && npm install \ && npm run deploy:prod \ && rm -rf node_modules \ - && apt-get remove -y python build-essential nodejs curl gnupg + && apt-get remove -y python build-essential nodejs curl RUN mv /app/dist/ /usr/local/apache2/htdocs/ From 1d62371a6c7eed1f83d0effc37d9251ada322f9d Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Wed, 3 Oct 2018 10:29:43 +0200 Subject: [PATCH 10/11] listen on 8080 --- onestep.Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/onestep.Dockerfile b/onestep.Dockerfile index 719f8e9..d6c6051 100644 --- a/onestep.Dockerfile +++ b/onestep.Dockerfile @@ -1,4 +1,4 @@ -# build +# 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 @@ -16,6 +16,9 @@ RUN apt-get update \ && 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 -RUN mv /app/dist/ /usr/local/apache2/htdocs/ +# Listen on 8080 +RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf +EXPOSE 8080 From f8e2f8559ad862e8be6a3fd6c96832def3194bc8 Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Sun, 7 Oct 2018 16:29:36 +0200 Subject: [PATCH 11/11] a more recent node-saas to avoid compilation of binary --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",