From 627774c910ec7c7793dfd2e10fe33b3b210bb6f0 Mon Sep 17 00:00:00 2001 From: acidumirae Date: Wed, 26 Apr 2023 17:25:58 +0800 Subject: [PATCH 1/4] Dev/prod env support --- .env.development | 30 ++++++++++++++++++++++++++++++ .env.poduction | 30 ++++++++++++++++++++++++++++++ docker-compose.yml | 4 ++++ docker/Dockerfile | 16 +++++++++++++++- nginx.conf | 29 +++++++++++++++++++++++++++++ run.sh | 15 +++++++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 .env.development create mode 100644 .env.poduction create mode 100644 nginx.conf create mode 100755 run.sh diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..f58ba9f --- /dev/null +++ b/.env.development @@ -0,0 +1,30 @@ +SKIP_PREFLIGHT_CHECK=true + +REACT_APP_FACEBOOK="https://www.facebook.com/profile.php?id=100066498622246" +REACT_APP_TWITTER="https://twitter.com/fluxtra" + +REACT_APP_APPSITE="https://myfitapp.mermsemr.com" +#REACT_APP_APPSITE="http://localhost:7012" + + +# REACT_APP_AUX_ENDPOINT="http://10.20.30.32:9083/svs/user" +# REACT_APP_USERS_ENDPOINT="http://10.20.30.32:9083/svs/user" +REACT_APP_AUX_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/svs/user" +REACT_APP_USERS_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/svs/user" + +#REACT_APP_AUX_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/en/wrench/api/v1" +#REACT_APP_USERS_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/en/wrench/api/v1" + +#"https://devapi.mermsemr.com/en/desktop/api/v2/myfituser" + +REACT_APP_SESSION_EXPIRE_MINUTES=300000 +REACT_APP_SESSION_EXPIRE_CHECKER=60000 + +REACT_APP_LOGIN_ERROR_TIMEOUT=7000 +REACT_APP_SIGNUP_ERROR_TIMEOUT=7000 + +# Had to change the error time to 3sec cause it took too long +REACT_APP_RESET_START_ERROR_TIMEOUT=3000 + +#apigate.lotus.g1.wrenchboard.com:76.209.103.227 +#apigate.orion.g1.wrenchboard.com:76.209.103.227 diff --git a/.env.poduction b/.env.poduction new file mode 100644 index 0000000..2dc4744 --- /dev/null +++ b/.env.poduction @@ -0,0 +1,30 @@ +SKIP_PREFLIGHT_CHECK=true + +REACT_APP_FACEBOOK="https://www.facebook.com/profile.php?id=100066498622246" +REACT_APP_TWITTER="https://twitter.com/fluxtra" + +REACT_APP_APPSITE="https://myfitapp.mermsemr.com" +#REACT_APP_APPSITE="http://localhost:7012" + + +# REACT_APP_AUX_ENDPOINT="http://10.20.30.32:9083/svs/user" +# REACT_APP_USERS_ENDPOINT="http://10.20.30.32:9083/svs/user" +REACT_APP_AUX_ENDPOINT="https://apigate.orion.g1.wrenchboard.com/svs/user" +REACT_APP_USERS_ENDPOINT="https://apigate.orion.g1.wrenchboard.com/svs/user" + +#REACT_APP_AUX_ENDPOINT="https://apigate.orion.g1.wrenchboard.com/en/wrench/api/v1" +#REACT_APP_USERS_ENDPOINT="https://apigate.orion.g1.wrenchboard.com/en/wrench/api/v1" + +#"https://devapi.mermsemr.com/en/desktop/api/v2/myfituser" + +REACT_APP_SESSION_EXPIRE_MINUTES=300000 +REACT_APP_SESSION_EXPIRE_CHECKER=60000 + +REACT_APP_LOGIN_ERROR_TIMEOUT=7000 +REACT_APP_SIGNUP_ERROR_TIMEOUT=7000 + +# Had to change the error time to 3sec cause it took too long +REACT_APP_RESET_START_ERROR_TIMEOUT=3000 + +#apigate.orion.g1.wrenchboard.com:76.209.103.227 +#apigate.orion.g1.wrenchboard.com:76.209.103.227 diff --git a/docker-compose.yml b/docker-compose.yml index eace1a6..0d38e2c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,8 @@ services: build: context: . dockerfile: docker/Dockerfile + args: + - NODE_ENV=production restart: unless-stopped ports: - 9082:3000 @@ -20,12 +22,14 @@ services: - backend.wrenchboard.api.live:10.10.33.15 - backend.wrenchboard.api.test:10.10.33.15 - apigate.lotus.g1.wrenchboard.com:10.10.33.15 + - apigate.orion.g1.wrenchboard.com:10.10.33.15 # #- backend.wrenchboard.api.live:172.31.4.27 # #- backend.wrenchboard.api.test:10.20.30.27 - apigateway.wrenchboard.app.dev.fluxtra.net:10.20.30.19 - apigateway.wrenchboard.app.lotus.fluxtra.net:172.31.4.19 environment: - CHOKIDAR_USEPOLLING=true + - NODE_ENV=${NODE_ENV:-production} # volumes: # - ./:/app # - /app/node_modules diff --git a/docker/Dockerfile b/docker/Dockerfile index 95cd1df..ce4d1bb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,7 +3,15 @@ FROM alpine:3.15 +# Build args +ARG NODE_ENV + ENV NODE_VERSION 14.19.0 +ENV NODE_ENV=$NODE_ENV + +# install nginx +RUN apk update +RUN apk add nginx RUN addgroup -g 1000 node \ && adduser -u 1000 -G node -s /bin/sh -D node \ @@ -103,6 +111,10 @@ WORKDIR /usr/src/app # ENV PATH /app/node_modules/.bin:$PATH ENV PATH /usr/src/app/node_modules/.bin:$PATH +COPY nginx.conf ./ + +COPY run.sh ./ + # install app dependencies COPY package.json ./ RUN npm install @@ -114,7 +126,9 @@ RUN npm install COPY . ./ # start app -CMD ["npm","run", "start"] +# CMD ["npm","run", "start"] # CMD ["yarn", "start"] +# start app +CMD /bin/sh ./run.sh diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b9f717a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,29 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + server { + gzip on; + listen 3000; + server_name localhost; + root /usr/src/app/build; + + include /etc/nginx/mime.types; + + location /nginx_status { + stub_status on; + access_log off; + } + + location / { + try_files $uri $uri/ /index.html; + } + } +} + diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..a346abc --- /dev/null +++ b/run.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +set -e +set -x + +export NODE_ENV="${NODE_ENV:-development}" + +if [ $NODE_ENV == "development" ]; then + # this runs webpack-dev-server with hot reloading + npm start +else + # build the app and serve it via nginx + npm run build + nginx -g 'daemon off;' -c /usr/src/app/nginx.conf + nginx -c /usr/src/app/nginx.conf +fi \ No newline at end of file -- 2.34.1 From f30600816b8dd483f7cdcc41210fc5281870d350 Mon Sep 17 00:00:00 2001 From: acidumirae Date: Wed, 26 Apr 2023 18:11:32 +0800 Subject: [PATCH 2/4] Map node_modules --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0d38e2c..a2f5ce2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: working_dir: /usr/src/app volumes: - ./:/usr/src/app - - /usr/src/app/node_modules + - ./node_modules:/usr/src/app/node_modules - ./src/:/usr/src/app/src - ./vendors/:/usr/src/app/vendors extra_hosts: -- 2.34.1 From 3acdbfb6e07f52f0027734be7d5dc9798f1e009d Mon Sep 17 00:00:00 2001 From: acidumirae Date: Wed, 26 Apr 2023 18:29:41 +0800 Subject: [PATCH 3/4] Remove volume maps for node_modules & vendors --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a2f5ce2..2133e78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,9 +15,7 @@ services: working_dir: /usr/src/app volumes: - ./:/usr/src/app - - ./node_modules:/usr/src/app/node_modules - ./src/:/usr/src/app/src - - ./vendors/:/usr/src/app/vendors extra_hosts: - backend.wrenchboard.api.live:10.10.33.15 - backend.wrenchboard.api.test:10.10.33.15 -- 2.34.1 From 104cd15f645c5758549f55bad970822e578ea7da Mon Sep 17 00:00:00 2001 From: acidumirae Date: Wed, 26 Apr 2023 18:49:58 +0800 Subject: [PATCH 4/4] Attempt to fix --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- package.json | 4 ++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e03e574 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# pull the base image +FROM node:alpine + +# Build args +ARG NODE_ENV + +# set the working direction +#WORKDIR /app +WORKDIR /usr/src/app + +# add `/app/node_modules/.bin` to $PATH +# ENV PATH /app/node_modules/.bin:$PATH +ENV PATH /usr/src/app/node_modules/.bin:$PATH +ENV NODE_ENV=$NODE_ENV + +# install nginx +RUN apk update +RUN apk add nginx + +# install app dependencies +COPY package.json ./ + +COPY package-lock.json ./ + +COPY nginx.conf ./ + +COPY run.sh ./ + +RUN npm install + +# add app +COPY . ./ + +# start app +CMD /bin/sh ./run.sh + diff --git a/docker-compose.yml b/docker-compose.yml index 2133e78..ce7f718 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: image: registry.chiefsoft.net/wrenchboard-users-wrench:latest build: context: . - dockerfile: docker/Dockerfile + dockerfile: Dockerfile args: - NODE_ENV=production restart: unless-stopped diff --git a/package.json b/package.json index 5f02a8a..3fe2dda 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "yup": "^1.1.1" }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", + "start": "react-scripts start -e .env.development", + "build": "react-scripts build -e .env.production", "test": "react-scripts test", "eject": "react-scripts eject", "lint": "yarn add -D prettier@2.4.1 && yarn add -D eslint@7.11.0 && yarn add -D babel-eslint@10.1.0 && npx install-peerdeps --dev eslint-config-airbnb@18.2.1 && yarn add -D eslint-config-prettier@8.3.0 eslint-plugin-prettier@4.0.0" -- 2.34.1