From 48a847c1e49f8ba5d2bb2b72ff1bf0c7080a70a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Negreiros?= Date: Sat, 9 Nov 2024 23:52:59 -0300 Subject: [PATCH] updates Dockeryzer.Dockerfile and Dockerfile --- Dockerfile | 38 +++++++++++++++--------------------- Dockeryzer.Dockerfile | 45 +++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/Dockerfile b/Dockerfile index 517973f..3311436 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,29 @@ -# Etapa 1: Construção do projeto -FROM node:18 AS build +# Etapa 1: Construção da imagem com as dependências +FROM node:18-alpine AS build -# Diretório de trabalho no contêiner +# Definir diretório de trabalho WORKDIR /app -# Copia o package.json e o package-lock.json (ou yarn.lock) para instalar as dependências -COPY package*.json ./ +# Copiar o package.json e package-lock.json para o contêiner +COPY package.json package-lock.json ./ -# Instala as dependências +# Instalar as dependências do projeto RUN npm install -# Copia todos os arquivos do projeto para o contêiner +# Copiar o restante dos arquivos do projeto COPY . . -# Executa o build do projeto Vite +# Rodar o build do Vite.js RUN npm run build -# Etapa 2: Configuração do ambiente de produção -FROM node:18-slim +# Etapa 2: Servir a aplicação +FROM nginx:alpine -# Diretório de trabalho no contêiner -WORKDIR /app - -# Instala o servidor estático para servir o conteúdo construído -RUN npm install -g serve - -# Copia apenas os arquivos necessários para o ambiente de produção -COPY --from=build /app/dist /app/dist +# Copiar o build do Vite.js para o diretório de arquivos estáticos do nginx +COPY --from=build /app/dist /usr/share/nginx/html -# Expondo a porta para o servidor estático -EXPOSE 3000 +# Expor a porta 80 do nginx +EXPOSE 80 -# Comando para iniciar o servidor -CMD ["serve", "-s", "dist", "-l", "3000"] +# Rodar o nginx em modo foreground +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockeryzer.Dockerfile b/Dockeryzer.Dockerfile index 8e33a66..3311436 100644 --- a/Dockeryzer.Dockerfile +++ b/Dockeryzer.Dockerfile @@ -1,30 +1,29 @@ -# --------------------> The build image -# Use the Node.js image based on Debian Bullseye for the build phase. -# Customization suggestion: You can change the base image to a different version of Node.js, such as 'node:slim' or 'node:alpine', if necessary. -FROM node:alpine AS builder +# Etapa 1: Construção da imagem com as dependências +FROM node:18-alpine AS build -# Set the working directory for the application in the build phase. -# Customization suggestion: If your application's working directory is different, you can modify it by changing the value of the WORKDIR variable. -WORKDIR /workspace/app +# Definir diretório de trabalho +WORKDIR /app -# Copy all files from the current host directory to the application's working directory in the container. -COPY --chown=node:node . /workspace/app +# Copiar o package.json e package-lock.json para o contêiner +COPY package.json package-lock.json ./ -# Install only production dependencies, optimizing the build process, and clean npm cache. -RUN npm ci --only=production && npm run build && npm cache clean --force +# Instalar as dependências do projeto +RUN npm install -# --------------------> The production image -# Again, use the Node.js image based on Debian Bullseye for the production phase. -FROM node:alpine +# Copiar o restante dos arquivos do projeto +COPY . . -# Copy the compiled files from the build phase to the '/app' directory in the container. -COPY --from=builder --chown=node:node /workspace/app/dist /app +# Rodar o build do Vite.js +RUN npm run build -# Set the working directory for the application in the production phase. -WORKDIR /app +# Etapa 2: Servir a aplicação +FROM nginx:alpine + +# Copiar o build do Vite.js para o diretório de arquivos estáticos do nginx +COPY --from=build /app/dist /usr/share/nginx/html + +# Expor a porta 80 do nginx +EXPOSE 80 -# Start the static server using the locally installed serve. -# Customization suggestions: -# - The default server port is set to 3000. You can change it as needed by modifying the '-p' argument in the CMD command. -# - If you prefer to use a different server or add more options to the execution command, you can modify the CMD as needed. -CMD ["npx", "serve", "-p", "3000", "-s", "/app"] +# Rodar o nginx em modo foreground +CMD ["nginx", "-g", "daemon off;"]