This commit is contained in:
skidoodle 2025-01-21 05:26:50 +01:00
parent cfccc4d177
commit 1cace925dd
No known key found for this signature in database

View file

@ -1,4 +1,3 @@
# Base image
FROM node:20-alpine AS base
### Dependencies ###
@ -19,20 +18,28 @@ RUN pnpm install --frozen-lockfile --prefer-frozen-lockfile
# Builder
FROM base AS builder
RUN corepack enable
RUN corepack prepare pnpm@latest --activate
WORKDIR /app
COPY . ./
COPY --from=deps /app/node_modules ./node_modules
COPY ./src ./src
COPY ./public ./public
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prefer-frozen-lockfile
RUN pnpm build
### Production image runner ###
FROM base AS runner
# Copy curl from deps stage
COPY --from=deps /usr/bin/curl /usr/bin/curl
# Install curl for healthcheck
RUN apk add --no-cache curl
# Disable Next.js telemetry
ENV NEXT_TELEMETRY_DISABLED 1
# https://nextjs.org/telemetry
ENV NEXT_TELEMETRY_DISABLED=1
# Set correct permissions for nextjs user and don't run as root
RUN addgroup nodejs
@ -40,7 +47,8 @@ RUN adduser -SDH nextjs
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy built app from builder stage
# 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
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
@ -49,9 +57,9 @@ USER nextjs
# Exposed port (for orchestrators and dynamic reverse proxies)
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD ["curl", "-f", "http://localhost:3000/health"]
# Run the next.js app
# Run the nextjs app
CMD ["node", "server.js"]