From ed145705460bb113da860de5ee06c0b1098118ff Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 25 Mar 2020 13:54:13 +0100 Subject: [PATCH] Fixed Dockerfile and parametrized backend URL --- Dockerfile | 55 +++++++++++++++------------------- nginx/nginx.conf | 48 +++++++++++++++++++++++++++++ smart-hut/public/index.html | 4 +++ smart-hut/src/client_server.js | 2 +- 4 files changed, 77 insertions(+), 32 deletions(-) create mode 100644 nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile index 18cd721..8ac8f02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,32 @@ -#FROM mhart/alpine-node:11 AS pleaseGodWork -#WORKDIR /app -#COPY . /app -#RUN ls -#RUN yarn run build -# -#RUN yarn global add serve -# -# -#CMD ["serve", "-p", "8080", "-s", "."] +FROM node:9-alpine as builder -# base image -FROM node:9.6.1 -RUN mkdir /usr/src/app +RUN mkdir -p /usr/src/app WORKDIR /usr/src/app + ENV PATH /usr/src/app/node_modules/.bin:$PATH - -COPY smart-hut/package.json /usr/src/app/package.json -RUN npm install --silent -RUN npm install react-scripts@1.1.1 -g --silent - - -CMD ["npm", "start"] - -FROM node:9.6.1 as builder -RUN mkdir /usr/src/app -WORKDIR /usr/src/app -ENV PATH /usr/src/app/node_modules/.bin:$PATH -COPY smart-hut/package.json /usr/src/app/package.json -RUN npm install --silent -RUN npm install react-scripts@1.1.1 -g --silent COPY smart-hut/. /usr/src/app + +RUN npm install --silent +RUN npm install react-scripts@1.1.1 -g --silent RUN npm run build -FROM nginx:1.13.9-alpine + +FROM nginx:alpine + +# Install envsubst +RUN apk add --no-cache gettext + COPY --from=builder /usr/src/app/build /usr/share/nginx/html -EXPOSE 8080 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file + +# Delete default config +RUN rm -r /etc/nginx/conf.d && rm /etc/nginx/nginx.conf + +# Create folder for PID file +RUN mkdir -p /run/nginx + +# Copy nginx config +COPY nginx/nginx.conf /etc/nginx/nginx.template.conf + +EXPOSE 80 +ENTRYPOINT ["/bin/sh", "-c", "envsubst '${BACKEND_URL}' /etc/nginx/nginx.conf && nginx -g 'daemon off;'"] diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..8bb34e3 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,48 @@ +# vim: set ft=nginx ts=4 sw=4 et tw=80: + +include /etc/nginx/modules/*.conf; + +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +pcre_jit on; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + + keepalive_timeout 65; + + server { + listen 80; + + root /usr/share/nginx/html; + index index.html index.htm; + + location / { + sub_filter "__BACKEND_URL__" ${BACKEND_URL}; + try_files $uri $uri/ /index.html; + } + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /usr/share/nginx/html; + } + } +} diff --git a/smart-hut/public/index.html b/smart-hut/public/index.html index 3c85f6b..fe04f39 100644 --- a/smart-hut/public/index.html +++ b/smart-hut/public/index.html @@ -2,6 +2,10 @@ + +