From a45ace42110788f7173ef41e8407b097c4c1003f Mon Sep 17 00:00:00 2001 From: zomborip Date: Wed, 26 Nov 2025 17:09:06 +0100 Subject: [PATCH] Multistage Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A dev és a prod is tud működni docker imagekből, de erre kellett két dockerfile --- .dockerignore | 4 +++- .gitignore | 2 ++ Dockerfile | 29 ++++++++++++++++++++++++++--- Dockerfile.dev | 16 ++++++++++++++++ docker-compose.yml | 8 +++++--- nginx.conf | 13 +++++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 Dockerfile.dev create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore index 038d1a3..824d828 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,6 @@ node_modules npm-debug.log Dockerfile docker-compose.yml -.env \ No newline at end of file +.env +dist +.git diff --git a/.gitignore b/.gitignore index 80d5540..1347168 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,9 @@ # gitignore template for Vue.js projects # # Recommended template: Node.gitignore +.git +dist # TODO: where does this rule come from? docs/_book diff --git a/Dockerfile b/Dockerfile index ad57687..834eefc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM node:20-alpine +# ================ +# 1. BUILD STAGE +# ================ +FROM node:20-alpine AS build WORKDIR /usr/src/app @@ -6,6 +9,26 @@ COPY package*.json ./ RUN npm install -EXPOSE 5173 +COPY . . -# A futtatási parancsot a compose adja +ARG VITE_BACKEND_API_HOST=http://telefonkonyv-api +ARG VITE_BACKEND_API_PORT=3000 +ENV VITE_BACKEND_API_HOST=${VITE_BACKEND_API_HOST} +ENV VITE_BACKEND_API_PORT=${VITE_BACKEND_API_PORT} + +RUN npm run build + +# ================= +# 2. RUNTIME STAGE +# ================= +FROM nginx:1.27-alpine + +RUN rm /etc/nginx/conf.d/default.conf + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +COPY --from=build /usr/src/app/dist /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..97ba0e1 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,16 @@ +FROM node:20-alpine + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 5173 + +# A futtatási parancsot a compose adja, de kell az alap is a k8s-hez +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"] + + diff --git a/docker-compose.yml b/docker-compose.yml index f3148ab..3740cfa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,15 @@ services: frontend: - build: . + build: + context: . + dockerfile: Dockerfile.dev container_name: telefonkonyv-frontend restart: always env_file: .env environment: - CHOKIDAR_USEPOLLING=true - - BACKEND_API_HOST=${BACKEND_API_HOST} - - BACKEND_API_PORT=${BACKEND_API_PORT} + - BACKEND_API_HOST=${VITE_BACKEND_API_HOST} + - BACKEND_API_PORT=${VITE_BACKEND_API_PORT} ports: - "${FRONTEND_PORT:-5173}:5173" volumes: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d0e46eb --- /dev/null +++ b/nginx.conf @@ -0,0 +1,13 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Statikus fájlok + location / { + try_files $uri $uri/ /index.html; + } + +} \ No newline at end of file