fix: use npm in Dockerfile
This commit is contained in:
parent
e51a16f622
commit
004f1228a2
1 changed files with 53 additions and 73 deletions
|
|
@ -1,73 +1,53 @@
|
||||||
# =============================================================================
|
# Stage 1: Base
|
||||||
# GoHorse Jobs Frontend - Ultra-Optimized Dockerfile
|
FROM node:22-alpine AS base
|
||||||
# =============================================================================
|
WORKDIR /app
|
||||||
# syntax=docker/dockerfile:1
|
|
||||||
|
# Stage 2: Dependencies
|
||||||
# -----------------------------------------------------------------------------
|
FROM base AS deps
|
||||||
# Stage 1: Base with pnpm
|
WORKDIR /app
|
||||||
# -----------------------------------------------------------------------------
|
COPY package.json package-lock.json ./
|
||||||
FROM mirror.gcr.io/library/node:20-alpine AS base
|
# Install dependencies using npm
|
||||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
RUN npm ci
|
||||||
ENV PNPM_HOME="/pnpm"
|
|
||||||
ENV PATH="$PNPM_HOME:$PATH"
|
# Stage 3: Builder
|
||||||
|
FROM base AS builder
|
||||||
# -----------------------------------------------------------------------------
|
ENV NODE_OPTIONS="--max-old-space-size=512"
|
||||||
# Stage 2: Dependencies
|
WORKDIR /app
|
||||||
# -----------------------------------------------------------------------------
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
FROM base AS deps
|
COPY package.json next.config.* tsconfig.json postcss.config.mjs ./
|
||||||
WORKDIR /app
|
|
||||||
COPY package.json package-lock.json* pnpm-lock.yaml* ./
|
# Copy other necessary files
|
||||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
COPY public ./public
|
||||||
pnpm import 2>/dev/null || true && \
|
COPY src ./src
|
||||||
pnpm install --frozen-lockfile || pnpm install
|
COPY messages ./messages
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# Build arguments (Preserved from original)
|
||||||
# Stage 3: Builder (AQUI ESTAVA O PROBLEMA)
|
ARG NEXT_PUBLIC_API_URL=http://localhost:8521
|
||||||
# -----------------------------------------------------------------------------
|
ARG NEXT_PUBLIC_BACKOFFICE_URL=http://localhost:3001
|
||||||
FROM base AS builder
|
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||||
ENV NODE_OPTIONS="--max-old-space-size=512"
|
ENV NEXT_PUBLIC_BACKOFFICE_URL=$NEXT_PUBLIC_BACKOFFICE_URL
|
||||||
WORKDIR /app
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
|
||||||
|
RUN npm run build && \
|
||||||
# CORREÇÃO: Copiando TODAS as configs e pastas necessárias
|
rm -rf node_modules/.cache .next/cache
|
||||||
COPY package.json next.config.* tsconfig.json postcss.config.mjs ./
|
|
||||||
# Se tiver outras configs como tailwind.config.ts, adicione aqui ou use COPY . . (com dockerignore bom)
|
# Stage 4: Production Runner
|
||||||
COPY public ./public
|
FROM base AS runner
|
||||||
COPY src ./src
|
WORKDIR /app
|
||||||
# Adicionei a pasta messages que apareceu no seu ls
|
ENV NODE_ENV=production
|
||||||
COPY messages ./messages
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV PORT=3000
|
||||||
# Build arguments
|
ENV HOSTNAME="0.0.0.0"
|
||||||
ARG NEXT_PUBLIC_API_URL=http://localhost:8521
|
|
||||||
ARG NEXT_PUBLIC_BACKOFFICE_URL=http://localhost:3001
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
RUN adduser --system --uid 1001 nextjs
|
||||||
ENV NEXT_PUBLIC_BACKOFFICE_URL=$NEXT_PUBLIC_BACKOFFICE_URL
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
RUN pnpm build && \
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
rm -rf node_modules/.cache .next/cache
|
|
||||||
|
USER nextjs
|
||||||
# -----------------------------------------------------------------------------
|
|
||||||
# Stage 4: Production Runner
|
EXPOSE 3000
|
||||||
# -----------------------------------------------------------------------------
|
|
||||||
FROM mirror.gcr.io/library/node:20-alpine AS runner
|
CMD ["node", "server.js"]
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
|
||||||
adduser -u 1001 -S nextjs -G nodejs
|
|
||||||
|
|
||||||
ENV NODE_ENV=production \
|
|
||||||
NEXT_TELEMETRY_DISABLED=1 \
|
|
||||||
PORT=3000 \
|
|
||||||
HOSTNAME="0.0.0.0"
|
|
||||||
|
|
||||||
# O Docker faz o "cp" que você fez na mão AQUI:
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
||||||
|
|
||||||
USER nextjs
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue