56 lines
1.3 KiB
Docker
56 lines
1.3 KiB
Docker
# Etapa 1 - extrair e buildar a aplicação
|
|
FROM node:18 AS build
|
|
|
|
WORKDIR /app
|
|
|
|
# Copiar e descompactar o ZIP do repositório
|
|
COPY app.zip /app/
|
|
RUN apt-get update && apt-get install -y unzip && \
|
|
unzip app.zip -d . && \
|
|
rm app.zip
|
|
|
|
# Instalar dependências e buildar o projeto
|
|
RUN npm install && npm run build
|
|
|
|
# Etapa 2 - imagem final com nginx
|
|
FROM nginx:alpine
|
|
|
|
# Configuração customizada do nginx para SPA
|
|
RUN cat <<'EOF' > /etc/nginx/conf.d/default.conf
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json;
|
|
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
location ~ /\. {
|
|
deny all;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Copiar os arquivos construídos para o diretório público do nginx
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
# Remover arquivo default se existir (evita sobrescrever a index.html do build)
|
|
RUN rm -f /usr/share/nginx/html/index.html.orig 2>/dev/null || true
|
|
|
|
EXPOSE 80
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|
|
|