Fixed Dockerfile and parametrized backend URL

This commit is contained in:
Claudio Maggioni 2020-03-25 13:54:13 +01:00
parent cee6e3ce59
commit ed14570546
4 changed files with 77 additions and 32 deletions

View file

@ -1,39 +1,32 @@
#FROM mhart/alpine-node:11 AS pleaseGodWork FROM node:9-alpine as builder
#WORKDIR /app
#COPY . /app
#RUN ls
#RUN yarn run build
#
#RUN yarn global add serve
#
#
#CMD ["serve", "-p", "8080", "-s", "."]
# base image RUN mkdir -p /usr/src/app
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH 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 COPY smart-hut/. /usr/src/app
RUN npm install --silent
RUN npm install react-scripts@1.1.1 -g --silent
RUN npm run build 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 COPY --from=builder /usr/src/app/build /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"] # 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.template.conf >/etc/nginx/nginx.conf && nginx -g 'daemon off;'"]

48
nginx/nginx.conf Normal file
View file

@ -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;
}
}
}

View file

@ -2,6 +2,10 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<script>
window.BACKEND_URL = "__BACKEND_URL__";
</script>
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<link <link

View file

@ -2,7 +2,7 @@
import axios from "axios"; import axios from "axios";
let config = "http://localhost:8080/"; let config = window.BACKEND_URL || "http://localhost:8080/";
var tkn = localStorage.getItem("token"); var tkn = localStorage.getItem("token");
/** the ServiceSocket instance valid for the current session */ /** the ServiceSocket instance valid for the current session */