gohorsejobs/frontend/Dockerfile
Tiago Yamamoto cb31713307 fix(docker): update frontend Dockerfile for Podman compatibility
- Remove deprecated --only=production flag
- Add default value for NEXT_PUBLIC_API_URL build arg
- Add BuildKit cache mount for npm
- Remove HEALTHCHECK (not supported by Podman OCI format)
2025-12-28 11:02:05 -03:00

65 lines
2 KiB
Docker

# =============================================================================
# GoHorse Jobs Frontend - Optimized Production Dockerfile
# =============================================================================
# syntax=docker/dockerfile:1
# -----------------------------------------------------------------------------
# Stage 1: Dependencies
# -----------------------------------------------------------------------------
FROM mirror.gcr.io/library/node:20-alpine AS deps
WORKDIR /app
# Install ALL dependencies (dev + prod) for build stage
COPY package.json package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm \
npm ci && npm cache clean --force
# -----------------------------------------------------------------------------
# Stage 2: Builder
# -----------------------------------------------------------------------------
FROM mirror.gcr.io/library/node:20-alpine AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build arguments for environment (with sensible default)
ARG NEXT_PUBLIC_API_URL=http://localhost:8080
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
# Build the application
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# -----------------------------------------------------------------------------
# Stage 3: Production Runner
# -----------------------------------------------------------------------------
FROM mirror.gcr.io/library/node:20-alpine AS runner
WORKDIR /app
# Security: Run as non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -u 1001 -S nextjs -G nodejs
# Set production environment
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000
# Copy only necessary files for production
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set ownership to non-root user
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]