From 934f424972ecf0bee75a37fc9b3c04c14a128deb Mon Sep 17 00:00:00 2001 From: nknguyenhc <87511888+nknguyenhc@users.noreply.github.com> Date: Wed, 2 Oct 2024 00:43:11 +0800 Subject: [PATCH] Dockerise frontend with nginx --- docker-compose.yml | 5 +++++ frontend/.dockerignore | 2 ++ frontend/Dockerfile | 23 +++++++++++++++++++++++ frontend/nginx/nginx.conf | 12 ++++++++++++ frontend/nginx/sites-enabled/app.conf | 8 ++++++++ 5 files changed, 50 insertions(+) create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile create mode 100644 frontend/nginx/nginx.conf create mode 100644 frontend/nginx/sites-enabled/app.conf diff --git a/docker-compose.yml b/docker-compose.yml index 6df7fd0d3a..5285c2f926 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,3 +8,8 @@ services: build: ./backend/user-service ports: - "3001:3001" + + frontend: + build: ./frontend + ports: + - "80:80" diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000000..3e2e84b087 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,2 @@ +build/ +node_modules/ diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000000..c2d6f302c1 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,23 @@ +FROM node:20 AS build + +WORKDIR /app + +COPY package*.json . + +RUN npm install + +COPY ./src ./src + +COPY ./public ./public + +COPY .env . + +COPY tsconfig.json . + +RUN npm run build + +FROM nginx:latest + +COPY ./nginx /etc/nginx + +COPY --from=build /app/build /app diff --git a/frontend/nginx/nginx.conf b/frontend/nginx/nginx.conf new file mode 100644 index 0000000000..ac3aee187c --- /dev/null +++ b/frontend/nginx/nginx.conf @@ -0,0 +1,12 @@ +worker_processes auto; + +error_log /var/log/nginx/error.log; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + include /etc/nginx/sites-enabled/*; +} diff --git a/frontend/nginx/sites-enabled/app.conf b/frontend/nginx/sites-enabled/app.conf new file mode 100644 index 0000000000..33b71053a3 --- /dev/null +++ b/frontend/nginx/sites-enabled/app.conf @@ -0,0 +1,8 @@ +server { + listen 80; + server_name localhost; + + location / { + root /app; + } +}