From ac68347c12ced724206112843623ee8c515bd3ad Mon Sep 17 00:00:00 2001 From: taichan03 Date: Mon, 15 Jan 2024 18:03:29 -0500 Subject: [PATCH] nginx --- config/env/.env.prod.db | 3 +++ docker-compose.prod.yml | 13 ++++--------- frontend/Dockerfile.prod | 19 +++++++++++++++++++ frontend/nginx.conf | 10 ++++++++++ frontend/src/components/Header/Chat.tsx | 2 +- frontend/src/components/Header/Header.tsx | 2 +- .../src/pages/DrugSummary/DrugSummaryForm.tsx | 2 +- frontend/src/pages/Layout/Layout.tsx | 2 +- frontend/vite.config.ts | 4 ++-- server/Dockerfile.prod | 2 +- 10 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 config/env/.env.prod.db create mode 100644 frontend/Dockerfile.prod create mode 100644 frontend/nginx.conf diff --git a/config/env/.env.prod.db b/config/env/.env.prod.db new file mode 100644 index 00000000..3c73c247 --- /dev/null +++ b/config/env/.env.prod.db @@ -0,0 +1,3 @@ +POSTGRES_USER=set_me +POSTGRES_PASSWORD=set_me +POSTGRES_DB=balancer_prod \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 2a7e43e8..a7f0ae12 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -5,7 +5,7 @@ services: volumes: - postgres_data:/var/lib/postgresql/data/ env_file: - - ./.env.prod.db + - ./config/env/.env.prod.db backend: build: context: ./server @@ -18,16 +18,11 @@ services: depends_on: - db frontend: - image: balancer-frontend build: - context: frontend - dockerfile: Dockerfile - args: - - IMAGE_NAME=balancer-frontend + context: ./frontend + dockerfile: Dockerfile.prod ports: - - "3000:3000" - environment: - - CHOKIDAR_USEPOLLING=true + - "3000:80" depends_on: - backend diff --git a/frontend/Dockerfile.prod b/frontend/Dockerfile.prod new file mode 100644 index 00000000..c0648913 --- /dev/null +++ b/frontend/Dockerfile.prod @@ -0,0 +1,19 @@ +FROM node:18 as builder + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm ci --legacy-peer-deps + +COPY . . + +RUN npm run build + +FROM nginx:latest + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +COPY --from=builder /usr/src/app/build /usr/share/nginx/html + +EXPOSE 80 \ No newline at end of file diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 00000000..05d512d6 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80; + server_name backend; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file diff --git a/frontend/src/components/Header/Chat.tsx b/frontend/src/components/Header/Chat.tsx index bd46f3c7..d3c618ca 100644 --- a/frontend/src/components/Header/Chat.tsx +++ b/frontend/src/components/Header/Chat.tsx @@ -1,6 +1,6 @@ import React from "react"; // import { Link } from "react-router-dom"; -import "../../components/Header/Chat.css"; +import "../../components/Header/chat.css"; import { useState, useEffect, useRef } from "react"; import axios from "axios"; diff --git a/frontend/src/components/Header/Header.tsx b/frontend/src/components/Header/Header.tsx index e0ca7fc5..a1d46d7f 100644 --- a/frontend/src/components/Header/Header.tsx +++ b/frontend/src/components/Header/Header.tsx @@ -2,7 +2,7 @@ import { useState, useRef, useEffect, Fragment } from "react"; import accountLogo from "../../assets/account.svg"; import { Link, useNavigate } from "react-router-dom"; import LoginMenuDropDown from "./LoginMenuDropDown"; -import "../../components/Header/Header.css"; +import "../../components/Header/header.css"; import Chat from "./Chat"; import { FeatureMenuDropDown } from "./FeatureMenuDropDown"; import MdNavBar from "./MdNavBar"; diff --git a/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx b/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx index 9123bf7c..61b80ac2 100644 --- a/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx +++ b/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx @@ -1,6 +1,6 @@ import React from "react"; // import { Link } from "react-router-dom"; -import "../../components/Header/Chat.css"; +import "../../components/Header/chat.css"; import { useState, useEffect, useRef } from "react"; import axios from "axios"; // import TypingAnimation from "./components/TypingAnimation.tsx"; diff --git a/frontend/src/pages/Layout/Layout.tsx b/frontend/src/pages/Layout/Layout.tsx index 3d712f8d..c09f261a 100644 --- a/frontend/src/pages/Layout/Layout.tsx +++ b/frontend/src/pages/Layout/Layout.tsx @@ -4,7 +4,7 @@ import Header from "../../components/Header/Header"; import Footer from "../../components/Footer/Footer"; import LoginMenuDropDown from "../../components/Header/LoginMenuDropDown"; import { connect } from "react-redux"; -import { useAuth } from "./AuthHooks"; +import { useAuth } from "./authHooks.ts"; import { RootState } from "../../services/actions/types"; import { useLocation } from "react-router-dom"; diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 8979dda2..1da09107 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,7 +4,7 @@ import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ build: { - outDir: '../server/build', // Custom output directory + outDir: 'build', // Custom output directory assetsDir: 'static', }, plugins: [react()], @@ -16,4 +16,4 @@ export default defineConfig({ strictPort: true, port: 3000, }, -}); +}); \ No newline at end of file diff --git a/server/Dockerfile.prod b/server/Dockerfile.prod index fe448bab..9c5244c6 100644 --- a/server/Dockerfile.prod +++ b/server/Dockerfile.prod @@ -68,4 +68,4 @@ RUN chown -R app:app $APP_HOME USER app # run entrypoint.prod.sh -ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"] +ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"] \ No newline at end of file