63 lines
1.7 KiB
Docker
63 lines
1.7 KiB
Docker
# Start from the pre-built Nextjs Base image
|
|
FROM registry.infra.mintel.me/mintel/nextjs:latest AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Ensure we are in a clean, standalone environment
|
|
RUN rm -rf packages apps pnpm-workspace.yaml 2>/dev/null || true
|
|
|
|
# Build-time environment variables for Next.js
|
|
ARG NEXT_PUBLIC_BASE_URL
|
|
ARG DIRECTUS_URL
|
|
ARG NEXT_PUBLIC_TARGET
|
|
ARG NPM_TOKEN
|
|
ARG REGISTRY_HOST
|
|
|
|
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
|
ENV DIRECTUS_URL=$DIRECTUS_URL
|
|
ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
|
|
ENV NPM_TOKEN=$NPM_TOKEN
|
|
ENV SKIP_RUNTIME_ENV_VALIDATION=true
|
|
|
|
# Enable corepack (pnpm is already in base image)
|
|
RUN corepack enable
|
|
|
|
# Copy package files
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
# Create .npmrc for private registry access if token is present
|
|
RUN if [ -n "$NPM_TOKEN" ]; then \
|
|
REGISTRY="${REGISTRY_HOST:-npm.infra.mintel.me}" && \
|
|
echo "@mintel:registry=https://$REGISTRY" > .npmrc && \
|
|
echo "//$REGISTRY/:_authToken=$NPM_TOKEN" >> .npmrc; \
|
|
fi
|
|
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# Copy local files
|
|
COPY . .
|
|
|
|
# Build the specific application
|
|
RUN pnpm build
|
|
|
|
# Production runner image
|
|
FROM registry.infra.mintel.me/mintel/runtime:latest AS runner
|
|
|
|
# Production environment configuration
|
|
ENV HOSTNAME="0.0.0.0"
|
|
ENV PORT=3000
|
|
ENV NODE_ENV=production
|
|
|
|
# Copy standalone output and static files
|
|
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
|
|
|
|
# Ensure the cache directory specifically is writeable (Mintel Standard #16)
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
|
|
|
|
USER nextjs
|
|
|
|
CMD ["node", "server.js"]
|