Some checks failed
CI - Lint, Typecheck & Test / quality-assurance (push) Failing after 1m21s
83 lines
2.4 KiB
Docker
83 lines
2.4 KiB
Docker
FROM node:20-alpine AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
RUN apk add --no-cache libc6-compat curl
|
|
WORKDIR /app
|
|
|
|
# Install pnpm
|
|
RUN npm install -g pnpm@10
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
ARG NPM_TOKEN
|
|
RUN if [ -n "$NPM_TOKEN" ]; then \
|
|
echo "@mintel:registry=https://npm.infra.mintel.me" > .npmrc && \
|
|
echo "//npm.infra.mintel.me/:_authToken=$NPM_TOKEN" >> .npmrc; \
|
|
fi
|
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile
|
|
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Next.js collects completely anonymous telemetry data about general usage.
|
|
# Learn more here: https://nextjs.org/telemetry
|
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Build-time environment variables for Next.js
|
|
# These are baked into the client bundle during build
|
|
ARG NEXT_PUBLIC_BASE_URL
|
|
ARG NEXT_PUBLIC_TARGET
|
|
ARG DIRECTUS_URL
|
|
|
|
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
|
ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
|
|
ENV DIRECTUS_URL=$DIRECTUS_URL
|
|
|
|
# Validate environment variables during build
|
|
RUN SKIP_RUNTIME_ENV_VALIDATION=true npx tsx scripts/validate-env.ts
|
|
|
|
RUN --mount=type=cache,target=/app/.next/cache pnpm run build
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
# Install curl for health checks
|
|
RUN apk add --no-cache curl
|
|
|
|
ENV NODE_ENV=production
|
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Set the correct permission for prerender cache
|
|
RUN mkdir .next
|
|
RUN chown nextjs:nodejs .next
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
# set hostname to localhost
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# server.js is created by next build from the standalone output
|
|
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
|
CMD ["node", "server.js"]
|