From 3b334d9a59723cb55c26be8bb17dcf3f9215e60d Mon Sep 17 00:00:00 2001 From: Mgrdich Date: Mon, 13 May 2024 17:38:24 +0400 Subject: [PATCH] FE: add nginx config + dockerize the front end build --- application-compose.yml => docker-compose.yml | 13 +++++++++---- frontend/Dockerfile | 18 ++++++++++-------- frontend/index.html | 1 + frontend/nginx.conf | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) rename application-compose.yml => docker-compose.yml (80%) create mode 100644 frontend/nginx.conf diff --git a/application-compose.yml b/docker-compose.yml similarity index 80% rename from application-compose.yml rename to docker-compose.yml index 37f608f..34b2951 100644 --- a/application-compose.yml +++ b/docker-compose.yml @@ -32,11 +32,16 @@ services: # - SPRING_JPA_HIBERNATE_DDL_AUTO=update - run-fe: - container_name: llm_service_ui + run-build-fe: + container_name: "llm_service_ui" + stdin_open: true build: context: ./frontend/ + dockerfile: Dockerfile + volumes: + - '/app/node_modules' + - './frontend/:/app' + ports: + - "4040:80" # Assuming you want to use port 8080 locally depends_on: - db - ports: - - "4040:4040" diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 2d19ad5..316b3bc 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,16 +1,13 @@ # Use the official Node.js 18 image as base -FROM node:18 +FROM node:18 as builder WORKDIR /app +COPY package.json . + # Set environment variables ENV PNPM_VERSION 8.15.0 -# Optionally, you can copy your application code here -COPY . /app - -RUN rm -rf node_modules - # Install PNPM globally RUN npm install -g pnpm@${PNPM_VERSION} @@ -19,6 +16,11 @@ RUN pnpm --version RUN pnpm install -EXPOSE 4040 +COPY . . + +RUN pnpm build -CMD ["pnpm", "dev"] +FROM nginx +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/dist /usr/share/nginx/html +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/index.html b/frontend/index.html index 9ee1395..47c7c87 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,6 +1,7 @@ + diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..4d14ea2 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}