Working to let react app work in Docker

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-15 17:07:02 -08:00
parent 535816033b
commit 726246778a
6 changed files with 94 additions and 10 deletions

View File

@ -17,3 +17,5 @@
!src
!util
!ketrface
!client
!scripts

View File

@ -45,33 +45,41 @@ WORKDIR /website
RUN npm upgrade && npm install
WORKDIR /website/client
COPY /website/client/package*json /website/client
COPY /client/package*json /website/client/
RUN npm upgrade && npm install
COPY /config/default.json /website/config/default.json
COPY /*js /website/
COPY /src /website/src
COPY /client /website/client
COPY /client/public /website/client/public
COPY /client/src /website/client/src
COPY /scanner /website/scanner
COPY /server /website/server
COPY /frontend /website/frontend
COPY /ketrface /website/ketrface
# Switch to bash instead of sh
SHELL [ "/bin/bash", "-c" ]
ARG DEVELOPMENT=
# If not DEVELOPMENT mode, copy production config, else development
RUN \
if [[ -z "${DEVELOPMENT}" ]]; then \
echo "Building PRODUCTION" ; \
cp /website/server/production.location /etc/nginx/snippets/active.location ; \
echo "Building PRODUCTION" ; \
cp /website/server/production.location \
/etc/nginx/snippets/active.location ; \
else \
echo "Building DEVELOPMENT" ; \
cp /website/server/development.location /etc/nginx/snippets/active.location ; \
echo "Building DEVELOPMENT" ; \
cp /website/server/development.location \
/etc/nginx/snippets/active.location ; \
fi
# If not DEVELOPMENT mode, then locally build project
RUN \
if [[ -z "${DEVELOPMENT}" ]]; then \
cd /website/client ; \
npm run build ; \
cd /website/client ; \
npm run build ; \
fi
COPY /scripts /opt/scripts

View File

@ -17,8 +17,8 @@ services:
# - db
restart: always
ports:
- ${PORT}:${TARGET_PORT:-8123}
- 127.0.0.1:14200:4200 # shellinabox
- ${PORT}:80 # nginx -> server/app.js express app
- 127.0.0.1:14200:4200 # shellinabox
volumes:
- ${PICTURES}:/pictures
- ${PWD}/db:/website/db

View File

@ -0,0 +1,14 @@
# DEVELOPMENT -- use npm development server on port 3000 (entrypoint.sh)
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://localhost:3000/;
}

54
server/nginx.conf Normal file
View File

@ -0,0 +1,54 @@
server {
root /website;
index index.html;
access_log /var/log/nginx/access.log;
error_log stderr;
autoindex on;
# 'active.conf' is copied during docker build based on whether
# DEVELOPMENT is set (development.conf) or not (production.conf)
include snippets/active.location;
# proxy_pass has automatic redirect from v1 -> v1/
location /api/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:8123/api/v1/;
}
# This routes all traffic to the Node Express server
#
# Eventually, a SSO layer in nginx can be used so the Express
# server does not need to be part of serving static content.
#
# See https://gist.github.com/mjbnz/b402edf819a69e517b0c59710f291da9
# for example.
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://localhost:8123/;
}
location ~ /(db|conf) {
deny all;
return 404;
}
}

View File

@ -0,0 +1,6 @@
# PRODUCTION -- pre-built source
location / {
try_files $uri $uri/ =404;
alias /website/client/build/;
index index.html;
}