-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates Dockeryzer.Dockerfile and Dockerfile
- Loading branch information
1 parent
22e03b4
commit 48a847c
Showing
2 changed files
with
38 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;"] |