saas_app/Dockerfile
2025-12-09 16:41:39 -03:00

59 lines
1.6 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================
# STAGE 1 Build
# ============================
FROM node:20-alpine AS builder
WORKDIR /app
# Copia pacotes e instala dependências
COPY package*.json ./
RUN npm ci
# Copia o restante do código
COPY . .
# ---------- Variáveis de build ----------
# Estas variáveis são usadas pelo Next.js durante o "build"
# para embutir no bundle do frontend.
ARG NEXT_PUBLIC_ORIUS_APP_STATE
ARG NEXT_PUBLIC_ORIUS_APP_API_URL
ARG NEXT_PUBLIC_ORIUS_APP_API_PREFIX
ARG NEXT_PUBLIC_ORIUS_APP_API_CONTENT_TYPE
ENV NEXT_PUBLIC_ORIUS_APP_STATE=$NEXT_PUBLIC_ORIUS_APP_STATE
ENV NEXT_PUBLIC_ORIUS_APP_API_URL=$NEXT_PUBLIC_ORIUS_APP_API_URL
ENV NEXT_PUBLIC_ORIUS_APP_API_PREFIX=$NEXT_PUBLIC_ORIUS_APP_API_PREFIX
ENV NEXT_PUBLIC_ORIUS_APP_API_CONTENT_TYPE=$NEXT_PUBLIC_ORIUS_APP_API_CONTENT_TYPE
# ---------- Build ----------
ENV NODE_ENV=production
RUN npm run build
# ============================
# STAGE 2 Runner (standalone)
# ============================
FROM node:20-alpine AS runner
WORKDIR /app
# ---------- Variáveis em runtime ----------
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copia apenas o necessário do build
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
COPY --from=builder /app/package*.json ./
# ---------- Corrige permissões ----------
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs \
&& mkdir -p .next/cache/images \
&& chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
# ---------- Executa o servidor ----------
CMD ["node", "server.js"]